For the CUC I created a script which reads a .txt file containing information about the Modbus configuration and creates this in the active project.
Save the following in a txt file:
Modbus_COM (COM)
Master (ModbusMaster)
ModbusSlave1 (ModbusSlave)
ModbusSlave2 (ModbusSlave)
Then create a .py file with the following code.
print"Current project."proj=projects.primary
\#Searchforalltop-leveldevicesinprojectfordevinproj.get_children():
  ifdev.is_device:
    f=open("C:\_d\Python\ModbusImport\ModbusConfiguratie.txt", "r")
    forlineinf:
      tok=line.split('')
      printtok[1], tok[0]
      if"(COM)"intok[1]:
        dev.add(tok[0], DeviceID(92, "0000 0001", "3.4.0.0"))
        subnodes=dev.get_children()
        master=subnodes[len(subnodes)-1]
      elif"(ModbusMaster)"intok[1]:
        master.add(tok[0], DeviceID(90, "0000 0002", "3.4.3.0"))
        subnodes=master.get_children()
        coupler=subnodes[len(subnodes)-1]
      elif"(ModbusSlave)"intok[1]:
        coupler.add(tok[0], DeviceID(91, "0000 0001", "3.4.0.0"))print"script finished."
Open a project, add your device (PLC) and run the script
Thanks for the example. I have another question about modifying Modbus configuration from Python. Is it possible to fill Modbus Slave configuration. I mean is it possible to add Modbus Slave Channels and fill ModbusGenericSerialSlave I/O Mapping in the Modbus Slave?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
AndreyS hat geschrieben:
Thanks for the example. I have another question about modifying Modbus configuration from Python. Is it possible to fill Modbus Slave configuration. I mean is it possible to add Modbus Slave Channels and fill ModbusGenericSerialSlave I/O Mapping in the Modbus Slave?
Have you checked the device parameters of the ModBus Slave device. You can access them through the property "device_paremeters" of the device object.
BR
Martin
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
For the CUC I created a script which reads a .txt file containing information about the Modbus configuration and creates this in the active project.
Save the following in a txt file:
Modbus_COM (COM)
Master (ModbusMaster)
ModbusSlave1 (ModbusSlave)
ModbusSlave2 (ModbusSlave)
Then create a .py file with the following code.
Open a project, add your device (PLC) and run the script
Related
Talk.ru: 1
Thanks for the example. I have another question about modifying Modbus configuration from Python. Is it possible to fill Modbus Slave configuration. I mean is it possible to add Modbus Slave Channels and fill ModbusGenericSerialSlave I/O Mapping in the Modbus Slave?
Hi AndreyS.
Have you checked the device parameters of the ModBus Slave device. You can access them through the property "device_paremeters" of the device object.
BR
Martin