Closed sameer546 closed 6 years ago
Hello,
If the PLC IP address is different from the first four octects of the AmsNetID, you must specify the targetIP
argument:
from pyads import *
with AdsDevice(amsTarget="5.35.137.56.1.1:801", targetIP="192.168.0.60") as device:
info = device.ReadDeviceInfo()
print(info)
@ccatterina 1. I'm running the above code in a linux based system, Will it work?
I tried your above suggestion, but it did not worked for me..
I'm running the above code in a linux based system, Will it work?
Yes, I use this package with a raspberry pi.
Can you help me in understanding this : ""Remember: You have to insert your client AMS-ID into the ams table of your target device!"
Ok, it means that you must insert the AMS Net ID of your system (the machine where pyads is installed) in the routes table on the CX9020.
In the Twincat System Manager
, select the target and in the left menu, under System Configuration
, you should find Route Settings
.
Select Static routes
and then add a new route with the AMS Net ID and IP Address of your client system.
NB: You can set the AMS Net ID of your system specifying amsSource
(default: 0.0.0.0.0.0:32905
):
from pyads import *
with AdsDevice(amsTarget="5.35.137.56.1.1:801",
amsSource='12.3.245.12.1.1:32455',
targetIP="192.168.0.60") as device:
info = device.ReadDeviceInfo()
print(info)
Thanks a lot @ccatterina that makes sense..
Could u please help me out in the add route settings, I have attached a snapshot..based on the numbers just guide me what should I fill in those areas... After Doing this Do I need to install anymore library files or pyads is enough??
0.0.0.0.0.0
if you don't specify the amsSource
in the code example, otherwise the AmsNetID of the amsSource
specified)After Doing this Do I need to install anymore library files or pyads is enough??
pyads is enough.
@ccatterina : Thanks a lot..We routed using plc directly. One more query: Did you captured the CX9020 time and date, if Yes what are the variable names which we can query? Please let me know about it..
Sorry for the late reply, i was a bit busy last week.
Btw I never tried to get time and date from the CX9020. If there was a way to set a variable with the datetime in the CX9020, you can get that variable value using pyads.
Tomorrow i'll make a test.
Here you can find a function block that retrieves system time as a string.
If you assign the result of this FB to a global variable called, for example, sysdt
, you can get it using pyads
in this way:
device.ReadByName('.sysdt', AdsDatatype.String)
I'm using the deviceinfo.py code for reading the device info of the plc..I'm using CX9020 plc IP Address of PLC: 192.168.0.60 amsnetid : 5.35.137.56.1.1 port: 801
from pyads import *
with AdsDevice(amsTarget="5.35.137.56.1.1:801") as device: info = device.ReadDeviceInfo() print(info)
Error: Traceback (most recent call last): File "first_contact.py", line 4, in
info = device.ReadDeviceInfo()
File "build/bdist.linux-armv7l/egg/pyads/adsclient.py", line 201, in ReadDeviceInfo
File "build/bdist.linux-armv7l/egg/pyads/commands/adscommand.py", line 36, in Execute
File "build/bdist.linux-armv7l/egg/pyads/adsclient.py", line 131, in SendAndRecv
File "build/bdist.linux-armv7l/egg/pyads/adsclient.py", line 69, in Connect
pyads.adsexception.AdsException: 'A socket operation was attempted to an unreachable host'
Can anyone help me out in resolving this error??