Hello Guest it is April 26, 2024, 02:13:19 PM

Author Topic: Modbus sending same register twice  (Read 968 times)

0 Members and 1 Guest are viewing this topic.

Offline wz2b

*
  •  12 12
    • View Profile
Modbus sending same register twice
« on: November 09, 2021, 01:56:39 PM »
Version 4.0.1.2259

I'm using the NewFangled modbus plugin to try to send X,Y,Z to an external data logger.  As configured there were two modbus devices, so I added a third.  I then set it up to send some registers using write multiple. Basically it's identical to one of the modbus configurations that writes to an on board PLC, but I'm also having it write to my own device.

The registers I'm trying to send are ContAxisPos1, ContAxisPos2, etc.  My modbus device is modbus2; modbus0 and modbus1 are PLCs on the machine.

Near as I can read, my modbus write function is identical to the one that writes to modbus0.  Same function code, same references. Very fast round trip time reported in Modbus Diagnostics (<5 msec).  The other end (my device) is receiving the messages no problem.  However, it's all zeros.

I can't figure out why when I look at modbus0 diagnostics ContAxisPos1 would have a value (say -118) but just below it trying to write the exact same register to device modbus2 that value (and all other values) is sending 0.  I confirmed with wireshark that's really what it's doing.

Is there any problem with trying to send the same register to two different places?

Offline wz2b

*
  •  12 12
    • View Profile
Re: Modbus sending same register twice
« Reply #1 on: November 09, 2021, 02:02:35 PM »
I think I misunderstood what it means to declare a register under modbus2.  I can name that register ContAxisPos2 but that doesn't connect it to that variable in mach. I discovered that if I force that value to "2"on the Mach register diagnostics screen that it does indeed push a 2 to my device.  So I think the problem is I don't know how to connect that Modbus register (on the Mach end) to the actual info I want it to send somewhere in mach. Is this something I have to write as a lua task?
Re: Modbus sending same register twice
« Reply #2 on: November 11, 2021, 10:57:41 PM »
Hi,

Quote
Is this something I have to write as a lua task?

Yes. Mach4's registers is a place where data can be shared between chunks/modules/Mach's core/plugins and external devices.
If you wish to have a piece of data communicated to another device then you must have Mach update the register.

For example:

local registerHandle=mc.mcRegGetHandle(inst,"....path....")
mc.mcRegSetValue(registerHandle,.....desired_value....)

If you wish that Mach quasi continuously update the register then put the code in the PLC script.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Modbus sending same register twice
« Reply #3 on: November 12, 2021, 12:43:29 AM »
i did modbus in other way(you can consider about this option)
i use mode bus to read all servo position (i use absolute encoder all axes)
i did c# application that read all drivers and update register in mach(c# have very easy modebus RTU libary that can read write...)
in mach i just add line that activate that c# app and cheack if that app finish the update
in that way i can do what ever i want in mode bus
maybi its litle more complex but its give me what i most like in mach ,to conrol my system as i want
yaakov

Offline wz2b

*
  •  12 12
    • View Profile
Re: Modbus sending same register twice
« Reply #4 on: November 12, 2021, 10:19:35 AM »
I would love to do that because then I'd skip modbus entirely and send the data the way I really want it to be sent: via MQTT.  I tried to create a C# project though and I think my older version of mach4 might not have the ability?  I went to create a visual studio C# project and I couldn't figure out which of the DLLs I have are something I could attach to.  The docs suggest I should have MachAPI.lib but I don't have that library anywhere on my system.

Re: Modbus sending same register twice
« Reply #5 on: November 14, 2021, 01:47:35 AM »
There is an MQTT library for lua, check out this thread https://www.machsupport.com/forum/index.php?topic=36807.0
Re: Modbus sending same register twice
« Reply #6 on: November 14, 2021, 03:43:14 PM »
NModbus.dll   and NModbus4.dll i see i use this 2
about lua mybi i didn't clear my self
i just call the wpf application nothing with api

os.execute([[C:\\AbsEncoder\\WpfApp4.application]])

this line only ,just run the c#

then c# update mach registry by  api

hope it was help

yaakov
Re: Modbus sending same register twice
« Reply #7 on: January 08, 2022, 02:50:08 AM »
I think I misunderstood what it means to declare a register under modbus2.  I can name that register ContAxisPos2 but that doesn't connect it to that variable in mach. I discovered that if I force that value to "2"on the Mach register diagnostics screen that it does indeed push a 2 to my device.  So I think the problem is I don't know how to connect that Modbus register (on the Mach end) to the actual info I want it to send somewhere in mach. Is this something I have to write as a lua task?

There is a difference between read and write registers in the Modbus plugin. You can only use the LUA api to write the registers that are defined as write registers in the Modbus plugin configuration. If you can get your hands on an cheap Arduino UNO and ethernet shield, I wrote a document on how to use Mach4 TCP Modbus with code examples and detailed instructions for Mach4. It just got buried in the forums https://www.machsupport.com/forum/index.php?topic=44512.0.

If you already have the modbus hardware setup then just use the examples to read and write registers in the document in that link without the arduino.
« Last Edit: January 08, 2022, 02:52:23 AM by compewter_numerical »