LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use Modbus discrete input polling to trigger events

Solved!
Go to solution

Hello

I have a Modbus RTU slave set up so that I can read a pair of sensors via discrete inputs. I want to know when either goes high and use that output to trigger other modbus events in labview. They are linked so sensor 2 turns sensor 1 off etc, as  illustrated below.

slave.png

 

My problem is how to access the poll output and use it to trigger the next events as it seems to be in an array. The code Iam using  is pictured below just to give people an idea of what I am writing about. Thanks

 

deal with slave 2.png

 

 

 

0 Kudos
Message 1 of 6
(5,272 Views)
Solution
Accepted by topic author EdHarris

Lets see if I have understood you correctly - you want to read the inputs (your two sensors). You already have the Modbus function to perform the read and it returns an array based on a starting address and quantity. Presumably you knowing the starting address and that the two inputs are contiguous; therefore you need to read quantity=2. This gives you an array of booleans (Inputs), which you need to "Index" (hint hint) in order to access each element individually. Check the Array palette and see if that "Index" hint helps.

Message 2 of 6
(5,250 Views)

Done that, thanks.

I now have problems with modbus timing in the scheme below. When the coil is written starting the motor, the PLC stops it via sensor 1 or 2 after an indeterminate time perhaps a 2-3 minutes. This could happen during or after the descrete input read and cause errors. To get round this I have tried to introduce a delay but still get an error at the read node. I wonder if there is something about the modbus session that prevents this working. I have tried putting seperate sessions in a flat sequence structure but this doesnot work either. Any ideas much appreciated.

 write coils and read inputs.png

 

0 Kudos
Message 3 of 6
(5,205 Views)

@EdHarris wrote:
but still get an error at the read node. I wonder if there is something about the modbus session that prevents this working.

 write coils and read inputs.png

 


What error do you get?  Give us an error number or description.

 

Use the block diagram cleanup button to clean up your code, you've got a few control terminals there where the wire is coming out of the wrong side of the terminal.

0 Kudos
Message 4 of 6
(5,193 Views)

On start up the plc works and the sensors work but the other code fails, I get the following error;

Error -1073807339 occurred at VISA Read in MB Master.lvlib:MB_ADU_RTU.lvclass:RX ADU.vi:4960001->MB Master.lvlib:MB_Master_Serial.lvclass:Querry.vi:3550001->MB Master.lvlib:Read Discrete Inputs.vi:3900001->PM basic read discrete inputs.vi.

Possible reason(s):VISA:  (Hex 0xBFFF0015) Timeout expired before operation completed.

 

if try again get;

Error 403481 occurred at MB Master.lvlib:MB_ADU_RTU.lvclass:RX ADU.vi:4960001

Possible reason(s): Modbus slave ID mismatch.

or 403482 CRC/LRC error.

Both parts of the code work alone. 

0 Kudos
Message 5 of 6
(5,186 Views)

Regarding the errors, they disappeared when I powered off the other slave, there may be a problem with the plc firmware.  I think it would be simpler to monitor the motor coil for stop condition - so will work on that.

Thanks for your help.

0 Kudos
Message 6 of 6
(5,167 Views)