Problem in reading/writing binary data in Linux
I am currently running Linux 7.2 and I am having some problems in reading and writing the serial ports with "binary" data. I can properly set up the serial port for reading and writing of ASCII data, but when it comes to binary data then I have the problem.... some of my code looks like the following:
unsigned char XYStatusRequest;
XYStatusRequest = 0xB3; // this is just a request buffer to obtain data
XYStatusRequest = 0x58; // from some hardware that I interface to
XYStatusRequest = 0x59;
XYStatusRequest = 0x0D;
Then, I write the data out of serial port #3 with the assistance of a "timer" as follows....
c = write(fd_serial_port_3, (void *) &XYStatusRequest, sizeof(long));
This code appears to be working for the writing of the binary data out of the serial port to the hardware device or to Procomm. If you see a problem in how I have coded it, please let me know as well. Thank you very much!
Then, the readback function expects 12 bytes of binary data from serial port #3. This code to read back the data from serial port #3 with the assistance of a "timer" looks like the following....
unsigned char XYStatusRequestReadback;
c = read(fd_serial_port_3, (void *) &XYStatusRequestReadback,
THIS code FAILS to retrieve the binary data and only will retrieve ASCII data, and to boot it needs a <CR> or 0x0D on the end of the data to even read the bytes that I send to it!
I have tried to sending the data to the port via Procomm, but with no luck so far!
Any assistance that you can afford to me would be greatly appreciated! Thank you very much for all of your time and consideration!
Try the serial programming how-to at www.tldp.org. Unix/Linux serial ports are typically set up for use by terminals and would need to be set to 'raw' or 'non-canonical' mode for binary (non-ASCII) data.
Thank you so very much for the advice and the reply! I shall let you know
if I get it going via the link you gave to me. Thank you very much once again!
Thank you very much Doug as my problem is now solved!!!!! I did like you said and programmed my Linux serial port for their typical set up for use by terminals and their need to be set to 'raw' or 'non-canonical' mode for binary (non-ASCII) data. After changing my serial port configuration everything worked!
Thank you so very much once again!
|All times are GMT -5. The time now is 02:24 AM.|