AMC 68VZ328 Frozen Dessert Maker User Manual


 
50
www.amctechcorp.com
printf (“Cannot open file\n”);
exit (-1);
}
// print the string to file
fprintf (file_handle, “Hello World!\n”);
// close the file afterwards
fclose (file_handle);
}
This application shows how to open and configure the RS485 serial port for communication. It
will write the same hello world string to the serial port and then close and exit gracefully.
// serial.c
//
// This program opens the RS485 serial port, configures it to
// run
// at 9600 bps and transmits a string containing “Hello World”
#include <stdio.h>
#include <fcntl.h>
#include <termios.h>
void main ()
{
int file_handle;
struct termios io_settings;
char hello_string[] = “Hello World”;
// open the serial port
file_handle = open (“/dev/ttyS1”, O_RDWR);
// check if an error occured
if (file_handle == -1) {
printf (“Cannot open serial port\n”);
exit (-1);
}
// set the serial port speed to 9600 in both directions
tcgetattr (file_handle, &io_settings);
cfsetospeed (&io_settings, B9600);
cfsetispeed (&io_settings, B9600);
tcsetattr (file_handle, TCSANOW, &io_settings);
// transmit the string
write (file_handle, (void *) hello_string, sizeof
(hello_string) - 1);
// close the serial port when finished
close (file_handle);