Read and write through UART port

Hello Team,

I have flashed linux kernel version 4.9 (L4T 32.4.4) Ubuntu 18.04 , in my Jetson NX SOM module carrier board.

  1. what are the commands/ preferebly scripts by which i can read and write in/from UART.
  2. What will be changes in scripts if our host device be windows or Linux.

On the Linux side there is a device associated with a serial UART. You have to know which UART you are using (and if that UART is already used by something like serial console, then you have to stop the other user first). Then it is just reading or writing from that device’s file for the most part like reading or writing from any file.

However, device special files also have “IOCTL” functions for extended functionality not covered by ordinary read/write. It depends on the exact driver being used as to which IOCTL matters. An example of a non-read/write function requiring an IOCTL call is to set speed or stop bits. If the ports at each end are already running correctly, then there is no need for an IOCTL of any kind. The default for ports on Jetson’s is 115200 8N1 (speed 115200 baud, 8-bit data, no stop bit, 1 parity bit), and if your port on Windows runs with the same setting, then everything is entirely just file reads/writes.

Almost all issues people have with UARTs are independent of whether the other end is Windows or Linux or anything else. Much of it is getting the two ports set up with matching parameters, e.g., if one end runs speed 9600, and the other runs speed 115200, then it will fail. Also, the UARTs on the Jetsons use a logic level of 3.3V, and if your other UART runs on a different voltage, then this will fail.

I don’t know about read/write to UARTs (COM ports) on Windows, but I suspect it is much like Linux and does not require much in the way of special handling so long as you know you are going to the right UART and that the UART is running with the correct setting (default of 115200 8N1).

Hello Team,

Sorry but still i am not clear , like how can we read/write data from uart for both Windows and Linux host OS .

please help me with any such script.

I don’t really work on Windows. In Linux, anything which reads or writes a file will work if you name the UART port’s file (and if the port is correctly configured). In Windows I suspect it is similar, but it likely has some sort of COM port command. On the Linux side this is easily done with the bash shell’s command line, Python, C, C++, Java, or any language at all…every language in Linux has the ability to read or write a file.

I have no way to help with Windows since it does not necessarily treat I/O as a file read/write the same way as Linux.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.