LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Trouble reading PLC variable froom TwinCAT using DLL and call function library

Solved!
Go to solution

Hello community,

 

I am trying to access TwinCAT PLC variables by using call library function from LABVIEW and accessing Beckhoff open protocol ADSDLL. Unfortunately, one of the function to access PLC variables can not recognize any variable from PLC and returns error code.


Is there anybody who has already faced this kind of problem? Please help.

Regards,
Harry

0 Kudos
Message 1 of 8
(5,539 Views)

You'll get better answers if you give more details in your question, including attaching code. 

 

"Unfortunately, one of the function to access PLC variables can not recognize any variable from PLC and returns error code."

 

Which function? What error code?

0 Kudos
Message 2 of 8
(5,522 Views)

Thanks for replying.

If you are familiar with ADS protocol then there is a function called ADSSYNCREADWRITEREQ to returns a handle to a variable in PLC and then one can read and write value to that specific variable in PLC. Idea is reading value from TwinCAT PLC by LabVIEW VI.

All ADS functions return error codes. In my case it returns that variable can not be found.

 

Question: Am I passing PLC variable in wrong way? Please see attached PNG. In this case the variable is called with ".PLCvar" as a string. Of course this variable also exists in TwinCAT PLC (PLCvar.PNG attached )...

 

Thanks in advance and waiting for your reply.

Download All
0 Kudos
Message 3 of 8
(5,517 Views)

Can you show the code for the AdsSyncReadWriteReq.vi? Why do you have a "." in front of PLCVar? It is not defined that way in the PLC code. (I am using the .NET interface to do something similar and do not need to preface variable names with a "." but the DLL setup may be different)

 

Also, what parameters are you using to open the ADS client connection? Are you sure you are connected on the correct server port? Are you able to get the device status or any other read back from the PLC? 

0 Kudos
Message 4 of 8
(5,515 Views)

I am letting run TwinCAT PLC locally. It assigns therefore a virtual ADS port. In my case it is 851 for TwinCAT 3.1.
Honestly I don't know how to pass variable to ADS function. 

I have no familiarity with .NET but only with C++ programming language. ADSDLL allows programming through C++. I have already programmed a program on Visual Studio using ADSDLL library to get notification from ADS device cyclic  and on change. I want to try the same with LabVIEW. In Visual I have passed the same variable with "MAIN.PLCvar" and it works. 

As asked I attach the front panel diagram of AdsSyncReadWriteReq. Here as you can see it gets NetID from TwinCAT local system and assigns port number to 851. The error as specified in error field is 1808, meaning "symbol not found" according to Beckhoff specifications.

0 Kudos
Message 5 of 8
(5,508 Views)

A picture of the front panel isnt really helpful - that doesnt give much information other than what you already showed - we need to see the actual code. (Or MUCH better, zip up your project and attach it if youre able)

 

If you are addressing the variable as MAIN.PLCVar in your VS code and its working, why are you trying to address it as '.PLCVar' in LabVIEW? Have you tried addressing it in the same way?

0 Kudos
Message 6 of 8
(5,505 Views)

Yes I have tried in many different ways. I think the problem lies in the addressing of such variable. I attach pictures of block and front panel as well as VI. If you notice it returns ADS error 1808. 

 

Looking forward to your reply. Thanks a lot in advance.

Download All
0 Kudos
Message 7 of 8
(5,485 Views)
Solution
Accepted by Harry_Hayer

I found the solution. One should Pass the PLC variable Name as strings to pointers in the call library Function node as "Main.variablename". The other parameter's configuration stays the same..:)

 

0 Kudos
Message 8 of 8
(5,463 Views)