示例#1
0
    def __init__(self, props, can_network: Network, can_node_id: int):
        ### props must contain the following attributes: "type", "name"
        self._name = TAString(self, 0x2512, 0x00,
                              b'\x1F\x00' + props["name"].encode("utf-16le"))
        self.__init_od()

        self._local_node = can_network.create_node(can_node_id, self._od)
        self._sdo_servers = {}

        super().__init__(props, can_network, can_node_id)

        self._sdo_client = SdoClient(0x640 + can_node_id, 0x5C0 + can_node_id,
                                     ObjectDictionary())

        self._sdo_client.network = can_network
        can_network.subscribe(0x5C0 + can_node_id,
                              self._sdo_client.on_response)

        self._sdo_node = None

        self.__analog_timer = threading.Timer(self.__analog_interval,
                                              self.__send_analog)
        self.__digital_timer = threading.Timer(self.__digital_interval,
                                               self.__send_digital)
        self.__analog_timer.start()
        self.__digital_timer.start()
        for i in range(0x400, 0x440):
            self._canNetwork.subscribe(i, self.__cs_mpdo_callback)
        for i in range(0x480, 0x4C0):
            self._canNetwork.subscribe(i, self.__dl_eh_mpdo_callback)

        self._nmt_send()
        self._eh_timer = threading.Timer(10, self._eh_send)
        self._eh_timer.start()
示例#2
0
def import_from_node(node_id, network):
    # Create temporary SDO client
    sdo_client = SdoClient(0x600 + node_id, 0x580 + node_id, None)
    sdo_client.network = network
    # Subscribe to SDO responses
    network.subscribe(0x580 + node_id, sdo_client.on_response)
    # Create file like object for Store EDS variable
    try:
        eds_fp = sdo_client.open(0x1021, 0, "rt")
        od = import_eds(eds_fp, node_id)
    except Exception as e:
        logger.error("No object dictionary could be loaded for node %d: %s",
                     node_id, e)
        od = None
    finally:
        network.unsubscribe(0x580 + node_id)
    return od
示例#3
0
def import_from_node(node_id, network):
    # Create temporary SDO client
    sdo_client = SdoClient(0x600 + node_id, 0x580 + node_id, None)
    sdo_client.network = network
    # Subscribe to SDO responses
    network.subscribe(0x580 + node_id, sdo_client.on_response)
    # Create file like object for Store EDS variable
    try:
        eds_fp = ReadableStream(sdo_client, 0x1021)
        eds_fp = io.BufferedReader(eds_fp)
        eds_fp = io.TextIOWrapper(eds_fp, "ascii")
        od = import_eds(eds_fp, node_id)
    except Exception as e:
        logger.error("No object dictionary could be loaded for node %d: %s",
                     node_id, e)
        od = None
    finally:
        network.unsubscribe(0x580 + node_id)
    return od
示例#4
0
文件: eds.py 项目: triveria/canopen
def import_from_node(node_id, network):
    """ Download the configuration from the remote node
    :param int node_id: Identifier of the node
    :param network: network object
    """
    # Create temporary SDO client
    sdo_client = SdoClient(0x600 + node_id, 0x580 + node_id, objectdictionary.ObjectDictionary())
    sdo_client.network = network
    # Subscribe to SDO responses
    network.subscribe(0x580 + node_id, sdo_client.on_response)
    # Create file like object for Store EDS variable
    try:
        eds_fp = sdo_client.open(0x1021, 0, "rt")
        od = import_eds(eds_fp, node_id)
    except Exception as e:
        logger.error("No object dictionary could be loaded for node %d: %s",
                     node_id, e)
        od = None
    finally:
        network.unsubscribe(0x580 + node_id)
    return od
示例#5
0
    assert resp_cmd == 0x60
    assert Index == index
    assert SubIndex == subindex
    return ErrCode


object_dictionary_table = [
    #index, subindex, value
    (0x3000, 0, bytearray([0x20])),  #Node Id: new node id, like 0x21 = 0x20 +1
    #Note: Result Value = Set Value + 0x01, Here we input the Set Value
    (0x3001, 0, bytearray([0x05])),  #Baud Rate: 500K
    (0x3003, 1, bytearray([0x00])),  #Auto Baud Detection: disable
    (0x6003, 0, bytearray([0xd0, 0x07, 0x00, 0x00])),  #Preset value: 2000
    (0x6200, 0, bytearray([0x32, 0x00])),  #Cyclic Timer: 50ms
    (0x1010, 1, bytearray("save")),  #save
]

if __name__ == "__main__":
    network = canopen.Network()
    network.connect(bustype='socketcan', channel="can1", bitrate=500000)
    node_id = 0x20
    if len(sys.argv) > 1:
        node_id = int(sys.argv[1])
    sc = SdoClient(0x600 + node_id, 0x580 + node_id, None)
    sc.network = network
    sc.RESPONSE_TIMEOUT = 10
    network.subscribe(sc.tx_cobid, sc.on_response)

    for index, subindex, data in object_dictionary_table:
        ErrCode = download_data(sc, index, subindex, data)
        print "%x|%x -> %d" % (index, subindex, ErrCode)