用canopen python fram设置RPDO数据

2024-10-16 20:42:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试通过CAN与标准的CANopen设备通信。为此,我使用python canopen框架(版本0.9.0)。 TPDO(从机传输数据)的读取仍然有效。但是如果我尝试写RPDO(从机的接收数据),它就不工作了。(将变量T30写入RPDO 1无效)。你知道吗

我的问题是,我不想任何重新映射或其他东西。我只想写默认对象。你知道吗

我的代码依赖于chrissandberg的示例代码,但我不想要任何特殊的。只有纯IO操作。你知道吗

# Start with creating a network representing one CAN bus
network = canopen.Network()
pCan.Uninitialize(Channel='PCAN_USBBUS1')
#network.check()


# Connect to the CAN bus
# Arguments are passed to python-can's can.interface.Bus() constructor
# (see https://python-can.readthedocs.io/en/stable/bus.html).network.connect()
network.connect(bustype='pcan', channel='PCAN_USBBUS1', bitrate=125000)

# Add some nodes with corresponding Object Dictionaries
node = canopen.RemoteNode (1, 'C:\\Workspace\\project\\hw\\Devices\\eds\\IoX1_16DI_8DO.eds')
network.add_node(node)
node.nmt.state = 'RESET'
time.sleep(1)
node.nmt.state = 'PRE-OPERATIONAL'
# Read a variable using SDO
device_name = node.sdo['Manufacturer Device Name'].raw
print("DEVICE-NAME:",device_name)
vendor_id = node.sdo[0x1018][1].raw
print('VENDOR-ID:',vendor_id)
# Write a variable using SDO

# Read PDO configuration from node
node.tpdo.read()
node.rpdo.read()

# Re-map TPDO[1]
node.tpdo[1].trans_type = 0
node.tpdo[1].enabled = True



T30 = 1
node.rpdo[1].enabled = True
node.rpdo[1].start(0.1)
# Save new PDO configuration to node

# Transmit SYNC every 100 ms
network.sync.start(0.1)

# Change state to operational (NMT start)
node.nmt.state = 'OPERATIONAL'

# Read a value from TPDO[1]
node.tpdo[1].wait_for_reception()
DOHS = int.from_bytes(node.tpdo[1].data, byteorder='big')
print('DOHS_state is:', DOHS)
node.rpdo[1].set_data = T30

Tags: tonodereadnetworkcanstateprintbus