LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-06-2015, 10:25 PM   #1
rpbulls
LQ Newbie
 
Registered: Jul 2015
Posts: 8

Rep: Reputation: Disabled
How do I read all the data from a serial port?


All,
I'm trying to talk to a modem through a usb2serial port interface. I managed to open a port, send commands to the modem and read back data.
Currently, i'm doing a simple read of responses using

read (int fd, char *response, 8)

Essentially, i'm reading 8 bytes at a time (note that the modem init was done at 1152000 8n1). Also, note that i'm monitoring for responses from the serial port using "select".

However, the response from the modem is of varying length. And, a fixed number of byte reads seems to be either missing some of the bytes or adding garbage to the "response" string.

How can i effectively read the exact number of bytes (no more no less) from the modem?

Appreciate help!
 
Old 08-07-2015, 03:10 PM   #2
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,982

Rep: Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626
Generally you issue command AT (attention) to a modem assuming you have the correct serial speeds. That speed you posted seems very wrong.
 
Old 08-07-2015, 03:28 PM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,702

Rep: Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896
I assume it is a typo i.e 115200. Its been awhile since I've played with a MODEM. You can look at the return value to see the number or characters that was actually read. Depending on how it is configured does it return an OK or other character(s) when the command completes?
 
Old 08-08-2015, 08:24 AM   #4
rpbulls
LQ Newbie
 
Registered: Jul 2015
Posts: 8

Original Poster
Rep: Reputation: Disabled
Thanks for the responses. Sorry about the typo in the serial port config (115200, it shudda been). Quite silly of me to not have realized that read() returns the actual byte count. Worked like a charm!
 
  


Reply

Tags
serial port



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
the get data from serial port function read() blocks when data not available DEF. Programming 3 11-17-2014 07:11 AM
Unable to read data from Serial port tanu1985 Linux - Enterprise 2 10-12-2011 05:05 PM
[SOLVED] Serial port : Read data problem, not reading complete data anujmehta Linux - Networking 5 09-06-2010 06:10 AM
Minicom -- want to read data coming in a serial port ihopeto Linux - Newbie 2 04-12-2009 09:46 PM
Why can't I read in data from the serial port using a bash script? tjt Linux - Newbie 1 06-17-2004 12:21 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:17 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