Locate P4 connector on board by referring to hardware manual and short pin 1 (RS232_TX_1) and pin 2(RS232_RX_1) to echo the transmitted data back to board. Short Type the following code in target board and save it with extension .py .
To test this python code, need to add the pyserial package in root file system in nor rootfs image, this pyserial package was not included. This will be included in sdcard image.
vi uart4.py
'''
Copy and Paste the python code on to your vi editor
and save and exit the editor.
You can also use any other editor from your host PC
to write the code with .py extension and transfer the
python code file to the RuggedBoard. To transfer files
from host PC to RB will be show in the later upcoming
section named as "Transfering files from host PC to RB"
'''
import time
import serial
def main():
# Replace '/dev/ttymxc0' with the correct UART device file
uart_port = '/dev/ttymxc0'
baud_rate = 115200
# Open the UART port
try:
ser = serial.Serial(uart_port, baud_rate, timeout=1)
print(f"Connected to {uart_port} at {baud_rate} bps")
except serial.SerialException as e:
print(f"Error: {e}")
return
try:
# Send a message
message = "Hello, UART!\n"
ser.write(message.encode())
print(f"Sent: {message}")
# Wait for a moment to receive data
time.sleep(1)
# Read and print received data
received_data = ser.read_all().decode()
print(f"Received: {received_data}")
except Exception as e:
print(f"Error: {e}")
finally:
# Close the UART port
ser.close()
print("UART port closed")
if __name__ == "__main__":
main()
To execute the code use the below command and enter anything for loopback test.