00001
00002
00003
00004 #include <stdio.h>
00005 #include <stdlib.h>
00006
00007 #include "_tty.h"
00008
00009 int
00010 main (int argc, char **argv)
00011 {
00012 #ifdef UNIX_LIKE_PLAT
00013 char *ttyDevName = "/dev/ttyb";
00014 #else
00015 char *ttyDevName = "COM2:";
00016 #endif
00017 if (argc > 1)
00018 {
00019 ttyDevName = argv[1];
00020 }
00021 RCS_SERIAL_PORT_HANDLE handle =
00022 open_serial_communications_port (ttyDevName);
00023
00024 print_serial_port_configuration (handle);
00025 set_serial_port_configuration (handle, NULL);
00026 char buf[80];
00027 memset (buf, 0, 80);
00028 int newline_received = 0;
00029 printf ("Receiving line:\n");
00030 while (1)
00031 {
00032 int bytes_read = read_serial_communications_port (handle, buf, 80);
00033 if (bytes_read != 0)
00034 {
00035
00036 for (int i = 0; i < bytes_read; i++)
00037 {
00038 if (buf[i] == '\n' || buf[i] == '\r')
00039 {
00040 newline_received = 1;
00041 }
00042
00043 }
00044
00045 fputs (buf, stdout);
00046
00047 }
00048 if (newline_received)
00049 {
00050 printf ("Enter line to send:\n");
00051 fgets (buf, 80, stdin);
00052 write_serial_communications_port (handle, buf, strlen (buf));
00053 newline_received = 0;
00054 memset (buf, 0, 80);
00055 printf ("Receiving line:\n");
00056 }
00057 }
00058 }