Home > Software engineering >  Modbus RTU protocol to read and write
Modbus RTU protocol to read and write

Time:09-30

Detailed problem description and the source code to see this post
http://bbs.csdn.net/topics/390977511? Page=1 # post - 398941257

Do with VB6 development and instrument communication, now reading parameter instrument display number less than 65535 can be read normal, as Long as more than 65535 the number of the instrument, communication back to the frame of data is 8000 h, converted to a decimal is 32768, write less than the number of 32767 when writing parameters can modify the data on the instrument properly, but writing is more than 32767 the number of the instrument is returned an error response code 03, can't change, also asked a lot of places, many say a type's definition, may have a problem what Integer to Long, it may not seem like this problem, can't see themselves under communication manuals, there was a place where translation feeling and I'm a little problem, the problem on the manual says a parameter is 16, so seems to be said more than 16 under how to read and write, but their translation is not very understand what to do, now sent to you to see whether help my problem under analysis and manual said this chapter, specific how should handle? Thank you very much!

7. CHAPTER 7 Modbus and EI Bisynch
The ADVANCED switchable viewer
7.1. The ACCESS TO the FULL RESOLUTION FLOATING POINT AND
TIMING DATA (MODBUS ONLY)

One of the main limitations of the Modbus is that only 16 bit integer representations of the data can
Normally be transferred. In most cases, this does not cause a problem, since appropriate
Scaling can be applied to the values without losing precision. Indeed all values displayable on
The 4 digit Series 2000 front panel may be transferred in this way. The clear this from the
Significant drawback that the scaling factor to be applied needs to be known at both ends of the
The communications link.

One further problem is that certain 'time' parameters, notably those 2 for the programmer
The function are always returned over the communications link in seconds. It is possible for long
16 bit durations to overflow the Modbus limit.
To overcome these problems, a sub protocol has had been defined, using the upper portion of the
The Modbus address space (8000 h and upwards), allowing full 32 bit resolution floating point
And The timer parameters. The upper area is known as The IEEE region.
This sub - protocol provides two consecutive Modbus addresses for all The parameters. The base
Address for any given parameter in the IEEE region can easily be calculated by taking its
Normal Modbus address, doubling it, and adding 8000 h. For example, the address in the
The IEEE region of the Target Setpoint (Modbus address 2) is simple
2 x 2 + 8000 h=8004 h=32772 decimal
This calculation applies to any parameter that has a Modbus address.
Access to the IEEE area is made via block reads (Functions provides 3 & amp; 4) and writes (16 Function
Attempts to use the "Write a Word" (6) the Function operation will be rejected with the an error
The response. Furthermore, the block reads and writes using the IEEE region should only be
Performed at even addresses, day no damage to the instrument will result in attempting
Access the at odd addresses. In general, the number of words' field, In the Modbus frame,
Should be set to 2 times what it he have had for the 'normal' Modbus.
The rules governing how The data in The two consecutive Modbus addresses are organised
Depending on the 'data type of the parameter.

CodePudding user response:

The passage says that general equipment he USES 16 bits of data to expressed, which is from 0 to 65535, then such as divided by 10 to figure out numerical
If need higher precision of data, from the Modbus address area of more than 8000 h to read, that USES the 32-bit floating-point
That you like in the original post
Need to send 02 03 81 42 00 02 XX XX (XX XX is check code, I'm too lazy to calculate]

CodePudding user response:

Oh, say write back to use function code 16, if written in 06 will return an error

CodePudding user response:

reference 1st floor bakw response:
the passage says that general equipment he by 16 bits of data, which is from 0 to 65535, then such as divided by 10 to figure out numerical
If need higher precision of data, from the Modbus address area of more than 8000 h to read, that USES the 32-bit floating-point
That you like in the original post
Need to send 02 03 81 42 00 02 XX XX XX XX is check code, I don't calculate]


Well I see post asked general meaning in combination with other each other, others say read two words

Send 02 03 81 42 00 02 10 4 c
Receive 02, 03 04 00 00 00 01 the euro F3

I try to read, according to my current code to read out the result is 0, the software is I pick up the return frame in front of 0000 to turn the decimal display
Is the conversion way also has a problem? If such receive scaling back of 00 00 00 01 how do?
In fact my hand instrument now want to read the parameter value is 8453.4
(I think it should be read correctly (decimal) this number, 84534 software inside to do except 10 shows results)

I now is to see this in the manual is not very understanding, you calculate how much is 8142?
Like I also post the example, I will read the parameters of address is 00 a1 (hexadecimal), the decimal is 161
And manual says a normal Modbus address should refer to the parameter's address, is that taking the 00 a1 or 161 to participate in computing?
Manual example: 2 + 2 x 8000 h=8004 h=32772 decimal
That to me this parameter
161 x2 + 8000 h=8322 h
00 a1x2 + 8000 h=?? So how to calculate?

CodePudding user response:

00 a1h=161
00 a1h * 2=161 * 2=322
322=142 h
161 and 322 are decimal number
8000 h 00 a1h are hexadecimal number (note that they finally had a letter h)
8000 h + 142 h=8142 h

00 00 00 01 I don't understand, the results of IEEE floating point number word conversion result is 1.401298 e-45
If it is 8453.4 into a floating point number should be 159 a4604 or 4604159 a

CodePudding user response:

refer to the second floor bakw response:
oh, behind that write to use function code 16, if written in 06 will return an error


Now read the actual value of parameters of the instrument is 8453.4
I try to read the address 8332 read two words

Send 02 03 83 32 00 02 4 c 73
Receive 02, 03 04 80 00 FF FF A8 D7

First hypothesis says 8332 this address is right
The incoming value should be 80 00 FF FF
How do you handle this data? Calculate a value or two values?
FFFF decimal is 65535, 80, 00 is 32768
Had no idea!!

CodePudding user response:

8332 certainly wrong, the problem he returned not like IEEE floating point number

CodePudding user response:

reference 5 floor chj510 reply:
Quote: refer to the second floor bakw response:

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related