Jostar,
Below is my code and output.
import os
import serial
from time import sleep
import numpy as np
from datetime import datetime
os.system(‘sudo chmod +777 /dev/ttyS0’)
print("", file=open(‘output.txt’, ‘a’))
print(datetime.now().strftime(’%Y-%m-%d-%H-%M-%S’))
def fetch_and_update_radar_data():
ser = serial.Serial ("/dev/ttyS0", 115200)
# read all the data reported at power cycle.
# no command is required from application program
msgRaw = bytearray(bytes(128))
sleep(1)
ndx = 0
while ser.in_waiting:
readByte = ser.read(1)
number = int.from_bytes(readByte, byteorder='big')
msgRaw[ndx] = number
ndx = ndx+1
msgNew = bytearray(bytes(ndx))
for x in range(ndx):
msgNew[x] = msgRaw[x]
print("Rp", datetime.now().strftime('%Y-%m-%d %H:%M:%S'), msgNew, file=open('output.txt', 'a'))
print("Rp", datetime.now().strftime('%Y-%m-%d %H:%M:%S'), msgNew)
flag = True
while flag == True:
sleep(10)
msgRaw = bytearray(bytes(256))
msgWrite = [bytes([0x53, 0x59, 0x80, 0x81, 0x00, 0x01, 0x0F, ((0x53 + 0x59 + 0x80 + 0x81 + 0x00 + 0x01 + 0x0f) & 0xFF), 0x54, 0x43]),
bytes([0x53, 0x59, 0x07, 0x87, 0x00, 0x01, 0x0F, ((0x53 + 0x59 + 0x07 + 0x87 + 0x00 + 0x01 + 0x0f) & 0xFF), 0x54, 0x43]), # out of bound status
bytes([0x53, 0x59, 0x01, 0x80, 0x00, 0x01, 0x0F, ((0x53 + 0x59 + 0x01 + 0x80 + 0x00 + 0x01 + 0x0F) & 0xFF), 0x54, 0x43]), # Heartbeat Package Inquiry
bytes([0x53, 0x59, 0x01, 0x02, 0x00, 0x01, 0x0F, ((0x53 + 0x59 + 0x01 + 0x02 + 0x00 + 0x01 + 0x0F) & 0xFF), 0x54, 0x43]), # Module Reset
bytes([0x53, 0x59, 0x02, 0xA1, 0x00, 0x01, 0x0F, ((0x53 + 0x59 + 0x02 + 0xA1 + 0x00 + 0x01 + 0x0F) & 0xFF), 0x54, 0x43]), # Product Model
]
i = 1 # change i values for selection of command
print("Sending ", msgWrite[i])
print("W", datetime.now().strftime('%Y-%m-%d %H:%M:%S') , msgWrite[i], file=open('output.txt', 'a'))
ser.write(msgWrite[i])
sleep(.1)
ndx = 0
while ser.in_waiting:
readByte = ser.read(1)
number = int.from_bytes(readByte, byteorder='big')
msgRaw[ndx] = number
ndx = ndx+1
msgNew = bytearray(bytes(ndx))
for x in range(ndx):
msgNew[x] = msgRaw[x]
print("R", datetime.now().strftime('%Y-%m-%d %H:%M:%S'), msgNew, file=open('output.txt', 'a'))
print("R", datetime.now().strftime('%Y-%m-%d %H:%M:%S'), msgNew)
def main():
#while 1:
fetch_and_update_radar_data()
main()
Out put file
Rp 2023-08-01 22:31:24 bytearray(b’\x04\xd0\xcc\xc4’)
W 2023-08-01 22:31:34 b’SY\x02\xa1\x00\x01\x0f_TC’
R 2023-08-01 22:31:34 bytearray(b’’)
W 2023-08-01 22:31:44 b’SY\x02\xa1\x00\x01\x0f_TC’
R 2023-08-01 22:31:45 bytearray(b’’)
W 2023-08-01 22:31:55 b’SY\x02\xa1\x00\x01\x0f_TC’
R 2023-08-01 22:31:55 bytearray(b’’)
Rp 2023-08-01 22:32:05 bytearray(b’Y\x80\x03\x00\x01\x044TCSY\x80\x05\x00\x04\x00_\x00Z\xeeTC’)
W 2023-08-01 22:32:15 b’SY\x02\xa1\x00\x01\x0f_TC’
R 2023-08-01 22:32:15 bytearray(b’’)
W 2023-08-01 22:32:25 b’SY\x02\xa1\x00\x01\x0f_TC’
R 2023-08-01 22:32:25 bytearray(b’’)
W 2023-08-01 22:32:35 b’SY\x02\xa1\x00\x01\x0f_TC’
R 2023-08-01 22:32:35 bytearray(b’’)
Rp 2023-08-01 22:37:14 bytearray(b’Y\xf1\x88\xf6’)
W 2023-08-01 22:37:24 b’SY\x02\xa1\x00\x01\x0f_TC’
R 2023-08-01 22:37:24 bytearray(b’’)
W 2023-08-01 22:37:34 b’SY\x02\xa1\x00\x01\x0f_TC’
R 2023-08-01 22:37:34 bytearray(b’’)
W 2023-08-01 22:37:44 b’SY\x02\xa1\x00\x01\x0f_TC’
R 2023-08-01 22:37:44 bytearray(b’’)
Rp 2023-08-01 22:38:02 bytearray(b’Y\x80\x02\x00\x01\x021TCSY\x80\x03\x00\x01\x13CTCSY\x80\x04\x00\x02\x00BtTC’)
W 2023-08-01 22:38:12 b’SY\x07\x87\x00\x01\x0fJTC’
R 2023-08-01 22:38:12 bytearray(b’’)
W 2023-08-01 22:38:22 b’SY\x07\x87\x00\x01\x0fJTC’
R 2023-08-01 22:38:22 bytearray(b’’)
W 2023-08-01 22:38:32 b’SY\x07\x87\x00\x01\x0fJTC’
R 2023-08-01 22:38:32 bytearray(b’’)