Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: compewter_numerical on July 29, 2019, 08:05:07 PM

Title: How to Turn Modbus on or off Using the Registers?
Post by: compewter_numerical 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.


(http://compewternumerical.com/ModbusQuestion.PNG)
Title: Re: How to Turn Modbus on or off Using the Registers?
Post by: Chaoticone 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.
Title: Re: How to Turn Modbus on or off Using the Registers?
Post by: compewter_numerical 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!
Title: Re: How to Turn Modbus on or off Using the Registers?
Post by: Chaoticone on July 30, 2019, 03:02:13 PM
 :)
Title: Re: How to Turn Modbus on or off Using the Registers?
Post by: Cbyrdtopper 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.
Title: Re: How to Turn Modbus on or off Using the Registers?
Post by: compewter_numerical 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")