MODBUS communication

G

Thread Starter

garincha

Hi,

I'm a beginner in MODBUS, so please help me.
I have a temperature regulator with MODBUS communication.

For example:

If I want to read holding register, e.g.: 0042 "Value of temperature" from mentioned device, in my application for MODBUS communication which was written in
Microsoft Visual Studio 2005- VC#,
I made the request -byte array: {0x01, 0x03, 0x00, 0x29, 0x00, 0x01, 0x83, 0x01}
1 2 3 4 5 6 7 8

1.- slave adress (configured in device)
2.- function code(Read Holding Registers)
3.- start adress Hi
4.- start adress Lo
5.- no. of registers Hi
6.- no of registers Lo
7.- error code
8.- exception code

and sent that array to device. Label Rx blinks on the front panel of device, so device received my request, but I don't get any response, Tx doesn't blink!!!

All other parameters like port name, baud rate, parity, data bits, stop bits, ReadTimeout, WriteTimeout and RS485/RS232 converter are O.K.

Plese, could you help me with some advice to get response from device and tell me what I do wrong?
Is my request -byte array O.K.??? (especially the last two bytes 0x83, 0x01- CRC)

Thank you very much.

Best regards!
 
S
Your CRC is incorrect. The CRC for the message should be 55 C2.

01 03 00 29 00 01 55 C2

Below is the C code to calculate CRC for a message.

/*
***************************************************************************
Function Name: crc
Purpose: To calculate the 16 bit CRC remainder
Parameters: count, buffer addr.
Returns: remainder
****************************************************************************
*/
WORD crc(WORD no_bytes,BYTE *buff_addr)
{

WORD bias,inner;
WORD crc_rem=0xffff,mod;

for (bias=0;bias<no_bytes;bias++)
{
crc_rem^=buff_addr[bias];
for (inner=0;inner<8;inner++)
{
mod=crc_rem&0x0001;
crc_rem>>=1;
if (mod)
crc_rem^=0xa001;
}
}
return crc_rem;
}

Syd Deitch
Calta Computer Systems
Calta Computer Systems Limited
Suite 202, 7003 - 5th Street S.E.
Calgary, Alberta, Canada T2H 2G2
Phone - 403-252-5094
Fax - 403-252-5102
email - [email protected]
Web - http://www.calta.com
 
F

Fred Loveless

Hi, the last 2 bytes of the packet are the CRC check sum of the request. You do not send and error Code and exception code to the device. If there is an error when you make the request the device will responed with

1 - Slave Device ID
2 - Funtion code (0x03) + (0x80)
3 - The Exception Code
4 and 5 - CRC check sum

Go to Modbus.org and get the offical modbus prodcol manual.

Fred Loveless
Senior Application Engineer
Kepware Technologies
 
Your parts 7 & 8 do not belong in your query message:
7.- error code
8.- exception code

Exception codes relate to responses from a slave to non-communication errors. Modbus slaves do not respond to communication errors.

Bytes for 7 & 8 should be, but are not, CRC values.

Your message is
01 03 00 29 00 01 83 01 or
010300290001 with out bytes 7 & 8

The first part of the query, 01 03 00 29 00 01 (h) interprets as

Read the value (command 03) at the single (0001) register address 40029 from the slave at address 01.

Is this what you intended?

The on-line CRC calculator at
http://www.lammertbies.nl/comm/info/crc-calculation.html?crc=010300290001&method=hex
produces a CRC value for 010600010100 of 0xC255

If the CRC is incorrect, a Modbus slave will not respond and the master will time out, which is what you are seeing.

MODBUS over Serial Line Specification and Implementation Guide V1.02, page 15
"When the CRC is appended to the message, the low-order byte is appended first, followed by the high-order byte. A detailed example of CRC generation is contained in Appendix B."

So try the query 01060001010055C2

The on-line CRC site has lots of information on calculating the CRC, as well as the serial standard cited above from this site's sister Modbus site.

David
 
J

Jaka Dolenec

Hi!

Your CRC code is wrong the proper modbus call should be:
0x03, 0x00, 0x29, 0x00, 0x01, 0x04, 0x193


Chek if your algoritem for getting CRC code is working right.

best regards
 
The last 2 crc bytes should be 55 C2
anr they shouldn't be labeled error code and exception code.

Exception codes are in a failed response from a slave, not a request from a master.
 
M

Michael Griffin

First, I think that bytes 7 and 8 in your message were meant to be the CRC, not the error code and exception code.

Secondly, I put your message into 2 different CRC calculators, and both give me 0xc255. You might want to check your calculation. There is sample C code in the appendix of the Modbus standard for calculating this.

Finally, make sure you are sending the bytes and bits in the correct order. Intel processors are backwards from most others, and are backwards from how network standards work.
 
J

Jairo J. Rodriguez

Hi there, first all you must be sure to the CRC is ok so a sugest to you to use a MODBUS simulator in order to verify the datagram CRC, if you have problem programing the CRC rutine I can send to you the second degree ecuation to solve it. In other hands if you CRC is OK somes modbus device use the modbuss address minus one so if you need the modbus register 40042 yor data request must be to the 40041 address.

regards,
Jairo J. Rodriguez U.
 
Good morning,
I've written a Microsoft Visual Basic 6.0 program to send Modbus RTU and when I put your values into it, the program returns a CRC of decimal 20 and decimal 12. I have never used VC# so I will not be able to help you debug the code. Good luck
 
Your parts 7 & 8 do not belong in your query message:
7.- error code
8.- exception code

Exception codes relate to responses from a slave to non-communication errors.
Modbus slaves do not respond to communication errors.

Bytes for 7 & 8 should be, but are not, CRC values.

Your message is
01 03 00 29 00 01 83 01 or
010300290001 with out 7 & 8

The first part of the query, 01 03 00 29 00 01 (h) interprets as

Read the value at the single register address 40029 from the slave at address 01.

Is this what you intended?

The on-line CRC calculator at
http://www.lammertbies.nl/comm/info/crc-calculation.html?crc=010300290001&method=hex
produces a CRC value for 010600010100 of 0xC255

If the CRC is incorrect, a Modbus slave will not respond and the master will time out, which is what you are seeing.

MODBUS over Serial Line Specification and Implementation Guide V1.02, page 15
"When the CRC is appended to the message, the low-order byte is appended first, followed by the high-order byte. A detailed example of CRC generation is contained in Appendix B."

So try the query 01060001010055C2

The on-line CRC site has lots of information on calculating the CRC, as well as the serial standard cited above from this site's sister Modbus site.

David
 
The fact that Rx blinks just means the signal is getting there, not that it's correct. I suggest you start off with a really low baud rate e.g. 1200. I have often found when trying to get two devices from different manufacturers to communicate you need to try different variations of parity and stop bits.

Starting with both devices at a low baud rate the signals seem to be more forgiving. Once you get it talking then you can crank up the speed.
Sorry it's a while since I used Modbus so I won't comment on the byte array.

I like to use a laptop running a terminal program to monitor the communications. If it's RS-485 connect the laptops Rx line to the -Ve signal. Often what you are sending isn't what you think you are sending.

Regards
Roy
 
Top