Send file via serial port using Linux and C

I am developing an application that reads data from a serial port and sends it over a TCP connection, and vice versa. Unfortunately, when reading data from the serial port, it never stops. It does not detect the EOF mark, nor EOL, nor any other special character.

So, how can I detect the end of the file (or the โ€œend of the connectionโ€) through the serial port in C and Linux?

+3
source share
5 answers

Depends on how much control you have over the protocol used for serial communication. If the files implicitly include some end-of-file marker (and, as I understand it, they donโ€™t have your post), you need to implement some kind of communication protocol for transferring files.

Some of the simplest punctures used in the days of BBS were XMODEM and its derivatives. They may be simple enough for you.

If you have a fully functional computer on the other end of the serial line, it would probably be much easier to set up a PPP link on the serial line and communicate over TCP / IP.

+6
source

. , , . - XMODEM, KERMIT ..

. TCP/IP , . SLIP PPP.

+2

" " "", ( DCD). -, .

, . , - ZMODEM - , CRC32 , 8-.

+1

:

stty -F /dev/ttySx -a

:

stty -F /dev/ttySx cooked
0

: linux, unix osx 'screen -L <serial_device > < & GT;". . -L , , . xxd, , , .

0

Source: https://habr.com/ru/post/1715787/


All Articles