Esempio n. 1
0
 def _sendPeriodic(self, canId, canData, period):
     print("Started Periodic Can Message - Every" + str(period) + "sec")
     msg = can.Message(arbitration_id=canId, is_extended_id=False, data=canData)
     try:
         can.send_periodic(self.bus, msg, period)
     except can.CanError:
         print("Message NOT sent")
Esempio n. 2
0
 def send_message_periodic(self):
     msg = can.Message(arbitration_id=0x222,
                       is_extended_id=False,
                       data=[0x11, 0x22, 0x33])
     try:
         can.send_periodic(self.bus, msg, 2)
         return True
     except can.CanError:
         print("message not sent!")
         return False
Esempio n. 3
0
 def _sendPeriodic(self, canId, canData, period):
     # send message
     #msg = can.Message(arbitration_id=0x123, is_extended_id=False,data=[0x11, 0x22, 0x33])
     msg = can.Message(arbitration_id=canId,
                       is_extended_id=False,
                       data=canData)
     try:
         # Send Periodic Message
         can.send_periodic(self.bus, msg, period)
         print(msg)
     except can.CanError:
         print("Message NOT sent")
Esempio n. 4
0
def main():
    global device_id
    global encoder_value_send_task
    if len(sys.argv) != 2:
        usage()
        sys.exit(1)

    device_id = int(sys.argv[1])
    if device_id < 0 or device_id >= 63:
        usage()
        sys.exit(1)

    can.rc['interface'] = 'socketcan_ctypes'
    can.rc['channel'] = 'vcan0'

    bus = Bus()
    notifier = can.Notifier(bus, [Listener()])
    status_3_msg = can.Message(arbitration_id=(talon_srx.STATUS_3 | device_id),
                               extended_id=True,
                               data=make_status_3_msg())
    status_3_task = can.send_periodic(can.rc['channel'], status_3_msg, 0.1)
    while True:
        status_3_msg.data = make_status_3_msg()
        status_3_task.modify_data(status_3_msg)
        time.sleep(0.05)
    notifier.stop()
Esempio n. 5
0
def test_simple_periodic_send():
    print("Starting to send a message every 200ms. Initial data is zeros")
    msg = can.Message(arbitration_id=0x0cf02200, data=[0, 0, 0, 0, 0, 0])
    task = can.send_periodic('vcan0', msg, 0.20)
    time.sleep(2)
    task.stop()
    print("stopped cyclic send")
Esempio n. 6
0
    def send_periodic_msg(self, bus):
        print("Starting to send a message every 200ms. Initial data is zeros")
        # msg = can.Message(arbitration_id=0x0cf02200, data=[11, 22, 33, 44, 55, 66])
        msg = can.Message(arbitration_id=0x1245, data=[11, 22, 33, 44, 55, 66])

        self.task = can.send_periodic(bus, msg, 0.20)
        time.sleep(2)

        self.task.stop()
        print("stopped cyclic send")
Esempio n. 7
0
 def AddPeriodicMessage(self, ibsid, contents, period):
     # For socketcan_native, bit 32 (MSb) needs to be set for extended ID
     # Is fixed in latest python-can though!
     log.debug(
         'Adding periodic message ID : 0x{mesgid:08X} period {T}'.format(
             mesgid=ibsid.GetCANID(), T=period))
     msg = can.Message(arbitration_id=(ibsid.GetCANID() | (1 << 31)),
                       data=contents,
                       extended_id=True)
     self.periodic_tasks.append(
         can.send_periodic(can.rc['channel'], msg, period))
Esempio n. 8
0
def test_simple_periodic_send():
    print("Trying to send a message...")
    msg = Message(arbitration_id=0x0cf02200, data=[0, 1, 3, 1, 4, 1])
    task = can.send_periodic('vcan0', msg, 0.020)
    time.sleep(2)

    print("Trying to change data")
    msg.data[0] = 99
    task.modify_data(msg)
    time.sleep(2)

    task.stop()
    print("stopped cyclic send")

    time.sleep(1)
    task.start()
    print("starting again")
    time.sleep(1)
    print("done")
