MODBUS RTU Master and Slave VB Code

J

Thread Starter

Jerzen

Can any one help me to have a sample vb source code for modbus master and slave as I am working to establish communication between the PC (Master) and the slave hardware on RTU mode. I am getting all the value but i am not able to send or change a new value from the PC to the slave unit though the slave ID and other information is correct.

can any one help me to know where is the mistake?
 
L

Lynn at Alist

Try writing the SAME message via some test tool (http://www.calta.com or http://www.win-tech.com) & see what CRC it sends.

A very common problem for beginners doing a CRC16 in VB is to goof up on the handling of 16-bit overflow. CRC16 needs unsigned 16-bit math, while VB has NO unsigned math. So some CRC16 you calculate will be correct, while others are NOT. It is very possible you can send a few Read requests and the CRC is correct, but the write you are sending happens to obtain an incorrect CRC. This can fool you into thinking your CRC routine is correct when it is not.

So best to confirm with someone else's tool exactly which CRC16 value you should be sending & confirm your routine.

Here is the Modbus CRC16 routine I used back in VB 3.0 days - http://www.iatips.com/crc_vb.txt . It is not pretty or efficient but it works - notice the "AND 65535" operations on 32-bit integers to simulate unsigned 16-bit.

best regards
- LynnL, www.digi.com
 
I wanted to communicate master (PC) to slave (Thermostate) thourgh modbus, Now please provide one example for VB. And communication will be done by Com port.
 
Top