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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
12-05-2008, 04:15 PM
|
#1
|
LQ Newbie
Registered: Dec 2008
Posts: 18
Rep:
|
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
|
|
|
12-07-2008, 07:43 AM
|
#2
|
Moderator
Registered: Aug 2002
Posts: 26,457
|
|
|
|
12-08-2008, 12:46 PM
|
#3
|
LQ Newbie
Registered: Dec 2008
Posts: 18
Original Poster
Rep:
|
Hi Michale,
Thank you so much. This is what I need.
Thank you once again.
-Chris
|
|
|
12-09-2008, 05:13 PM
|
#4
|
LQ Newbie
Registered: Dec 2008
Posts: 18
Original Poster
Rep:
|
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
|
|
|
12-09-2008, 06:38 PM
|
#5
|
Moderator
Registered: Aug 2002
Posts: 26,457
|
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.
|
|
|
12-09-2008, 08:31 PM
|
#6
|
LQ Newbie
Registered: Dec 2008
Posts: 18
Original Poster
Rep:
|
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
|
|
|
12-10-2008, 12:11 AM
|
#7
|
Moderator
Registered: Aug 2002
Posts: 26,457
|
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.
|
|
|
12-10-2008, 01:01 AM
|
#8
|
LQ Newbie
Registered: Dec 2008
Posts: 18
Original Poster
Rep:
|
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
|
|
|
12-10-2008, 07:51 AM
|
#9
|
Moderator
Registered: Aug 2002
Posts: 26,457
|
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.
|
|
|
12-10-2008, 02:05 PM
|
#10
|
LQ Newbie
Registered: Dec 2008
Posts: 18
Original Poster
Rep:
|
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
|
|
|
All times are GMT -5. The time now is 12:55 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|