ni.com checkout is currently experiencing issues.

Support teams are actively working on the resolution.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Modbus RTU programming

Hi,

Want to design an application to communicate with Microsystems' SCADAPack PLC device, which supports Modbus RTU protocol. Due to be the new to the protocol, so hope can get a code phase or a sample written with CVI. Your advis is highly appreciated .
0 Kudos
Message 1 of 10
(12,012 Views)
How is your PLC connected to the computer (serial, ethernet, ...) ? And how do you want to communicate with it (OPC, ActiveX, direct integration in the code, ...) ? Depending on those choices the solution can be different.
In any case, here some documentation on the protocol in Modicon site. Additionally, consider that modbus constitutes a framework the surrounds your informations: the content of the communication with your device is not part of Modbus protocol and is to be documented by actual device producer.
 
In case you want to connect via RS232 I can give you some hint based on my experience.


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 10
(11,981 Views)
Hi Roberto,

The PLC will connect with PC directly, in my application, there will not  use any other ways to embedded the protocol, just need to use RS-232 to communicate with it. The PLC provider just states that the communication  protocol complys with Modbus RTU. I will use the PLC to turn on or off a light. I have read a protocol doc. from www. Modbus.org, it said that modbus can read out a coil's status, and also can read out the register's value, I'm confused because I do not know the distinguish between coil and the register. Please give a hint, your advise is highly appreciated. Thanks.


David
0 Kudos
Message 3 of 10
(11,952 Views)

Hi David, basically modbus permits you to read and write into the PLC memory: it's up to the program resident inside the PLC to determine the content of the memory to read and what to do with the memory written to by the computer.

In order to establish a serial communication with the PLC your program must:

1. Open the serial port with proper parameters the plc can use to communicate
2. Prepare the memory arrays to calculate the CRC
3. Prepare a message with the correct PLC address, function number (0x03: read if I'm not in remembering), addressof memory to read and width of memory read, CRC
4. Send to the PLC which should receive, check the message and respond with an appropriate ACK message
5. Wait for the response and check it (calculate the CRC on the answer and check with the CRC received by the PLC)
6. If it's ok, read the response

What I exactly don't know is which part of the protocol is automatically performed by the PLC and which one is to be written by you inside that device. Shortly I will attach some source code I developed to communicate.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 10
(11,944 Views)
Hi Roberto,

The PLC is Control Microsystems' SCADAPack 100 module(http://www.controlmicrosystems.com/support/support_manuals.html), I just have a hadware manual referrence, it said the product comply with the standard Modbus RTU protocol. I do not know if using the standard protocol message could connect the device? Are there any other conditions need to be taken on?  Hope can get a code phase example. Thanks.



David
0 Kudos
Message 5 of 10
(11,935 Views)

Hi David,

I have implemented both Modbus and Modbus over ethernet natively in CVI using Ansi C Code.

The  Modbus serial implementation is straightforward and I basically used the sample code from the Modicon Modbus manuals. If you need the manuals and /or my code mail me directly.(ni_cviforum@jattie.co.uk)

Best regards

Jattie van der Linde

Jattie van der Linde
Engineering Manager, Software & Automation
TEL Magnetic Solutions Ltd
0 Kudos
Message 6 of 10
(11,920 Views)

Dear Lee,

I have done only project where I read a temperature from a Brain Child Temperature indicator. The following is the coding. It is proved and working for more than one year.

double ReadTemperature(void)
{
//int i,val,send_array[8]={0x01,0x03,0x00,0x41,0x00,0x01,0xD4,0x1E},read_array[7]={0,0,0,0,0,0,0};
  int i,val,send_array[8]={0x01,0x03,0x00,0x40,0x00,0x01,0x85,0xDE},read_array[7]={0,0,0,0,0,0,0};
double temperature=0.0;
for (i=0; i<=7; i++)
ComWrtByte (TCport, send_array[i]);
for (i=0; i<=6; i++)
read_array[i] = ComRdByte (TCport);
read_array[3]=read_array[3]<<8;
val=read_array[3]+read_array[4] ;
temperature=(val-19999)/10;
return (temperature);   
}

Regards,

Kumar.E

Using CVI since 1998.

 

0 Kudos
Message 7 of 10
(11,855 Views)
Hi, I am new to this forum and I need help

 I want to establish a connection between PC and PLC via Ethernet.The program which will be written in C must be able to send and receive the data to and from the PLC.At present I have no idea how the PLC is , its just a black box for me and is of siemens.This PLC is already programmed .How should my program communicate with this PLC.Should I use sockets or Modbus any idea about the protocol.

Thanks
 Vishal
0 Kudos
Message 8 of 10
(11,315 Views)

ni_cviforum@jattie.co.uk email to this id fails.........I need some sample code for Modbus RTU and also the manuals. Please send me at hafeezullah_88@yahoo.com

 

Thanks

If you are young work to Learn, not to earn.
0 Kudos
Message 9 of 10
(7,591 Views)

Did you see this nice contribution?

0 Kudos
Message 10 of 10
(7,585 Views)