03-09-2015 08:47 AM
Ok So this should be a fairly easy question as i am sure that most of you have done this before. I need to right to a register in a modbus slave device, I know the TCP/IP address and the register address but i am looking for some help on how to write the data into that register. I assume that most of that can be accomplished by the header but i am not sure how to manipulate the header other then reading holding register.
Thanks for the Help,
Mark R.
Solved! Go to Solution.
03-09-2015 11:22 AM
I would pick Write Single Register since you are only working with a single register.
Since you want register 40001, drop the 4. Then subtract 1. You have a zero. Write zero into the Address input. (Registers are numbered starting at 1 in the documentation of devices, but the modbus spec. has them starting at 0.) If that doesn't work. Then try to put a 1 into the Address input.
Wire a 4 constant to the Register input (since you want the 4 mA to start.) If you use the Write Multiple, you need to feed it an array of the data. Which means giving it a 1-D array with 1 element, that is a 4. In later iterations, make that a 4.1, 4.2, 4.3 .....
03-09-2015 11:35 AM
Ok,
So What the API is calling "Register" is the Value I want to put in that register as a U16? and the Address field is what is appears to be. I only need to write a single register so no worries about passing arrays of data.
I Don't have access to the deceive at the moment but thanks for the answer I will mark your solution when i get a chance to try it.
Thanks,
Mark R.
03-09-2015 11:52 AM
@markhrussell wrote:
Ok,
So What the API is calling "Register" is the Value I want to put in that register as a U16?
Yes. And now that you mention it, that description does seem a little confusing. That input is supposed to be th data that goes into the register.. And yes address is the address of the register just like you would think.
You are right that you need a U16 value to put in there. So a 4.1 won't work. You'll have to read the manual for the device to determine how it wants the data coded. It might be a case that you enter a value that is multiple by 10 or a 100. (So a 4.1 would be entered as 41, or possibly 4100). Often single precision floating point values use two registers (thus 4 bytes) and you need to typecast the 4-byte floating point value to a U16 array to pass it in and have it sent to two consecutive registers. Then you have to worry about most significant word vs. least significant word for which register gets which pair of bytes.
and the Address field is what is appears to be. I only need to write a single register so no worries about passing arrays of data.
Yes.
I Don't have access to the device at the moment but thanks for the answer I will mark your solution when i get a chance to try it.
Good luck. If you don't get it correct right away, play around with it. You may even want to just start out with reading registers to begin with since that makes it easier to figure out if the data you are receiving makes sense for the register you expect to be receiving it from.
Thanks,
Mark R.
03-23-2015 02:43 PM - edited 03-23-2015 02:44 PM
Ok so using the setup I have used before and I still timeout. I am attaching the Modbus register Map so That we are all on the same page I want To write To Register 40019.
Thanks,
Mark R.
03-24-2015 06:30 PM
What are you using for the address? It should be one minus the register, so in this case 18. If you look at your register map, the address for 40019 is 12 (hex) which is 18 in decimal.
03-24-2015 07:29 PM
Is the timeout on the read function or on the connect? In theory, a well behaved modbus device should respond to every request even if it just responds with an error code. Its regular enough that this doesn't happen but its worth checking where the timeout has occurred.
I'd also try looking through documentation for your device with respect to the unit ID. In theory 1 should be ok, but...
I'd also try changing the transaction ID to something non-zero. In theory...well you get the idea. Modbus is not the most standard of standards.
03-25-2015 10:41 AM
Thanks to all who answered. The issue was a mistake in the manual for the Device. It says to communicate to the device on port 50. I tried this for several hours trying to figure out why it was timing out at the Open Connection so I changed to the default http port 80 since the deceive could be accessed via a web browser. This changed my time out error to my write function. last I decided that I would try the default tcp/ip port 502 as a last ditch. That seemed to solve my problems any that project is finished and all is communicating well.
thanks,
Mark R.