04-08-2011 03:45 AM
Hello !
I need your help!
My LabWindows/CVI version is 8.0.
I have just completed a procedure that read and write datas.
LabWindows/CVI has RS-232 library ,but it has no Modbus library.
As our products are all using Modbus communication, our chief engineer requires me to use Modbus communication
protocal. But,I have no idea about Modbus communication protocal.
So,I am looking your help!
If you ever did such project ,would you please help me and give me some directions or share some examples?
Looking forward to your reply.
Thank you very much!
xiepei
04-08-2011 04:04 AM
04-09-2011 02:39 AM
Hi !
Thank you for your reply.
I'm sorry to say that I don't get any useful documentation on the protocol in that site.
I regret to say that I don't know how to use Modbus programming.
For example,I don't know to calculate the number of registers and the address of registers.
There is code of CRC in Modbus protocal,but I don't know how to use CRC in my programming.
I have known how to use device address and function code. The function code I need is 0x03.
But I don't know how to use the others.
My original procedure didn't use Modbus protocal and it connects via RS232.
Now I want to use Modbus protocal in my program.
I need you give me some advice on programming.
Your advice is highly appreciated. Thanks !
xiepei
04-11-2011 06:06 AM
Hi xiepei,
I have downloaded on the Developer's Community site some code that can help you in handling Modbus over RS232: you can find it here. I hope it can help you in developing your application.
Nevertheless, it cannot help you in detecting correct addresses to use and decoding messages: all this material should be explained in the documentation for the device you are using.
04-12-2011 04:01 AM
Hi !
Thank you very much for your reply.
I've seen your code.Unfortunately,The format of the file is newer than my version of CVI.My CVI version is 8.0.
However,I will look at your programs seriously. Thank you again for your help.
I have set a fixed address in my procedure. Reading datas is through the change registers value.
It could communicate via RS232 using modbus,but a new problem comes out.
Sometimes communications would interrupt.This affects the stability of the communication.
Maybe the problem is cleared serial port.
I put the following sentences in my send function and do not clear the serial port in my receiver function.
FlushInQ (comport);
FlushOutQ (comport);
What do you think it will affect the stability of the communication ?
Regards.
xiepei
04-12-2011 04:18 AM
xiepei,
I have added a new software release of the modbus module that you may want to download and test (I have no 8.0 installation on my machine, only 7.1 and 8.5 so I thought 7.1 was the best option for you).
Problems in serial communication may arise if you do not let enough time for the slave to respond: in this case, unless you specifically handle this situation, you may find that no communications is possible. As you can see in my project I have a parameter to set for delay between message sending and answer check: try experimenting with different delays until you find a stable condition.
04-13-2011 04:01 AM
Hi !
Thank you very much for your reply.
I'm sorry to say that I could not understand your program since I have learned deficiency.
For example,
"Initialize tables for CRC calculation" "Computes the CRC and append to the buffer with the data to be transmitted"
"CRC check and match with the CRC found on the received data buffer" I could not understand the contents of these.
Lost a file when I open Modbus_CVI71.zip. I have added the file ModbusFramework.c to Modbus_CVI71.zip..It stills shows a missing file.
I'm sorry to bring you so much trouble. Hope you taking the time to help me.
Regards.
xiepei
04-13-2011 04:17 AM
Which file are you missing? Out of the files listed I am using only standard CVI files. You may be missing the toolbox ( <cvidir>\toolslib\toolbox\toolbox.fp ) which I have added in the library list as I very often use functions in it. You may want to load in the Instrument list: go to Instrument >> Load menu and browse to the folder I mentioned, selecting the appropriate .fp file.
With regard to the functions you listed, they are functions needed to calculate the Cyclic Redundacy Check (CRC) that is required by Modbus protocol; as you can see in the linked page, several CRC algorythms have been used: Modbus uses CRC-16. Calculation of the CRC is made by means of appropriate tables; this part of the code is mainly taken from documentation on Modbus.
The procedure is as follows: you must prepare the tables before calculating the CRC on some message; after tables are ready, you must prepare the message and then append the CRC calculated on it; all this is transmitted to the slave device which recalculates the CRC and compares it with the one received from the PC: if they don't match a transmission problem can be arised and the message is normally discarded. The same procedure must be performed by PC program on the responses from the slave.
04-14-2011 04:00 AM
Thank you very much for your help.
The file I am missing is ModbusFramework.c. I have added the head file #include "toolbox.h" in the main procedure.
I regret to say that the software CVI is I downloaded from the internet.So I could not find the file toolbox.fp.
( <cvidir>\toolslib\toolbox\toolbox.fp )
I really appreciate your help and support. I will see your program earnestly.
Best wishes !
xiepei
04-14-2011 04:20 AM
What you say about the Programmer's Toolbox is very strange: every CVI installation should have it loaded in CVI directory.
In any case, I am using Toolbox function only in two cases:
- CallCtrlCallback function, which can be substituted by directly calling the control callback ChoosePort
- Min macro, which can be easily rewritten as it simply returns the minimum of the values passed to it