Esempio n. 9
0
def test_simple_periodic_send():
    print("Trying to send a message...")
    msg = Message(arbitration_id=0x0cf02200, data=[0, 1, 3, 1, 4, 1])
    task = can.send_periodic('vcan0', msg, 0.020)
    time.sleep(2)

    print("Trying to change data")
    msg.data[0] = 99
    task.modify_data(msg)
    time.sleep(2)

    task.stop()
    print("stopped cyclic send")

    time.sleep(1)
    task.start()
    print("starting again")
    time.sleep(1)
    print("done")
Esempio n. 10
0
def test_periodic_send_with_modifying_data():
    print("Starting to send a message every 200ms. Initial data is ones")
    msg = can.Message(arbitration_id=0x0cf02200, data=[1, 1, 1, 1])
    task = can.send_periodic('vcan0', msg, 0.20)
    time.sleep(2)
    print("Changing data of running task to begin with 99")
    msg.data[0] = 0x99
    task.modify_data(msg)
    time.sleep(2)

    task.stop()
    print("stopped cyclic send")
    print("Changing data of stopped task to single ff byte")
    msg.data = bytearray([0xff])
    task.modify_data(msg)
    time.sleep(1)
    print("starting again")
    task.start()
    time.sleep(1)
    task.stop()
    print("done")
Esempio n. 11
0
    def send_periodic(self,
                      data,
                      arbitration_id,
                      extended_id,
                      period,
                      duration=None):
        '''
        :param float period:
            Period in seconds between each message
        :param float duration:
            The duration to keep sending this message at given rate. If
            no duration is provided, the task will continue indefinitely.

        :return: A started task instance
        :rtype: can.CyclicSendTaskABC
        '''
        message = can.Message(arbitration_id=arbitration_id,
                              data=data,
                              extended_id=extended_id)
        task = can.send_periodic(message, period, duration)
        assert isinstance(task, can.CyclicSendTaskABC)
        return task
Esempio n. 12
0
import can
import mppts

can_interface = 'slcan0'
bus = can.interface.Bus(can_interface, bustype='socketcan')
mppt_full = can.Message(arbitration_id=0x711,
                        data=[255, 255, 255, 255, 255, 255, 255, 255])
mppt_send = can.Message(arbitration_id=0x712)
can.send_periodic('slcan0', mppt_send, 0.10)
test = mppts.Drivetek(1810)
#while True:
#   msg = bus.recv()
#   test.parse_can_msg(msg.arbitration_id, msg.data)
Esempio n. 13
0
# many other interfaces are supported as well (see below)
bus = can.Bus(interface='socketcan',
              channel='vcan0',
              receive_own_messages=True)

db = cantools.database.load_file('Sample.dbc')
example_message = db.get_message_by_name('ExampleMessage')
test_message = db.get_message_by_name('Message1')

data = example_message.encode({'Temperature': 250.1, 'AverageRadius': (3.2), 'Enable': 1})
msg = can.Message(arbitration_id=example_message.frame_id, data=data)

# send message
#msg = can.Message(arbitration_id=0x123, is_extended_id=False,data=[0x11, 0x22, 0x33])
try:
    can.send_periodic(bus, msg, 1)    # Send Periodic Message
    #bus.send(msg)                    # Send Single Message
    print(msg)
except can.CanError:
    print("Message NOT sent")

# iterate over received messages
for msg in bus:
    if(msg.arbitration_id == 0x444):
        data = test_message.encode({'Signal1': 1})
        rsp_msg = can.Message(arbitration_id=test_message.frame_id, data=data)
        bus.send(rsp_msg)
    #print(msg)
    try:
        print(db.decode_message(msg.arbitration_id, msg.data))
    except: