Hello Guest it is April 17, 2021, 08:19:01 AM

Author Topic: Interface with Industrial PLC (Ethernet or other options)  (Read 486 times)

0 Members and 1 Guest are viewing this topic.

Offline bcoop

*
  •  48 48
    • View Profile
Re: Interface with Industrial PLC (Ethernet or other options)
« Reply #10 on: April 29, 2020, 06:46:57 PM »
Mike,  so if your poll interval for modbus is set for 100ms,  and the denominator for a MB function is set to "4"  then the scan rate for that function would be 100/4 =25ms.

16/32bit data show up as registers, and can be used just like any register accessible from the register plugin. viewable in diagnostics.
Bits don't show up there, but they do show up were you assign your I/O signals - see snapshot


Bob
Bob

Offline smurph

*
  • *
  •  1,380 1,380
  • "That there... that's an RV."
    • View Profile
Re: Interface with Industrial PLC (Ethernet or other options)
« Reply #11 on: May 12, 2020, 01:41:04 AM »
Coils and discrete inputs (outputs and inputs) show up as output and input objects in Mach.  And can be operated on via the mcIo*() API calls. 

I should have called the scan denominator a multiplier or "read every n cycles".  I have to change that!   If your scan time is 100ms, and scan denominator is 4, then the function is performed every 4 cycles (every 400ms) milliseconds.  Is is a way to SLOW the function.

All modbus devices implement things differently.  Sometimes, you may be reading a version or the like that comes from SLOW NVRAM.  If you have to read something like this, it can slow you whole scan!  So if you separate the slow read into its' own function, then you can read it less often via the multiplier (what is now called the denominator).

Also, in the later modubs plugins (4458 and up) you can control the plugin via its command register called mbcntl.  Look for it in the regfile plugin diag window.  You can actually test the commands in that interface.

mcRegSendCommand() will send the command and receive the response and it is a nice robust way to control a plugin that provides such a command register.

Anyway, the commands you write to the register are:
stop
start
restart

By themselves, they will operate on the plugin as a whole. But now you can operate on the device and function levels as well! Do this with the name of the device as seen in the modbus diag window.

start modbus0
stop modbus0
restart modubus0

Next, you can drill down to the function level.

start modbus0/fucntion1
stop modbus0/fucntion1
restart modubus0/function1

:) Total control now. So for your slow NVRAM read, just create another function and stop it when you don't need to read it anymore.

Here is the example in code:
Code: [Select]
hReg, rc = mc.mcRegGetHandle(inst, 'mbcntl/command');
response, rc = mc.mcRegSendCommand(hReg, 'stop modbus0') -- response will be OK or FAIL.
response, rc = mc.mcRegSendCommand(hReg, 'start modbus0')
response, rc = mc.mcRegSendCommand(hReg, 'stop modbus0/function1')
response, rc = mc.mcRegSendCommand(hReg, 'start modbus0/function1')

There is an Initial State that is defined at the function level too.  So you can control what is started at startup time.  In case you need to start a function up late with the command register.

Steve
« Last Edit: May 12, 2020, 01:57:41 AM by smurph »