boliva Posted September 13, 2021 Share Posted September 13, 2021 Is there a way to programatically change the device type of channels? I want to have the option of using Modbus RTU or TCP that is user selectable via an on-screen button but don't want to have completely different channel sets for this change. Quote Link to comment Share on other sites More sharing options...
AzeoTech Posted September 13, 2021 Share Posted September 13, 2021 Actually, the easier way is to use a single device and change which port and protocol it points to. Then you don't have to mess with the channels. You'll need to precreate both a TCP and a serial port, setting the address / port # to 0 for the inactive one. Then to change the port for a device, do: device.myDevice.PortName = "mySerialPort" Don't forget to disable the old port by setting its port # to 0 and calling initcomm() before doing this, and then enabling the new port by giving the correct port # to the new port and calling initcomm() on that. So, something like: device.myDevice.port = 0 device.myDevice.initcomm() device.myDevice.portName = "mySerialPort" device.myDevice.port = 3 device.myDevice.initComm() Next, to change the protocol: device.myDevice.ProtocolName = "ModbusRTU" Quote Link to comment Share on other sites More sharing options...
AzeoTech Posted September 13, 2021 Share Posted September 13, 2021 But, to answer your original question, you can change the device of a channel: myChannel.strDevice = "Test Device" When done, do: channel.restart() which probably isn't needed but is required if you change timing. Still it is a good thing to do. I would use channel.listAll("myGroupName") to get a list of all the channels in a particular group, then cycle through to update the device. Something like: private string clist = channel.ListAll("myGroupName") for (private i = 0, i < numrows(clist), i++) execute(clist + ".strDevice = 'myNewDevice'") endfor channel.restart() This same pattern can be used to change any parameter of a channel, Timing being the most common. Quote Link to comment Share on other sites More sharing options...
boliva Posted September 13, 2021 Author Share Posted September 13, 2021 Thanks! Both replies are exactly what I needed. Appreciate the help. Quote Link to comment Share on other sites More sharing options...
boliva Posted September 13, 2021 Author Share Posted September 13, 2021 One more question...I have created, using the Quick Device Configuration, a Modbus TCP device. In looking at what's tied to that, I see the Address and an AddressType. What is the AddressType refer to (currently set to 2 for Modbus TCP but blank for Modbus RTU)? Quote Link to comment Share on other sites More sharing options...
AzeoTech Posted September 13, 2021 Share Posted September 13, 2021 AddressType is not something you should change. I don't remember why it is in there, probably for a very specific use case. It actually refers to the socket itself, not the protocol. It is ethernet port specific and won't appear if you have a serial port selected, as you probably did for RTU. It has nothing to do with the protocol. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.