Labview Modbus Serial Example



Labview modbus serial example reference

Does anyone have a labview example code on how to read a slave device holding register using Labview Serial port connection. Labview will be my master and it will read slave device holding register through its serial port. I could not see any example on the labview Help section and I am in need of an example to use as my starting point. MODBUS C library for LabView. Windows XP, NT,2000,Vista,Windows 7, Windows 2008, Windows 10, Linux, FreeBSD. Modbus simulator. MODBUS Slave simulation functions as well Master and Client. Thread safe MODBUS library MODBUS RTU protocol library, MODBUS serial ASCII. Toolbox for Modbus supporting binary mode RTU and ASCII over tcp/ip and serial.

Hi

I am trying to 'just collect' data from a CR1000 to my PC (not sending data or writing data to CR1000). I want to make the CR1000 as a Modbus slave and make my pc (running with NI LabView) as a Modbus server without going through LoggerNet btwn LabView and CR1000.

From the CR1000's manual and CRBasic's help (Modbus slave example), I compiled and sent the following CRBasic code via LoggerNet (on different pc) to CR1000. Then connected the CR1000 w/ RF416 to the PC (Modbus server) to excute it. I wonder is the code correct? Shall I use ComSDC7 or ComRS232 in the ModBusSlave line?

My system is: one AM25T connects to CR1000;
CR1000 connects to RF416s
RF416 connects to PC(as Modbus server)
Any feedback is appreciated. Thank you,

Hsien

Public BattV
Public RTempC
Public Temp_F(25)

Units BattV=Volts
Units RTempC=Deg C
Units Temp_F=Deg F

Ck2 hip vs ck2%2b. 'Define Data Tables
DataTable(TableTC,True,-1)
DataInterval(0,10,Min,10)
Average(1,BattV,FP2,False)
Average(1,Temp_F(1),FP2,False)
Average(1,Temp_F(2),FP2,False)
Average(1,Temp_F(3),FP2,False)
Average(1,Temp_F(4),FP2,False)
Average(1,Temp_F(5),FP2,False)
Average(1,Temp_F(6),FP2,False)
Average(1,Temp_F(7),FP2,False)
Average(1,Temp_F(8),FP2,False)
Average(1,Temp_F(9),FP2,False)
Average(1,Temp_F(10),FP2,False)
Average(1,Temp_F(11),FP2,False)
Average(1,Temp_F(12),FP2,False)
Average(1,Temp_F(13),FP2,False)
Average(1,Temp_F(14),FP2,False)
Average(1,Temp_F(15),FP2,False)
Average(1,Temp_F(16),FP2,False)
Average(1,Temp_F(17),FP2,False)
Average(1,Temp_F(18),FP2,False)
Average(1,Temp_F(19),FP2,False)
Average(1,Temp_F(20),FP2,False)
Average(1,Temp_F(21),FP2,False)
Average(1,Temp_F(22),FP2,False)
Average(1,Temp_F(23),FP2,False)
Average(1,Temp_F(24),FP2,False)
Average(1,Temp_F(25),FP2,False)
EndTable

Labview Modbus Serial Example

'Main Program
BeginProg
ModBusSlave (ComSDC7,9600,1,Temp_F(),0)

Scan(2,Sec,1,0)
'Default Datalogger Battery Voltage measurement BattV
Battery(BattV)
'Type K (copper-constantan) Thermocouple measurements Temp_F() on the AM25T Multiplexer
AM25T(Temp_F(),25,mV250C,1,1,TypeK,RTempC,1,2,1,True,0,_60Hz,1.8,32)
'Call Data Tables and Store Data
CallTable(TableTC)
NextScan
EndProg

In this post, I will try to describe an approach of LabVIEW/Arduino communication using Modbus protocol. The motivation is to read temperatures from multiple Ds18b20 temperature sensors, however be able to modify easily the code to control relays, read analog inputs etc. I like Ds18b20 sensors from several reason: sufficient accuracy and time constant for many applications, Onewire bus (for one Pt100 or thermocouple is needed a dedicated channel or multiplexer) and good price.

The easiest approach from the point of view of Arduino programming is usage of Serial monitor and read the data with LabVIEW VI Visa node, since Arduino/Ds18b20 measurement is well documented. A tutorial on the topic of LabVIEW/Arduino data transfer through serial is published on Instructables [1]. I experiences some issues with reading data from serial monitor, LabVIEW sometimes read a blank row and I had to add some buffer and data filter and the VI started to expand to a messy mixture of nodes.

Second approach can be based on LabVIEW plugin LINX [2]. With LINX you can very simply read or write values on digital or analog pins. LINX add-on allows you also to include Arduino libraries using Custom commands, but I found this approach quit complicated even though reading data from Ds18b20 was discussed in this post [3], where is also example of the LabVIEW VI.

After some experiments with mentioned approaches, I have started to test the communication via serial protocol called Modbus. Modbus is a serial communications protocol originally published by Modicon in 1979 for use with its programmable logic controllers (PLCs). The data can be transferred through serial lines RS-485, RS-232-C, RS-422, etc with Modbus RTU or via ethernet using Modbus TCP, but there are several other versions. On Arduino, the USB port can be used for data transfer with Modbus RTU. Modbus devices can be master or slave and on one line can be up to 32 slaves. The data stream is controlled by master device, but the information can be transferred both ways: from slave to master or from master to slave.

There can be found several Modbus libraries for Arduino and I selected this one [4]. After installling the library to Arduino IDE, the library can be imported to a new sketch by following code

I will demonstrate the use of modbus library for reading temperature from 3 Ds18b20 sensors. I have them connected to pin 4. To be able to read the data from the sensors, two another libraries is necesseary to import

Full code

Modbus

LabVIEW side:

I am using Modbus API library [5], possible to install via VI Package Manager. Reading data from Arduino through USB is then pretty simple, only two blocks are necessary: Create Serial Master and Read Holding Registers. Full LabVIEW code is in following image.

References

Labview Modbus Serial Example Java

Note: Since free WordPress.com version does not allow you to install plugins, I used online code highlitghter hilite.me.





Comments are closed.