0

I have a question linked to Linux and serial port.

I want to be able to receive and send messages to a dedicated serial port and to redirect it to another port (/dev/tty).

For the first part, I’m able to dialog with my hardware equipment without any problem, but I’m just wondering if it’s possible to intercept and redirect message coming from a serial port #1 to another port #2.

To give more context, I had used a GPS Antenna and NTP open source software for years.

Since 2018, the new GPS antenna protocol has modified the order of bytes in the message used by NTP to steer and now it’s not working anymore.

So my idea is to put a simple C program (middleware) which fixes this byte ordering; but I’m wondering if I have to build a kernel-specific module or if it can be done in another way. The NTP software uses the symbolic link to dialog.

Thanks for your help.

Joel C
  • 2,958
  • 2
  • 15
  • 18
Sined40
  • 11
  • 1
  • 4
  • IMO there may not be a *"simple C program which fixes this byte ordering"*. How are you going to (robustly) identify which is the high-order byte versus the low-order byte? *"I’m wondering if I have to build a kernel-specific module"* -- Typically in Linux, you do not want to access the actual *"serial port"* or UART, but rather a serial terminal device node, e.g. **/dev/ttyS0** with its termios interface. See https://stackoverflow.com/questions/5379720/accessing-a-serial-port-from-a-linux-kernel-module – sawdust Jan 23 '20 at 07:54

1 Answers1

0

You can probably use a simple redirect, look here: Pipe One Serial Port to Another in Linux

If the ports are in different rates you can use stty or perhaps screen to adjust: https://unix.stackexchange.com/a/117064

If you need it to be in c program to manipulate it you can use the following: https://stackoverflow.com/a/6947758/8901188

Using c it will need to run in an infinite loop so it can constantly read, manipulate and write the data.

dani39
  • 153
  • 8
  • *"If you need it to be in c program to manipulate it you can use the following:..."* -- You provided a link to the "inferior" answer (that has more complaints of problems). – sawdust Jan 23 '20 at 08:04