LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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, 12: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, 02: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, 03: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, 04: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
Problems with reading back serial binary data esi-eric Linux - Software 15 10-03-2018 09:13 AM
Binary reading/writing in cpp kornerr Programming 1 11-27-2005 07:09 PM
problem in reading Microsoft word as a binary file ljqu_happy Programming 15 02-02-2005 10:10 AM
reading and writing to Linux partitions from windows Moebius Linux - General 2 01-21-2004 04:57 PM
Problem reading floppy after writing boot image. QtCoder Linux - General 1 10-01-2003 07:33 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 12:34 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
Open Source Consulting | Domain Registration