How To Temporarily Disable A Device?


Recommended Posts

Hi,

 

How can I temporarily disable and re-enable a device from within a sequence.

 

I have a ModBus TCP device for my I/O connections to the outside world. All my I/O uses channels connected to this device.

For various reasons, this device is not always connected. When not connected I continuously get "P-ModbusTCP 0010: Timeout" and "P-ModbusTCP 0013: Port locked" alerts and need a way to stop these alerts.

 

I've tried setting the address and port to "" and 0 respectively and then doing and InitComm:-

    device.ModBus1.address = ""

    device.ModBus1.port = 0

    device.ModBus1.InitComm()

 

but that doesn't work.

I've thought about deleting the device and later recreating it, but I've read elsewhere (on this forum) that a device created in a sequence can not have channels associated with it.

 

Please tell me there is a simple way switch a device off and back on.

 

Rod.

Link to comment
Share on other sites

There are two ways to do it.  Both require you to put all the input channels for that device in their own channel group.  Then you can either:

 

1) use channel.listall() to get all the channels in the group, cycle through them, setting Timing to 0, then do channel.restart()

 

2) set the timing to 0 directly, then instead of using Timing at all, use a sequence to trigger the reads by using channel.readgroup().  Then just stop the sequence to stop the reads.  ReadGroup() by the way will still optimize modbus reads, so is preferable to a bunch of read()'s

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.