Find the answer to your Linux question:
Results 1 to 6 of 6
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Writing files to serial C

    How do i write files (like a .jpg) to the serial port and have a pretty reliable stream of data that will go to another serial port? I'm looking to transfer about 1MB of data with no restrictions on time, however data has to be accurate. I'm thinking that it would be easy to have hardware flow control (i'm thinking that this will get handled automatically by the OS if it is enabled in the code) as a means of data integrity and making sure there are no buffer problems. Please help me with what direction i should take this.

    I have read many articles on the internet which led me to libcurl and ftplib. I was thinking of using the libraries, but when it came down to it, i would probably have to write my own serial driver. Basically, all i want is data to be passed from one terminal to another through a serial port.

  2. #2
    Linux User
    Join Date
    Aug 2005

    File abstraction...

    You should open the device file rappresenting the serial port you want to use...

    so in your program you should open /dev/ttyS[0-4] files. Writing on them you send data, reading on it you receive data.

    About sending there are no tricks... reading from a serial port can be tricky: I'm not sure read system call will blocks and should handle the read operation with a timeout parameter.

    Hardware flow control will be handled by the kernel, but it should be customizable with the ioctl routine...
    When using Windows, have you ever told "Ehi... do your business?"
    Linux user #396597 (

  3. #3
    OK...i got code working with the serial port...however only 79 bytes are being read by the receiving machine. the sending machine seems to be sending all the data ok. i set the bufferes for 255...any suggestions? i could post code if you like...but they are mostly similar to the samples codes for the serial howto's, i have just modularized them, and added somethings that i thought necessary. I have flow control setup for hardware, so i'm guessing the kernel is taking care of that. please help!...i almost got ascii completely working, after i'll try pictures..

  4. $spacer_open
  5. #4
    It may seem a little silly for me to be so non-assuming, but...

    If you are going to use hardware flow control, you should definitely make sure your hardware sockets/plugs and cables are properly set up to correctly transfer all of the hardware signals between the computers -- if they are "defeated", so will be your flow control...

    If you are using an RS-232 to RS-232 connection:

    Understand that this protocol was designed for communications between a computer and a modem - not computer to computer - and is not truely compatible with itself pin to pin (although it can be made to work). It is very common for RS-232 sockets/plugs/cables to "tie off" the hardware control signals, reducing it to a three-wire "free-wheeling" bi-directional communications channel... Make sure your sockets/plugs and cable are not wired in the "three-wire" configuration...

    I have not looked at the kernel code... ;however, I am pretty sure it has probably been written a lot more intellegently than the code which can be found in most of the BIOSs that are out there -- I have discovered that [the BIOS code that I have tried it with (well tested)] doesn't seem to handle "full mode" hardware flow control very well... (random bits seem to find their way into the bit bucket) If your hardware is hooked up correctly, the Linux kernel (if on both ends) can probably handle it just fine.

    If you are using USB/USB, then you can probably expect a seemless connection (from HW POV) - especially if both boxes have Linux on them.

  6. #5
    Well, i'm using a USB to serial adapter with a NULL modem connector connected in between the two devices. I guess i should do a continuity check for the connector just to check that that CTS and RTS lines are indeed connected to each other. If they are i have no idea what is going on.
    edit: i've checked the connections, everything is i don't know...

  7. #6
    Hardware O.K.? --- post the code?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts