我写了一个小程序来在RasPi和Arduino之间通信。我可以完美地将消息从RasPi发送到Arduino。 Arduino将读取传入的消息,并做出适当的响应。当RasPi正在读取Arduino消息时,会发生问题。
arduino发送“ 2,2,'A','B','C',(crc)“。我可以通过在rs485网络上附加第二个arduino来确认这一点。 Python将此视为乱码,并给了我以下信息:
b'\xd5'
b'i'
b'\x8a'
b'j'
b'z'
b'\xf6'
b'T'
b'{'
b'\xf6'
b'\x8c'
b'\xe2'
b'\xfe'
Python代码(不是完整的代码,而是相关的内容):
data = bytearray()
info = ord('A')
data.append(info)
sendMsg(2, len(data), data)
while(True):
inByte = rs.read()
print(inByte)
答案 0 :(得分:0)
您需要解码数据。
尝试
var myArray = [ [ 'Procare Fitted Hospital Bed Bottom Sheet, Ivory',
'DT4098',
'Demo',
null,
12300,
2],
[ 'Essential Medical Supply Deluxe Complete Hospital Bed Set',
'ERT665',
'Demo',
null,
11790,
2],
[ 'Dr. Morepen St 04 Acoustic Stethoscope',
'DT4098',
'Demo',
null,
21237,
2],
[ 'CosmoCare KLife 5 Para Patient Monitor',
'YTT690',
'Demo',
null,
11000,
2],
[ 'CosmoCare KLife 5 Para Patient Monitor',
'YTT690',
'Demo',
null,
11000,
2],
[ 'CosmoCare KLife 5 Para Patient Monitor',
'YTT690',
'Demo',
null,
11000,
2],
[ 'CosmoCare KLife 5 Para Patient Monitor',
'YTT690',
'Demo',
null,
11000,
2],
[ 'Dr. Morepen St 04 Acoustic Stethoscope',
'DT4098',
'Demo',
null,
21237,
2],
[ 'Essential Medical Supply Deluxe Complete Hospital Bed Set',
'ERT665',
'Demo',
null,
11790,
2],
[ 'Essential Medical Supply Deluxe Complete Hospital Bed Set',
'ERT665',
'Demo',
null,
11790,
2] ];
let duplicates = [];
let output = myArray.reduce((t, i) => {
if(duplicates.includes(i[1])) {
let myArray = t.filter((item) => item[1] == i[1])[0];
myArray[5] += i[5];
t = t.filter((item) => item[1] != i[1]);
i = myArray;
} else {
duplicates.push(i[1]);
}
t.push(i);
return t;
}, []);
console.log(output);