我有一个配置为(Python 代码)以通过 COM 端口串行发送数据的 Digi zigbee 设备。在串行通信的另一端有一个接收数据的嵌入式板。
将digi(发送数据)连接到嵌入式板后,发送少量数据后的digi重新启动(COM PORT关闭)。但是嵌入式板在整个期间都保持活跃。
这个嵌入式板有一个软件,通过它我可以看到它的日志。当我检查日志时,我收到了一些数据(三个传感器值)并且 digi 设备死了。我不知道问题出在哪里。是使用digi-zigbee设备发送数据还是PYTHON CODE(用于digi设备)还是接收数据的嵌入式板?
这里只是python源代码的一部分:
open()
flushInput()
flushOutput()
while True:
# Retrieve a sample reading from the LT
io_sample = xbee.ddo_get_param(sensor_address, "is")
light = parseIS(io_sample)["AI1"]
temp = parseIS(io_sample)["AI2"]
hum = parseIS(io_sample)["AI3"]
mVanalog = (float(temp) / 1023.0) * 1200.0
temp_C = (mVanalog - 500.0)/ 10.0 # - 4.0
lux = (float(light) / 1023.0) * 1200.0
print "hum:%f" %hum
sync=254
temp=round(temp_C,2)
light=round(lux,2)
no_temp = len(str(temp))
no_light = len(str(light))
total_length=no_temp+no_light+3+3
if total_length<256:
low_byte=total_length
high_byte=0
else:
low_byte=total_length%256
high_byte=high_byte/256
msg_id_low=0
msg_id_high=0
checksum=low_byte+high_byte+msg_id_low+msg_id_high+ord('#')+ord(':')+ord(',')
t=str(temp)
for c in t:
if c == '.':
checksum+=ord('.')
else:
checksum+=ord(c)
t=str(light)
for c in t:
if c == '.':
checksum+=ord('.')
else:
checksum+=ord(c)
checksum=256-(checksum%256)
if checksum == 256:
checksum=0
print "Checksum Value after applying mod operator:%d" %checksum
packet=str(chr(254))+str(chr(low_byte))+str(chr(high_byte))+str(chr(msg_id_low))+str(chr(msg_id_high))+str('#')+str(temp)+str(':')+str(light)+str(',')+str(chr(checksum))
print "packet:%s" %packet
bytes_written = write(packet)
print "bytes_written : %s value : %s" %(bytes_written,packet)
time.sleep(5)
此代码从传感器获取温度和光值并将其转换为要发送到嵌入式板的数据包(同步、校验和等)。