LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 12-05-2008, 04:15 PM   #1
linux_chris
LQ Newbie
 
Registered: Dec 2008
Posts: 18

Rep: Reputation: 0
Reading/Writing to serial ports (Rs-232).


Hi, I am about to write a program to listen and read data from /dev/ttyS0 and write the data to /dev/ttyS1 after processing. Also, the same time I need to listen to /dev/ttyS1 and write to /dev/ttyS0 if any data arrived at /dev/ttyS1.

Can you please give me your idea to implement this.

Thanks in advance,
Chris
 
Old 12-07-2008, 07:43 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 26,457

Rep: Reputation: 6216Reputation: 6216Reputation: 6216Reputation: 6216Reputation: 6216Reputation: 6216Reputation: 6216Reputation: 6216Reputation: 6216Reputation: 6216Reputation: 6216
Here is a good starting point
http://www.faqs.org/docs/Linux-HOWTO...ing-HOWTO.html
 
Old 12-08-2008, 12:46 PM   #3
linux_chris
LQ Newbie
 
Registered: Dec 2008
Posts: 18

Original Poster
Rep: Reputation: 0
Hi Michale,

Thank you so much. This is what I need.

Thank you once again.

-Chris
 
Old 12-09-2008, 05:13 PM   #4
linux_chris
LQ Newbie
 
Registered: Dec 2008
Posts: 18

Original Poster
Rep: Reputation: 0
Hi Michale,

I am able to read and write both ttyS0 and ttyS1 simultaneously.

One more help. Now I send/read only the text(chars). How can I send/read files (.xls, .ini, .txt)?

PS: The requirement is, the microcontroller should be capable of receiving text (stream of chars) and files over RS-232.

Thanks in Advance,
-Chris
 
Old 12-09-2008, 06:38 PM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 26,457

Rep: Reputation: 6216Reputation: 6216Reputation: 6216Reputation: 6216Reputation: 6216Reputation: 6216Reputation: 6216Reputation: 6216Reputation: 6216Reputation: 6216Reputation: 6216
There really is no difference. A byte is a byte. Just open the file as binary vs text, read in a character and write to the serial port. Is this a homework project?

Code:
 
 char key;

  key=0x02;
  write(handler,&key,1);

Last edited by michaelk; 12-09-2008 at 06:39 PM.
 
Old 12-09-2008, 08:31 PM   #6
linux_chris
LQ Newbie
 
Registered: Dec 2008
Posts: 18

Original Poster
Rep: Reputation: 0
Hi Michale,

Thanks. It is an actual project.

We have a medical device which has a PDA (windowsCE) as a client and a server (ELAN SC520 microcontroller and linux 2.4) which controlls a set of sensors. The server reads the sensors over RS-232 (/dev/ttyS1) and it will process the data and send it the PDA over RS232 (/dev/ttyS0). Meantime, the PDA will send some command to the server to controll the sensor over /dev/ttyS0 and also it will send some configuration files (.ini, .txt, .dat) to the server. Server will process the data received from PDA (/dev/ttySo) and it will send it to sensor board (/dev/ttyS1).

I am able to read and write data over /dev/ttyS0 and /dev/ttyS1. (The credit goes to you).

Now, the problem is how can I differentiate the data which I am getting from /dev/ttyS0 is whether it is a plain text or a file?. If it is a plain text, I have to process and send it /dev/ttyS1 and if it is a file then I need to copy it to a path.

Help needed.

Thanks in Advance,
-Chris
 
Old 12-10-2008, 12:11 AM   #7
michaelk
Moderator
 
Registered: Aug 2002
Posts: 26,457

Rep: Reputation: 6216Reputation: 6216Reputation: 6216Reputation: 6216Reputation: 6216Reputation: 6216Reputation: 6216Reputation: 6216Reputation: 6216Reputation: 6216Reputation: 6216
One idea would be to use techniques similar to dialup modems and Bulletin Board Systems (BBS). Dial up modems use an escape sequence when differentiating between commands and data. The escape code is +++. To hangup the commamd is +++ATH.

So if uploading a file you would first send an attention command to the controller and then something similar to the zmodem or ymodem protocols. It basically transmits the file name, and number of bytes and the data.
 
Old 12-10-2008, 01:01 AM   #8
linux_chris
LQ Newbie
 
Registered: Dec 2008
Posts: 18

Original Poster
Rep: Reputation: 0
1. You mean I need to send the data something like this
+++COMMAND+++FILENAME+++NUMBER-OF-BITES+++DATA
In this case, how can I set the buffer size in the controller?

2. Or I need to use some other protocols (ymodem/zmodem)?

But our kernel provides very limited functions and protocols.
We have pppd running on the controller.
3. Is it possible to to upload files using PPP? If so, how can I do it? Do you have any documents or books on that?

Thank you so much for your help.

Thanks
- Chris
 
Old 12-10-2008, 07:51 AM   #9
michaelk
Moderator
 
Registered: Aug 2002
Posts: 26,457

Rep: Reputation: 6216Reputation: 6216Reputation: 6216Reputation: 6216Reputation: 6216Reputation: 6216Reputation: 6216Reputation: 6216Reputation: 6216Reputation: 6216Reputation: 6216
The +++command will tell the server that you are going to send a file vs a command. The data following +++command will be the file transfer protocol.

By what process or application are you using to send commands to the server from the PDA vs configuration files.
 
Old 12-10-2008, 02:05 PM   #10
linux_chris
LQ Newbie
 
Registered: Dec 2008
Posts: 18

Original Poster
Rep: Reputation: 0
Hi Michale,

For the time beeing the config files are part of the Linux Live CD (for the server). So, not able to modify it dynamically.
We need to implement a way to transfer the files also.

I will try to implement what you said.

Thanks for your help.

-Chris
 
  


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
Reading and Writing to a Serial Port without SU Steef223 Programming 2 06-16-2008 10:16 AM
Serial Port (RS-232) programming on a Linux Machine tmclint Linux - Software 2 03-26-2008 09:36 PM
Facing problems in reading from and writing to serial port. vineel Linux - Hardware 2 02-27-2008 03:18 PM
I want to sent string out to serial port com1 (RS-232) lek171 Programming 1 12-25-2005 04:44 PM
reading and writing to a serial device (modem) Xanadu Linux - Laptop and Netbook 0 01-04-2005 11:05 AM

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

All times are GMT -5. The time now is 12:55 PM.

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