diff options
author | Pavel Vymetálek <pavel@vym.cz> | 2019-03-16 21:36:55 +0100 |
---|---|---|
committer | Pavel Vymetálek <pavel@vym.cz> | 2019-03-16 21:36:55 +0100 |
commit | 1d21d34fa71ab52fc4725c6df3b259ec664e1e1c (patch) | |
tree | a199308b8d104391f199e8d315117263ad27e6f5 /sercp.c | |
parent | cde51f8e3d769ea26870a5fed5c0f60c9343a9c4 (diff) | |
download | sercp-pc-1d21d34fa71ab52fc4725c6df3b259ec664e1e1c.tar.gz |
Upravy nastaveni seriaku. Chodi na MacOS - Delal to Otis
Diffstat (limited to 'sercp.c')
-rw-r--r-- | sercp.c | 26 |
1 files changed, 14 insertions, 12 deletions
@@ -42,7 +42,7 @@ #include <libgen.h> #include <getopt.h> #include <termios.h> - #include <error.h> + #include <err.h> #include <sys/stat.h> #include <sys/ioctl.h> #include <sys/signal.h> @@ -210,7 +210,7 @@ void uSleep(int waitTime) { QueryPerformanceCounter((LARGE_INTEGER *) &time2); } while ((time2 - time1) < waitTime); #else - uSleep(waitTime); + usleep(waitTime); #endif } @@ -376,7 +376,7 @@ void sercpRecv(void) { uint32_t recv_length = 0; // zatim prijatych dat ze souboru #ifndef __WIN32 int result; - int err; + int _err; #endif FILEINFO *p_fileinfo = &fileinfo; unsigned char *p_buff = buff; @@ -426,8 +426,8 @@ void sercpRecv(void) { exit (EXIT_FAILURE); #else - err = errno; - error (1, err, "can't open output file"); + _err = errno; + err (1, "can't open output file"); #endif } } else { @@ -654,6 +654,7 @@ int OpenUart() { return(-1); } tcgetattr(serial_fd, &oldtio); /* save current port settings */ + bzero(&newtio, sizeof (newtio)); switch (baud_rate){ case 115200: newtio.c_cflag = B115200; @@ -661,8 +662,6 @@ int OpenUart() { case 57600: newtio.c_cflag = B57600; break; - default: - baud_rate = 38400; case 38400: newtio.c_cflag = B38400; break; @@ -681,14 +680,17 @@ int OpenUart() { case 1200: newtio.c_cflag = B1200; break; + default: + baud_rate = 38400; + newtio.c_cflag = B38400; + break; } + cfmakeraw(&newtio); + cfsetspeed(&newtio, baud_rate); newtio.c_cflag |= CS8 | CLOCAL | CREAD | CRTSCTS; // CSTOPB - dva stop bity NEE printf ("Serial device: %s, communication speed is: %d Bd\n", MODEMDEVICE, baud_rate); - newtio.c_iflag = 0; - newtio.c_oflag = 0; - newtio.c_lflag = 0; - newtio.c_cc[VMIN] = 0; - newtio.c_cc[VTIME] = 10; + newtio.c_cc[VMIN] = 1; + newtio.c_cc[VTIME] = 0; tcsetattr(serial_fd, TCSANOW, &newtio); tcflush(serial_fd, TCIOFLUSH); return 0; |