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)