I’m new in this forum and have the following problem:
I 've written a Module K8055N.py with Python V3.7.4 and I am using the original K8055D.dll from VELLEMAN (V5.0.0.0) with ctypes to control the USB-board on Windows 32-bit.
All functions work fine except the following one: ReadBackAnalogOut
and I have no idea on how to use this in Python.
I think, this function has the goal, to receive-back the momentary data from the two PWM’s when reconnecting the board. Am I right?
I 'm a little bit confused about the use of the expression “(*Buffer)” mentioned in the synthax-declaration in the dll-manual:
voidReadBackAnalogOut(int *Buffer);
Can anyone instruct me, how to code this function?
An example in Python3 would be appreciated.
int * Buffer is pointer to an array of two 32-bit integers where the data will be read.
Here an example in Delphi:
procedure TForm1.Button10Click(Sender: TObject);
var out_digital: integer;
out_analog: array[0..1] of integer;
begin
out_digital:=ReadBackDigitalOut;
ReadBackAnalogOut(@out_analog[0]);
CheckBox6.checked:=(out_digital and 1)>0;
CheckBox7.checked:=(out_digital and 2)>0;
CheckBox8.checked:=(out_digital and 4)>0;
CheckBox9.checked:=(out_digital and 8)>0;
CheckBox10.checked:=(out_digital and 16)>0;
CheckBox11.checked:=(out_digital and 32)>0;
CheckBox12.checked:=(out_digital and 64)>0;
CheckBox13.checked:=(out_digital and 128)>0;
TrackBar1.position:=255-out_analog[0];
TrackBar2.position:=255-out_analog[1];
TrackBar1Change(Self);
TrackBar2Change(Self);
end;
But I do not know Delphi and as a Python-beginner too, I’m not able to figure out how to translate your suggestion in adequate Python-code.
Sorry - but this was the reason why I posted my wish to get an example in Python3 …
So I’m really dependent on a precise and eventually also commented example in Python3.
import ctypes
from ctypes import *
import time
K8055dll = ctypes.WinDLL("K8055D.dll")
p0 = ctypes.c_long(0)
print ("\nOpening Device\n")
rc = K8055dll.OpenDevice(p0)
if (rc == -1):
print ("Card was not found")
exit(1)
print ("\nTesting the Analog Output Channels\n")
print ("OutputAllAnalog(50, 200)")
K8055dll.OutputAllAnalog(50, 200)
print ("\nTesting ReadBackAnalogOut()")
IntArray2 = c_int * 2
ia = IntArray2(0, 0)
K8055dll.ReadBackAnalogOut(byref(ia))
print ("the value of Analog Channel 1 is: ")
print(ia[0])
print ("the value of Analog Channel 2 is: ")
print(ia[1])
print ("\n\nClosing Device\n")
K8055dll.CloseDevice()
exit(0)
Output:
Opening Device
Testing the Analog Output Channels
OutputAllAnalog(50, 200)
Testing ReadBackAnalogOut()
the value of Analog Channel 1 is:
50
the value of Analog Channel 2 is:
200
Closing Device
>>>