简体   繁体   English

Python-可以总线,仅获取字节吗?

[英]Python-Can Bus, grab only the bytes?

Require some help with Python-can. 需要使用Python-can的帮助。 At the moment, my code is just receiving data with a 2 second delay so the shell doesn't flood itself. 目前,我的代码仅接收2秒钟的延迟数据,因此shell不会自行溢出。

How do i filter the information, just so I can use the bytes received to interpret the information? 我如何过滤信息,以便可以使用接收到的字节来解释信息? At the moment its giving me everything. 此刻它给了我一切。

import can
import time

bus = can.interface.Bus(bustype='nican', channel='CAN0', bitrate=1000000)

recvMsg = bus.recv(timeout=None)
while(recvMsg is not None):
    print (recvMsg.)
    time.sleep(2)
else:
    print ("None")

Please have a look at the message type of python-can . 请查看python-canmessage类型

Examples: 例子:

If you want to print the number of bytes in the data field, use 如果要打印数据字段中的字节数,请使用

print(recvMsg.dlc)

If you want to print the first data byte, use 如果要打印第一个数据字节,请使用

print(recvMsg.data[0])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM