if os.path.exists('/dev/ttyAMA2'):
ser.port = "/dev/ttyAMA2"
else:
print('/dev/ttyAMA2 is present')
#9600,N,8,1
ser.baudrate = 9600
ser.bytesize = serial.EIGHTBITS #number of bits per bytes
ser.parity = serial.PARITY_NONE #set parity check
ser.stopbits = serial.STOPBITS_ONE #number of stop bits
ser.timeout = 0.5 #non-block read 0.5s
ser.writeTimeout = 0.5 #timeout for write 0.5s
ser.xonxoff = False #disable software flow control
ser.rtscts = False #disable hardware (RTS/CTS) flow control
ser.dsrdtr = False #disable hardware (DSR/DTR) flow control
try:
ser.open()
except Exception as ex:
print ("open serial port error " + str(ex))
exit()
if ser.isOpen():
try:
ser.flushInput() #flush input buffer
ser.flushOutput() #flush output buffer
time.sleep(0.1)
#write data
ser.write("rs485 communication is on, you can try to send data...\n".encode())
print("Sent successfully\n")
time.sleep(5) #wait 5
#read data
#read data
numofline = 0
print("Reading Data:")
while True:
response = ser.readline()
print(response)
numofline = numofline +1
if (numofline >= 1):