diff --git a/sensor_to_local.py b/sensor_to_local.py index 920e784..932a868 100755 --- a/sensor_to_local.py +++ b/sensor_to_local.py @@ -19,7 +19,7 @@ if __name__ == '__main__': windspeed_send = '04 03 00 00 00 02 C4 5E' # 风速查询指令 winddirection_send = '05 03 00 00 00 02 C5 8F' # 风向查询指令 - ser = serial.Serial("/dev/ttyS2", 9600) + # 发送的数据转为2进制b'\x01\x03\x00\x00\x00\x02\xc4\x0b' temp_send = bytes.fromhex(temp_send) @@ -33,6 +33,7 @@ if __name__ == '__main__': winddirection_send = bytes.fromhex(winddirection_send) while True: try: + ser = serial.Serial("/dev/ttyS2", 9600) # if ser.is_open: ser.write(temp_send) time.sleep(1) diff --git a/sensor_to_server.py b/sensor_to_server.py index d8ee4e3..d0cb285 100755 --- a/sensor_to_server.py +++ b/sensor_to_server.py @@ -23,7 +23,6 @@ def t(): windspeed_send = '04 03 00 00 00 02 C4 5E' # 风速查询指令 winddirection_send = '05 03 00 00 00 02 C5 8F' # 风向查询指令 - ser = serial.Serial("/dev/ttyS2", 9600) # 发送的数据转为2进制b'\x01\x03\x00\x00\x00\x02\xc4\x0b' temp_send = bytes.fromhex(temp_send) @@ -37,6 +36,7 @@ def t(): winddirection_send = bytes.fromhex(winddirection_send) while True: try: + ser = serial.Serial("/dev/ttyS2", 9600) # if ser.is_open: ser.write(temp_send) time.sleep(1)