From 479abdfc5ffbaafa4b00f46cf589309dc0ec071b Mon Sep 17 00:00:00 2001 From: "Haoran S. Diao" <0@hairydiode.xyz> Date: Sat, 13 Apr 2019 13:03:52 -0400 Subject: added RS-232 Library, also covered by the GPL --- RS-232/demo_tx.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 RS-232/demo_tx.c (limited to 'RS-232/demo_tx.c') diff --git a/RS-232/demo_tx.c b/RS-232/demo_tx.c new file mode 100644 index 0000000..bd43fb4 --- /dev/null +++ b/RS-232/demo_tx.c @@ -0,0 +1,66 @@ + +/************************************************** + +file: demo_tx.c +purpose: simple demo that transmits characters to +the serial port and print them on the screen, +exit the program by pressing Ctrl-C + +compile with the command: gcc demo_tx.c rs232.c -Wall -Wextra -o2 -o test_tx + +**************************************************/ + +#include +#include + +#ifdef _WIN32 +#include +#else +#include +#endif + +#include "rs232.h" + + + +int main() +{ + int i=0, + cport_nr=0, /* /dev/ttyS0 (COM1 on windows) */ + bdrate=9600; /* 9600 baud */ + + char mode[]={'8','N','1',0}, + str[2][512]; + + + strcpy(str[0], "The quick brown fox jumped over the lazy grey dog.\n"); + + strcpy(str[1], "Happy serial programming!\n"); + + if(RS232_OpenComport(cport_nr, bdrate, mode)) + { + printf("Can not open comport\n"); + + return(0); + } + + while(1) + { + RS232_cputs(cport_nr, str[i]); + + printf("sent: %s\n", str[i]); + +#ifdef _WIN32 + Sleep(1000); +#else + usleep(1000000); /* sleep for 1 Second */ +#endif + + i++; + + i %= 2; + } + + return(0); +} + -- cgit v1.1