java - Calculating CRC for int32 data format using the Modbus protocol -


i connecting device using modbus protocol. need obtain 3 values machine. first value of data format int16 , when send example byte array:

static byte[] hz = new byte[] { (byte) 0x01, (byte) 0x03, (byte) 0x00,         (byte) 0x33, (byte) 0x00, (byte) 0x01 }; 

and use crc calculation method obtained a previous question asked on subject.

    // compute modbus rtu crc private static int modrtu_crc(byte[] buf, int len) {   int crc = 0xffff;    (int pos = 0; pos < len; pos++) {     crc ^= (int)buf[pos];          // xor byte least sig. byte of crc      (int = 8; != 0; i--) {    // loop on each bit       if ((crc & 0x0001) != 0) {      // if lsb set         crc >>= 1;                    // shift right , xor 0xa001         crc ^= 0xa001;       }       else                            // else lsb not set         crc >>= 1;                    // shift right     }   }      // note, number has low , high bytes swapped, use accordingly (or swap bytes)     return crc;       } 

i can recieve response. however, other 2 values of int32 data format , not return reply when use method. troubleshoot using program called realterm. fire off commands well. use append modbus 16 crc end of byte stream , send it, works 3 , returns desired reply. case of data format not working specific calculation formula? whats difference between crc16 , modbus16?

modbus16 is crc16. crc calculations have several parameters:

  • the bit width, in case 16
  • the polynomial, in case 0xa001
  • the initial value,in case 0xffff
  • the bit order
  • whether final crc inverted xor.

there quite number of crc16s defined, different values these parameters, , appears 1 of them. see wikipedia article on cyclic redundancy checks more informaton.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -