test_sercom.c

00001 /*
00002  * @(#)test_sercom.c       07/08/12
00003  * 
00004  * Description  : Test program for the "sercom" library.
00005  *
00006  * License      : GNU GPL v.2
00007  * Contacts     : Tran Duy Khanh (www.tran.cz)
00008  */
00009 #include <stdio.h>
00010 #include <string.h>
00011 #include <stdlib.h>
00012 #include <sercom.h>
00013 
00014 #define BUF_MAX_LEN             255
00015 
00016 int main()
00017 {
00018         struct sercom_data sercom;
00019         unsigned char stop = 0;
00020         char buf[BUF_MAX_LEN];
00021         ssize_t len;
00022         int cnt = 0;
00023 
00024         /* communication settings */
00025         strcpy((char *)&sercom.devname, "/dev/ttyS0");
00026         sercom.baudrate = 19200;
00027         sercom.parity = SERCOM_PARNONE;
00028         sercom.databits = 8;
00029         sercom.stopbits = 1;
00030 
00031         /* open communication */
00032         sercom_open(&sercom);
00033 
00034         /* receive loop */
00035         while (!stop) {
00036                 printf(".");
00037                 fflush(stdout);
00038                 usleep(100000);
00039                 len = sercom_read(&sercom, buf, BUF_MAX_LEN);
00040                 if (len > 1)
00041                         printf("%d:(%d):%s\r\n ", cnt++, len, buf);
00042         }
00043 
00044         /* close communication */
00045         sercom_close(&sercom);
00046 
00047         return 0;
00048 }

Generated on Thu Sep 13 11:28:28 2007 for DCE-Eurobot by  doxygen 1.5.3