LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Reading/Writing to serial ports (Rs-232). (https://www.linuxquestions.org/questions/linux-software-2/reading-writing-to-serial-ports-rs-232-a-688608/)

linux_chris 12-05-2008 03:15 PM

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

michaelk 12-07-2008 06:43 AM

Here is a good starting point
http://www.faqs.org/docs/Linux-HOWTO...ing-HOWTO.html

linux_chris 12-08-2008 11:46 AM

Hi Michale,

Thank you so much. This is what I need.

Thank you once again.

-Chris

linux_chris 12-09-2008 04:13 PM

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

michaelk 12-09-2008 05:38 PM

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);


linux_chris 12-09-2008 07:31 PM

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

michaelk 12-09-2008 11:11 PM

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.

linux_chris 12-10-2008 12:01 AM

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

michaelk 12-10-2008 06:51 AM

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.

linux_chris 12-10-2008 01:05 PM

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 11:20 AM.