I am trying to use bus.send_periodic to send multiple messages with a period of 100ms. However, when I run the code below I get the error: AttributeError: 'list' object has no attribute 'channel' in line 50: task = bus.send_periodic(messages, 0.1)
This doesn't make sense to me as it is written the same way as the example for the source code.
import logging
import time
import can
import cantools
bus = can.interface.Bus(channel='can0', bustype='socketcan', bitrate='500000')
db = cantools.database.load_file('CAN_v2.2.kcd')
def cyclic_multiple_send(bus):
messages = []
# LLC_Mode_Control = Voltage feedback
messages.append(
can.Message(
arbitration_id=0x30041,
data=[8],
is_extended_id=True,
)
)
# LLC_Voltage_Limits
LLC_Voltage_Limits_data = db.encode_message('LLC_Voltage_Limits_3', {
'Input_voltage_min_3': 0, 'Input_voltage_max_3': 750, 'Output_voltage_min_3': 0, 'Output_voltage_max_3': 750
}
)
messages.append(
can.Message(
arbitration_id=0x30047,
data=LLC_Voltage_Limits_data,
is_extended_id=True,
)
)
#LLC_Current_Limits
LLC_Current_Limits_data = db.encode_message('LLC_Current_Limits_3', {
'Output_current_min_3': 0, 'Output_current_max_3': 75
}
)
messages.append(
can.Message(
arbitration_id=0x30048,
data=LLC_Current_Limits_data,
is_extended_id=True,
)
)
task = bus.send_periodic(messages, 0.1)
assert isinstance(task, can.CyclicSendTaskABC)
time.sleep(100)
if __name__ == "__main__":
cyclic_multiple_send(bus)
Look at line 6 of your example code.
bus = can.interface.Bus(channel='can0', bustype='socketcan', bitrate='500000')
While reviewing your linked example code I would write it like this.
bus = can.Bus(channel='can0', interface='socketcan', bitrate='500000')
Because you haven't provided a out of the box running example I am not able to test this solution. It is just a guess while comparing your code with the python-can example code.
And another advise for using StackOverflow: Please read How to Ask and How to create a Minimal, Reproducible Example carefully. Next time please provide us a smaller and reproducible example. You have to help us so we can help you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.