diff options
Diffstat (limited to 'sercp.c')
-rw-r--r-- | sercp.c | 17 |
1 files changed, 12 insertions, 5 deletions
@@ -24,7 +24,6 @@ #include <stdio.h> #include <stdint.h> #include <io.h> - #include <fcntl.h> #include <windows.h> #include <getopt.h> #include <strings.h> @@ -65,7 +64,7 @@ #define FALSE 0 #define true 1 #define TRUE 1 -const char* _version = "v0.3.4"; +const char* _version = "v0.3.5"; // SERIAL FILE *tapout_fd = NULL; int is_outfile = 0; @@ -86,6 +85,10 @@ int scp = 0; int is_scp_read = 0; int is_continue = 1; +// prototypes + +void sleep_ms(int milliseconds); + char SERIALDEVICE[128] = { #ifdef _WIN32 "\\\\.\\COM1" @@ -169,7 +172,7 @@ void TestArgs (int argc, char *argv[]) #else sprintf(SERIALDEVICE, "%s", optarg); #endif - printf ("Serial port: %s\n", SERIALDEVICE); +// printf ("Serial port: %s\n", SERIALDEVICE); break; case 'b': baud_rate = atoi(optarg); @@ -204,6 +207,7 @@ void TestArgs (int argc, char *argv[]) void FlushSerialPort() { if (serial_fd) { + sleep_ms(20); #ifdef _WIN32 PurgeComm(serial_fd, PURGE_RXABORT| PURGE_TXABORT | PURGE_RXCLEAR | PURGE_TXCLEAR); #else @@ -652,6 +656,8 @@ void sercpSend(void) { } } printf("\nFile sent...\n"); + // FIXME na __APPLE__ tady pomaha pockat + // sleep_ms(5000); fclose(tap_fd); } @@ -699,13 +705,14 @@ int OpenUart() { #else struct termios oldtio, newtio; /* open the device to be non-blocking (read will return immediatly) */ - serial_fd = open(SERIALDEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK); + serial_fd = open(SERIALDEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK | O_NDELAY); if (serial_fd < 0) { perror(SERIALDEVICE); return(-1); } tcgetattr(serial_fd, &oldtio); /* save current port settings */ bzero(&newtio, sizeof (newtio)); + cfmakeraw(&newtio); switch (baud_rate){ case 115200: newtio.c_cflag = B115200; @@ -736,7 +743,6 @@ int OpenUart() { newtio.c_cflag = B38400; break; } - cfmakeraw(&newtio); cfsetspeed(&newtio, baud_rate); #if defined (__APPLE__) || defined (BSD) // newtio.c_cflag |= CS8 | CLOCAL | CREAD | CCTS_OFLOW | CRTS_IFLOW; @@ -751,6 +757,7 @@ int OpenUart() { newtio.c_cc[VMIN] = 0; newtio.c_cc[VTIME] = 0; tcsetattr(serial_fd, TCSANOW, &newtio); + sleep_ms(20); tcflush(serial_fd, TCIOFLUSH); return 0; #endif |