Cannot return value from C function in Python script, but maybe in console

I am using python (Pydev) to communicate with stepper motors with a DLL using ctypes. I am trying to get the position of the engine. The thing is, if I type the script line by line in the console, it works, but if I run the script, it always gives me 0. This is my code:

import ctypes

AC=windll.hvpositionerv2
adr=addressof
class PositionerInfo (Structure):
    _fields_=[("id",c_int),("locked",c_bool)]

ptr=POINTER(PositionerInfo)()
devCount=AC.PositionerCheck(adr(ptr))
print("Devices found: "+repr(devCount))
for i in range(min(adr(ptr),devCount)):
     print("ID: "+repr(ptr[i].id)+" Locked? "+repr(ptr[i].locked))

handle=POINTER(c_int)()
AC.PositionerConnect(0,adr(handle))

While the program is connected only to the device. Now the problem is this:

ypos=c_int()
AC.PositionerGetPosition(handle,1,adr(ypos)

print(ypos.value)

This always prints 0 if I run the script (in Eclipse) but it works in the console.

+3
source share
1 answer

: . , , 0. 1- AC.PositionerGetPosition.

0

Source: https://habr.com/ru/post/1794733/


All Articles