Home > Uncategorized > Sending Hex Text on Serial Port on Windows

Sending Hex Text on Serial Port on Windows

March 21st, 2019

Many small hardware communicate on UART Serial port, often using a USB to UART chip. You sometimes need to communicate with these devices from your Windows machine - and this is the topic of this blog.

Using Python

Python comes to your rescue. With increasing use of Python it has become a de facto standard not only for many front and back end web software and services but also for controlling hardware. Sending data to Serial Port using Python is easy.

Install PySerial

Once you have installed Pythnon ( the latest version at the time of writing is 3.7) and and the pip, you need to install the pyserial library

pip install pyserial

The Serial Port code

You need to write the following code to send the Hex Data to Serial Port and read it back.

import serial

ser = serial.Serial("COM5", 9600) command = b'\x41\x42\x43\x44\x48\x65\x6c\x6c\x6f'

ser.write(command)

s = ser.read(9)

print(s)

You could also use a software called Realterm - It does work, though we are not sure if it could be harmful.

Uncategorized

  1. No comments yet.
  1. No trackbacks yet.