LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

I cannot read and write information using the Modbus API library and the serial port becomes unusable when the program is run.

Solved!
Go to solution

I want to communicate with an Ac Servo motor over Modbus RTU protocol over labview without using PLC. Currently, I can connect to the servo's own program, read and write parameters, but the problem is that I cannot do this with labview.
The serial port is displayed on the NI-Max.

I was able to get values between 0-65531 once using an I/O server, but I cannot establish a healthy connection in my next attempts.


Below is the piece of code I used as an example.

 

All cable connections are ok. Serial port baud rate etc. all settings are correct.

Error 56 occurred at RTU Data Unit.lvclass:Read ADU Packet.vi:5030001 I get this error when I run the program.

 

I do a lot of research and have documentation on communicating with the device.
I just need help with this. there is no one locally that can help.
Every opinion given is worthy of respect.

Download All
0 Kudos
Message 1 of 37
(2,712 Views)

@constructionworker wrote:

I want to communicate with an Ac Servo motor over Modbus RTU protocol


What AC Servo?

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 2 of 37
(2,691 Views)

Is this still on the myRIO or have you moved to a normal PC? How did you connect the drive to your computer?

Rolf Kalbermatter
My Blog
0 Kudos
Message 4 of 37
(2,647 Views)

Hi mr.

 

 

Communication parameters via servo driver
I set it as below.
Baudrate:115200
protocol:8N2
station:127
communication selection:RS232
communication address:0x007F

 

0 Kudos
Message 5 of 37
(2,638 Views)

Since your device is configured to use station ID 127 (probably the same as communication port 0x007F) it could make a significant difference if you change the Modbus Unit ID on the LabVIEW side to 127 too. What's that about consistent naming you ask? Well ask the thousands of Modbus adopters worldwide. There's an "officious" Modbus standard as made by the original inventor Modicon and later passed to the Modbus Organization and maintained by them since. It specifies a lot of things but is pretty vague in many others. And it does simply call this element server address.

 

For RS-232 connections this element is usually not important as RS-232 is normally always a point to point connection, but in RS-422/485 networks it is very important. Some devices will ignore this address byte and answer irrespective of its value when connected through RS-232, others make no difference if they are connected over RS-422/485 or RS-232 and insist on correct addressing anyways.

Rolf Kalbermatter
My Blog
0 Kudos
Message 6 of 37
(2,621 Views)

I change it to Unit ID 127, I connect, even the RX light on the converter cable between the servo driver and the computer is blinking.
but I can't read any value.
But there is a problem with my current instance of Labview, if I close the program the port is now full.

 

What about consistent naming you ask? I don't quite understand this question. Could you please explain a little bit?

 

By the way, I can set RS-232 and connect with ASDA soft program. No problem. I guess that means this. Serial communication should be possible without any problems with the parameters set on the servo.

I can connect with the program called Modscan32.

I am reading some values.
The screenshot is as follows.

If I change the address in the Modscan32 Application I get different output.

0 Kudos
Message 7 of 37
(2,611 Views)
Solution
Accepted by topic author constructionworker

That Modscan image is inconclusive at best!

 

You try to WRITE to Coil Address 01 in LabVIEW but READ 100 coils starting from address 1 and 2 in Modscan.

You try to READ 1 Holding Register from Address 00 in LabVIEW and none in Modscan.

 

The data you see in the Modscan screen is the serial data bytes SENT OUT to the device. Not what it returns. It most likely returns nothing as indicated by the Valid Slave Responses: 0.

Rolf Kalbermatter
My Blog
0 Kudos
Message 8 of 37
(2,601 Views)

I did some testing on your suggestion. I don't write labview anymore, I just read it and got a result like the picture below. What does it mean. But these values I read cannot be ordinary values because if I control the motor, these values change.

 

Now I don't get an error if I press the labview stop button.

0 Kudos
Message 9 of 37
(2,593 Views)

Modbus is a general purpose bus. What the different register mean, what values they contain and which ones can be only read or also written is completely device specific.

 

As such you should of course refer to chapter 8 in this manual: https://downloadcenter.deltaww.com/downloadCenterCounter.aspx?DID=3948&DocPath=1&hl=en-US

 

Here the different registers are documented. As extra complication they seem to document the address of each register in byte offsets, whereas Modbus uses normally register offsets with each register being 2 bytes. And their registers are meant to be read and written as Holding Registers.

 

So in order to access any of these registers you probably want to use the Read or Write Holding Register function, apply an address that is half of what this manual describes for the relevant register and then specify the number of registers to read.

 

Try to do the same in the ModScan application (and set the Device ID there also to 127, Holding Register to access not Coils) and see if you get anything there that matches with what the LabVIEW VI returns. if you want to read a specific information you have to see what register that is then lookup its address in that manual, most likely divide it by 2 and enter that address in LabVIEW. Then see if you can make sense of that. Once you figured out the relevant details you can also try to change some registers but watch out that some of the registers are read only and will probably cause a Modbus exception if you try to write them.

Rolf Kalbermatter
My Blog
0 Kudos
Message 10 of 37
(2,585 Views)