09-28-2018 07:00 AM
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.
Solved! Go to Solution.
09-28-2018 08:34 AM
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?
09-28-2018 08:48 AM
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.
09-28-2018 08:58 AM
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?
09-28-2018 09:40 AM
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.
09-28-2018 09:48 AM
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?
09-29-2018 09:50 AM
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.
10-07-2018 08:55 AM
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..:)