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()
print(ser.name + ’ Is open’)
time.sleep(.1)
while True:
x = ser.readline(100)
x = x.decode(‘utf-8’)
print(x)
time.sleep(1)
ser.close()