#include #include #include #include #include int main (int argc, char *argv[]) { struct termios oldtio, newtio; int fd; int file; int rdsz; char byte[1]; long baudrate; FILE *f; baudrate = B57600; if ((fd = open( "/dev/ttyUSB0", O_RDWR| O_NOCTTY)) <0) { perror("Could not open ttyS1 device"); return (-1); } if (tcgetattr(fd, &oldtio) < 0) { perror("Could not get term attributes"); return (-1); } /* 8 bits, baud rate and local control */ bzero(&newtio, sizeof(newtio)); newtio.c_cflag = CS8 | CLOCAL|baudrate|CREAD; newtio.c_lflag = 0; newtio.c_oflag = 0; newtio.c_iflag = IGNPAR; newtio.c_cc[VMIN] = 2; newtio.c_cc[VTIME] = 10; cfsetospeed( &newtio, baudrate); cfsetispeed( &newtio, baudrate); tcflush( fd, TCIFLUSH); if (tcsetattr(fd, TCSANOW, &newtio) < 0) { perror("Could not set term attributes"); return (-1); } if( NULL == ( f = fopen( argv[1], "rb"))) { perror("Could not open file"); return (-1); } else { /* Soubor se podarilo otevrit */ printf("Upload started\n"); while (! feof(f)) { byte[0]=fgetc( f); write( fd, byte, 1); } fclose( f); } if (tcsetattr(fd, TCSANOW, &oldtio) < 0) { perror("Could not set previous term attributes"); return (-1); } close( fd); }