Forum Home › Forums › Communicating with Devices › Modbus › Send IEEE Float To device
- This topic has 7 replies, 3 voices, and was last updated 6 years, 9 months ago by roska.
-
AuthorPosts
-
June 28, 2017 at 12:41 pm #2298roskaParticipant
Im able to read all kinds of values from a Controller with Modbus RTU, and I’m also able to set single coils or registers. Everything easy and as usual. But I’m not able to send a IEEE float. (for excample to transmit the setpoint).
In the command section, I select Multiple, to get modbus function 16, and I set element count to 2.
But when I want to send the command, I can only select string or hexadecimal. If I select hexadecimal, and enter the float as hex value (for excample 77.88 = 0x429BC28F), only the first word (429B) is transmetted. The setpoint of the controller is then 77.5, which is 0x429B0000.So how to send a IEEE float?
Thanks,
Robert
June 28, 2017 at 12:42 pm #2299roskaParticipantAnd I would like to enter the decimal number, not hex. 🙂
June 28, 2017 at 12:56 pm #2300manjey73ParticipantOptions for Standard commands to use formulas for IEEE (float)
Add to base formula
public double fRevers (int rev)
{
float q = Convert.ToSingle(CmdVal);
byte[] f = new byte[4];
byte[] o = new byte[4];
f = BitConverter.GetBytes(q);
Array.Copy(f,0,o,0,4);
if (rev == 1)
{
Array.Copy(f, 0, o, 1, 1);
Array.Copy(f, 1, o, 0, 1);
Array.Copy(f, 2, o, 3, 1);
Array.Copy(f, 3, o, 2, 1);
}
Array.Resize(ref o, 8);
Double ou = BitConverter.ToDouble(o,0);
return ou;
}Use the formula in the control channel – fRevers(1) Command type Standard, suitable for some Modbus devices.
Or try to use this formula
LINK{ buf[1], buf[0], 0, 0, 0, 0, 0, 0 }and change the variable type on input
ushort val = (ushort)Cmd;June 28, 2017 at 2:28 pm #2305roskaParticipantThis doesn’t work as well. Now at least I know that if I turn on formula, that I can enter a “Value”, and not only “String” or “Hex”.
But the device receives only garbage. I also tried some other formulas I found in the forum, but as the description is often Russian, I don’t understand the explainations.Receiving floats works without any problems, why is sending that complicated and requires messing around with formulas? 🙂
June 28, 2017 at 8:18 pm #2306manjey73ParticipantThe features of the processors other devices (Little Endian o Big Endian)
Features of the sequence of bytes in the organization of the data transferWell, we don’t all speak the same English 🙂
I use online translation to learn examples in English as well as writing in the English forum.June 29, 2017 at 6:13 am #2308MikhailModeratorroska, I tried to reproduce the problem.
1. I added command into Modbus template: Holding Registers, Multiple, 2 elements
2. Using Communicator GUI I sent a binary command in hex format: 429BC28F
3. Data were sent:
Send (17): 00 00 00 00 00 0B 01 10 00 64 00 02 04 42 9B C2 8FRegisters value are: 0x429B (17051), 0xC28F (49807) according to http://modbus.rapidscada.net/
Do you get another results if repeat the above sequence?
(I use Modbus TCP, it doesn’t matter)June 29, 2017 at 6:15 am #2309MikhailModeratorTo covert a value entered manually into a command value you definitely need a formula. Because command value is a double (8 bytes), but you need to send only a single (4 bytes).
June 29, 2017 at 8:01 am #2310roskaParticipantOk, now I got it. I checked the register values with ModbusPoll software, and noticed there was a combination of 2 problems: first of all, the the adress was shifted by 1, and the word-order wrong. In combination, I didn’t notice the mistake while reading the floats, because the values seemed reasonable. I just noticed, that it was wrong while trying to send floats. With the word order exchanged and shifting the adress, everything works. For receiving, I use the fRevers formula.
Thank you all!
-
AuthorPosts
- You must be logged in to reply to this topic.