Change device type


Recommended Posts

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.portName = "mySerialPort"
device.myDevice.port = 3

Next, to change the protocol:

device.myDevice.ProtocolName = "ModbusRTU"


Link to comment
Share on other sites

But, to answer your original question, you can change the device of a channel:

myChannel.strDevice = "Test Device"

When done, do:


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

This same pattern can be used to change any parameter of a channel, Timing being the most common.


Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.