chwiede / pyads

Beckhoff ADS implementation for python
MIT License
49 stars 14 forks source link

AdsDevice.GetSymbolHandle throws symbol not found exception #10

Closed dddomodossola closed 7 years ago

dddomodossola commented 7 years ago

I tried it unsucessfully. Maybe am I missing something? Can you provide an usage example?

Thank you for sharing this brillantly written library.

ccatterina commented 7 years ago

Hello, Here's an example:

with AdsDevice(amsTarget='192.168.1.85.1.1:801', amsSource='192.168.1.125.1.1:3515') as device:
     data = device.GetSymbolHandle('variable_name')

Remember that the name of global variables starts with '.' so if you have a global variable called 'foo' you must use '.foo' .

dddomodossola commented 7 years ago

Thank you for your reply. It reflects what I tried to do but without success. Does this code works for you?

ccatterina commented 7 years ago

Yes, for me it works, i've just done a test. I use a CX9020 with twincat 2.

dddomodossola commented 7 years ago

I'm using twincat2 too. I will do some tests tomorrow at my office. ;-)

dddomodossola commented 7 years ago

@ccatterina Doing further tests.. I have two questions: I can't get connected to the target device if I don't specify a targetIp

with AdsDevice(amsTarget="5.27.216.16.1.1:801", amsSource="192.168.56.1.1.1:801", targetIP = "192.168.2.5") as device:
    handle = device.GetSymbolHandle(".TOHMI")

Why?

Also, where to get the amsSource PORT value? Is it an arbitrary value?

I'm still unable to obtain the symbol handle. Tried to do the same in C++ with ads dll with success.

ccatterina commented 7 years ago

Hi, You must specify targetIP because adsDevice need both IP Address and AmsNetID to works. In my example i didn't specify it because the first 4 octets of amsNetID corresponds to the IP of the PLC, in this case pyads obtain targetIP from amsNetID. (For the amsSource is the same, so amsNetID of the source must corresponds to the sourceIP + '1.1') Regarding the amsSource port, it is arbitrary but it's better make sure that the port is not used by something else, i use socket.bind to obtain a free port.

It still throws symbol not found exception?

dddomodossola commented 7 years ago

Ok it works. Thank you a lot for the help! ;-)

ccatterina commented 7 years ago

you're welcome! :smiley: