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
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
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
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)