LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices



Reply
 
Search this Thread
Old 07-20-2004, 01:40 PM   #1
esi-eric
Member
 
Registered: May 2004
Location: Florida
Distribution: 7.2
Posts: 32

Rep: Reputation: 15
Problem in reading/writing binary data in Linux


Greetings Everyone!

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[4];

XYStatusRequest[0] = 0xB3; // this is just a request buffer to obtain data
XYStatusRequest[1] = 0x58; // from some hardware that I interface to
XYStatusRequest[2] = 0x59;
XYStatusRequest[3] = 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[12];

c = read(fd_serial_port_3, (void *) &XYStatusRequestReadback,
sizeof(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!

Eric.
 
Old 07-20-2004, 03:29 PM   #2
ddowens
LQ Newbie
 
Registered: Jul 2004
Distribution: mandrake 9.2
Posts: 2

Rep: Reputation: 0
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.

Doug
 
Old 07-20-2004, 04:09 PM   #3
esi-eric
Member
 
Registered: May 2004
Location: Florida
Distribution: 7.2
Posts: 32

Original Poster
Rep: Reputation: 15
Doug,

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!

Eric.
 
Old 07-20-2004, 05:21 PM   #4
esi-eric
Member
 
Registered: May 2004
Location: Florida
Distribution: 7.2
Posts: 32

Original Poster
Rep: Reputation: 15
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!

Eric.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Binary reading/writing in cpp kornerr Programming 1 11-27-2005 08:09 PM
problem in reading Microsoft word as a binary file ljqu_happy Programming 15 02-02-2005 11:10 AM
Problems with reading back serial binary data esi-eric Linux - Software 14 08-06-2004 02:48 PM
reading and writing to Linux partitions from windows Moebius Linux - General 2 01-21-2004 05:57 PM
Problem reading floppy after writing boot image. QtCoder Linux - General 1 10-01-2003 08:33 PM


All times are GMT -5. The time now is 11:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration