Reading Serial Data in a Python Script

I’ve recently had the idea(and I’m not the first one) to read in the position of a tag node by directly connecting through the serial port; specifically using a python script. I’ve been able to do so using programs like putty and teraterm but have been unable to do so in Python. The difficulty is that in order to access the data on the tag node you first must hit enter twice. This is difficult in python because you have to encode the “enter” key with a ASCII equivalent. I’ve tried to do so by using the ASCII equivalent for enter, “0x0D”, but have been unsuccseful. My code looks like this.

import serial
import time

ser = serial.Serial(‘COM7’, 115200, timeout=0, parity = serial.PARITY_EVEN, rtscts=1)

apg = “apg”
apg = apg.encode(‘utf-8’)

if ser.isOpen():
print( + ’ Is open’)

while True:
x = ser.readline(100)
x = x.decode(‘utf-8’)


you forgot to write to UART, where is your write data to set the UART to SHELL mode and ser.write(apg) function?


-- coding: utf-8 --

import serial, time

class DecawaveCmds:
shell_mode = b’\x0D\x0D’
apg = b’apg\n’

ser = serial.Serial(“COM10”, 115200, timeout=0.1)


st = # len 225
data = st
print ("DATA: ", data)
print (“LEN: “, len(data))
print (”------------------------\n”)


st =
print ("Data: ", st)
print ("LEN: ", len(st))

If you want it perriodically, add some delay and loop when sending Cmds.apg
Have a nice day.
Reagrds Pavol