![]() ![]() ![]() Or as benhoyt says, skip the not equal and take advantage of the fact that b"" evaluates to false. We will no longer get raw characters from the stream in byte mode but byte objects, thus we need to alter the condition: with open("myfile", "rb") as f: To use it in v 2.5 you'll need to import it: from _future_ import with_statement Note that the with statement is not available in versions of Python below 2.5. Python 2.4 and Earlier f = open("myfile", "rb") TCSANOW specifies all option changes to occur immediately Tcsetattr(fd, TCSANOW, &options) //set the new options. Options.c_cc = 0 // Wait x * 0.1s for input (unblocks!) Options.c_cc = 0 // Wait until x bytes read (blocks!) Options.c_oflag |= OPOST // ? choosing processed output Options.c_iflag &= ~(IXON | IXOFF | IXANY) // disable software flow control Options.c_iflag &= ~INPCK // disable parity check Options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG) // choosing raw input Options.c_cflag |= CS8 /* select 8 data bits */ options.c_cflag &= ~CSIZE /* mask the character size bits */ Options.c_cflag |= (CLOCAL | CREAD) // ? enable receicer and set local mode Tcgetattr(fd, &options) //this gets the current options set for the portĬfsetispeed(&options, B9600) //input baudrateĬfsetospeed(&options, B9600) // output baudrate Perror("open_port: Unable to open /dev/ttyS0 - ") Int fd = open(str, O_RDWR | O_NOCTTY | O_NONBLOCK) // ? NDELAY or NONBLOCK? **//I tried these three methods, with little success** Int readport = open_port("/dev/ttyUSB1") If (n /* Standard input/output definitions */ ![]() Int n = write(writeport, buffer, fileLen + 1) Int writeport = open_port("/dev/ttyUSB0") #include /* POSIX terminal control definitions */ #include /* UNIX standard function definitions */ #include /* String function definitions */ Serial write: #include /* Standard input/output definitions */ Perhaps I need to use fread for that too? I tried, but I cannot figure out how to implement it for a serial port as I am relatively new to programming. ![]() I have a hunch that the problem in my code lies in the second program. The second program creates a file called "testout.jpg", and is supposed to read in the data sent from the previous program. It then closes the file, and is supposed to send that file over a serial port. The first program opens a file "test.jpg", reads it in binary mode and stores the result in a buffer. Please note, I asked a question similar to this earlier when I was at a different stage of this project.īelow are programs. I need help reading and writing binary data over a serial port, and would appreciate any advice you may have. So I searched around, and couldn't exactly find what I needed. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |