logo

请问pyb中can.send函数怎么发送8个字节?发送了一个列表提示错误。

2019-09-20 17:31
4
z1sk
# Untitled - By: Administrator - 周五 九月 20 2019
import time
from pyb import Pin, Timer
from pyb import CAN
can2 = CAN(2,CAN.NORMAL,extframe=False,prescaler=9,sjw=1,bs1=8,bs2=3)
can2.setfilter(0,CAN.LIST16,0,(0,1,123,124))
ID=0x111
MSG=123
Data=[1,2,3,4,5,6,7,8]

def tick(timer):            # we will receive the timer object when being called
    print("Timer callback")

tim = Timer(4, freq=1)      # create a timer object using timer 4 - trigger at 1Hz
tim.callback(tick)          # set the callback to our tick function

while(True):
    time.sleep(1000)
    print("wait")

    can2.send(MSG,ID,timeout=3000)
    can2.send(Data,ID,timeout=3000)
2019-09-21 12:07
I
网红小智智 星瞳科技

https://forum.singtown.com/topic/2133/%E5%A6%82%E4%BD%95%E5%B0%86%E8%89%B2%E5%9D%97%E7%9A%84%E4%B8%AD%E5%BF%83%E5%9D%90%E6%A0%87%E5%81%9A%E6%88%90%E4%BA%8C%E8%BF%9B%E5%88%B6%E5%8C%85%E5%8F%91%E9%80%81%E5%88%B0%E4%B8%B2%E5%8F%A3%E4%B8%8A/2

2019-09-23 08:41
4
z1sk

非常感谢!能通过,但是我想知道原因,为什么需要用bytes()来将数组转换才能传入数组?

2019-09-23 11:32
I
网红小智智 星瞳科技

@z1sk 数组不是字节。你要考虑大小端的问题。