LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Controlling Modbus electric motor with Labview through ethernet

Solved!
Go to solution

Hello, I need some help for a project. I have various equipment for an experiment that was put togehter to work without a computer, just using some separate displays installed on a plastic box. Now I need to make them work using a computer with Labview (2017 Home and Student edition), which I know is not going to be easy. Any help is greatly appreciated, as I am relatively new to LabView.

 

First of all I have an electric motor (Schneider Eectric LMDCE851C) that according to the manufacturer is communicating using Modbus protocol, via an ethernet cable. Is it possible for me to control this motor from Labview, using the software version that I already have (2017 Home and Student edition)? I read that I have to create an I/O server, but I don't seem to have this option in my version...

 

Second, assuming that I have or get the correct version of Labview, is it possible to physically connect the motor to the pc using the existing ethernet port on the computer itself and operate it through Labview? Or do I need to use a DAQ chassis (which I have) with an appropriate input module (that I would need to purchase)?

 

Thank you in advance for any help!

0 Kudos
Message 1 of 10
(3,813 Views)
Solution
Accepted by topic author Bronte02

First, get the NI Modbus Library. You can download it via the VI Package Manager. That will solve your Modbus communication requirements. You will need the documentation for the hardware to identify which registers you need to read/write and what the data set is. The library is pretty straightforward to use.

 

From a legal perspective, you may run into licensing issues using the Student or Home version of LabVIEW. If the application will be used commercially you need a full version of LabVIEW.

 

You can connect the motor directly to the PC. If the motor is fairly old you may need a crossover cable. Most modern Ethernet adapters will automatically switch to support direct connections between devices. You will need to assign the IP addresses correctly on both devices in order for them to communicate.

 

You will not need any DAQ chassis unless you need to interact with specific I/O lines. However, since the motor has a Modbus interface I doubt you will need any I/O control.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 2 of 10
(3,796 Views)

Hi Mark, thank you very much for your reply. Sorry if it took me some time to come back to you, but I had some difficulties establishing a communication between the pc and the motor due to a wrong IP, plus other problems.

Now the computer is connected to the motor and I verified the connection via a specific software available from the manufacturer.


I installed the MODBUS library on LabView and looked at the documentation of the motor and of the library itself.

I was trying to create a simple project just to read a parameter from the motor, (as shown in the introductory example of paragraph 4 at this link: http://www.ni.com/white-paper/7675/en/ ), but I get an error right in the MODBUS master TCP instance. It says it doesn't find anything at the selected address. I set the correct IP address and correct port on the block, ethernet communication as I said is working outside LabView, so I don't know what else to do... Any idea of what I'm doing wrong?

 

Thank you again for the help

0 Kudos
Message 3 of 10
(3,771 Views)

Check the slave ID or unit ID value.  The newer Modbus libraries tend to hide that setting and will default to a certain value.  (I think 1.)  If your controller is set as a different unit ID, it will ignore messages sent to it.

 

I came across this issue for a controller where it was locked into unit ID 0, but the default values for the "purple" modbus library is 1.  Once I used an explicit Set Unit ID node in LabVIEW to set the channel to 0, communications started working.

 

Something worth looking into.

0 Kudos
Message 4 of 10
(3,766 Views)

Thank you for your answer, in the end it was much simpler than that... 

Checking everything again I found out that I connected the constant value of "502", which should identify the port, to the wrong terminal in the TCP Master block, now the connection is indeed working.

 

But I'm having now a different error message, this time at the "Read Coils" block.  It says "Illegal data value", which is one of the four exception codes listed in the manual of the motor. Since I'm not getting the "Illegal data address" or "Illegal or not supported function" ones, I assume the header and fuction code of the MODBUS command I'm sending are accepted, but I'm sending the wrong data.

 

How do I know wich data I'm sending with my command to the slave?

Also, according to the manual, the registers are listed in hexadecimal values, do the functions of MODBUS library take this into account or do I have to convert them myself? 

 

Thank you for your help!

0 Kudos
Message 5 of 10
(3,748 Views)

You are talking about using Read Coils, but also about sending data.

 

You aren't sending data if you want to Read Coils.  If you want to send data, you want to use Write Coils.

0 Kudos
Message 6 of 10
(3,733 Views)
Solution
Accepted by topic author Bronte02

Sorry, I am new to Modbus terms, I was referring to the basic structure of any Modbus data packet (ADU), as reported in the manuals.  They say there is an address, or Modbus Application Protocol header, followed by  function code that specifies the kind of action we want to perform (read inputs, read coils, write coils, etc...) and a "data" segment, which "consists of the data and/or parameters associated with the commands".  In the case of "read coils" the data I was referring to are just the number of coils I want to read.

 

Anyway I found the answer to my question, in my case there are only 4 coils available, and I was trying to access coils from 0 to 10, that's why I got an error message. Thank you anyway for your help!

0 Kudos
Message 7 of 10
(3,706 Views)

I'm resuming this topic to ask maybe a stupid question: how can I write negative numbers on the holding register?

I wanted to set a value for the register variable that defines the current given to the motor, but to have it turn in the opposite direction I'm supposed to write a negative number, which doesn't seem to be possible with the Write Multiple Holding Registers function. Any idea?

 

Thank you for the help

0 Kudos
Message 8 of 10
(3,666 Views)

Use an INT16 as your initial value. This will hold either positive or negative numbers. Just before writing it to the register convert this value to a UINT16.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 9 of 10
(3,664 Views)

Thank you Mark, your suggestion worked just fine. Smiley Happy

 

I have still another question, but I prefer to add it to this topic rather than starting another one, as it's still related to the main subject.

 

I need to read and write also an analog input for the motor, which should be settable to some current or voltage ranges. I see that LabView has some functions for reading inputs in its Modbus library, but none of these seem to work... The "read discrete inputs" function just returns the 4 digital inputs, which are booleans and are not the parameters I'm interested in. The "read input register" function is returning an error no matter what address or number of inputs I give it. I don't see anything else that could match my need. 

 

Do you think that the latter could be the function I'm looking for, I just need to give it the correct address, or I'm looking at the wrong functions?

 

Thank you again

0 Kudos
Message 10 of 10
(3,611 Views)