Hello Guest it is January 28, 2020, 07:55:32 AM

Author Topic: How to Turn Modbus on or off Using the Registers?  (Read 187 times)

0 Members and 1 Guest are viewing this topic.

How to Turn Modbus on or off Using the Registers?
« on: July 29, 2019, 08:05:07 PM »
Hello,

I see there is a mbcntl register in the register diagnostics window which shows the status and gives a command register for the modbus plugin.

How do I start/stop the modbus plugin like in the diagnostic window where there is a play and stop button? Is there a command I can use? This would be very helpful because for whatever reason, the PLC we are using (Smart 3g from Vital Systems) completely times out after a few hours when connected via modbus. If we can control the on/off function of modbus then we can just "restart" the modbus devices everytime the user homes the machine or presses the enable button.

The pic below shows the code. The code works to send the command and read the status, but the command value must either be wrong or the register doesn't actually do anything. The code is in a regular button clicked script.

Thank you for any help or suggestions.



« Last Edit: July 29, 2019, 08:07:04 PM by compewter_numerical »

Offline Chaoticone

*
  • *
  •  5,634 5,634
  • Precision Chaos
    • View Profile
Re: How to Turn Modbus on or off Using the Registers?
« Reply #1 on: July 30, 2019, 11:53:08 AM »
I think if you are having to do this you have other issues that need to be fixed but.........

You should be able to control it by writing (as a string) to the mbcntl/command register............. STOP, START or RESTART.

The status register will be read only.
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: How to Turn Modbus on or off Using the Registers?
« Reply #2 on: July 30, 2019, 02:06:38 PM »
Yes, we have been told by the PLC manufacturer that there may be a bug in the firmware causing this issue but we are just looking for a quick solution while the company looks to resolve the issue.

Problem is solved! Thanks again for your help!

Offline Chaoticone

*
  • *
  •  5,634 5,634
  • Precision Chaos
    • View Profile
Re: How to Turn Modbus on or off Using the Registers?
« Reply #3 on: July 30, 2019, 03:02:13 PM »
 :)
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: How to Turn Modbus on or off Using the Registers?
« Reply #4 on: July 30, 2019, 10:38:31 PM »
Nice!  Every so often I have to reset the communication on one of our machines because the PLC will timeout for some reason.  This could make a nice little button on the screen to reset it quickly. 
Let us know if you get something working.
Chad Byrd
Re: How to Turn Modbus on or off Using the Registers?
« Reply #5 on: July 31, 2019, 04:27:57 PM »
Nice!  Every so often I have to reset the communication on one of our machines because the PLC will timeout for some reason.  This could make a nice little button on the screen to reset it quickly. 
Let us know if you get something working.

I did get it working per Chaoticone's advice I used the following code in the button 'Clicked Script':

Code: [Select]
local modbusCmdReg = mc.mcRegGetHandle(inst, "mbcntl/command")
local modbusStatusReg = mc.mcRegGetHandle(inst, "mbcntl/status")
local modbusCmdVal = mc.mcRegGetValueString(modbusCmdReg)
local modbusStatusVal = mc.mcRegGetValueString(modbusStatusReg)

mc.mcRegSetValueString(modbusCmdReg, modbusStatusVal == "STOPPED" and "START" or "STOP")