IO-Warrior56 nicht vollständig ansteuerbar mit Python

Dies ist das deutsche Forum für alle Themen um den IO-Warrior. Beiträge bitte nur in Deutsch.

Moderator: Guido Körber

Post Reply
ebug38
Posts: 5
Joined: Thu Jun 27, 2019 2:19 pm

IO-Warrior56 nicht vollständig ansteuerbar mit Python

Post by ebug38 »

Hallo,

aktuell versuche ich mit Python Daten von der IOW56 auszulesen. Ich scheitere bereits bei grundlegenden Funktionen wie z.B. IowKitGetRevision oder IowKitGetSerialNumber.

Ich habe provisorisch mal zum Testen folgenden Code geschrieben. Testread ist auskommentiert.

Code: Select all

import ctypes

testlib = ctypes.CDLL("iowkit.dll")
HANDLE = testlib.IowKitOpenDevice()
NUM_DEV = testlib.IowKitGetNumDevs()
DEVICE_HANDLE = testlib.IowKitGetDeviceHandle(1)
#testRead = testlib.IowKitReadImmediate()

testBuffer = ctypes.c_buffer(9)
serial = testlib.IowKitGetRevision(DEVICE_HANDLE)

print(DEVICE_HANDLE)
print(testlib)
print(HANDLE)
print(NUM_DEV)
#print(testRead)
print(serial)


testlib.IowKitCloseDevice()
Meine Ausgabe sieht wie folgt aus:

Code: Select all

1795489816
<CDLL iowkit.dll', handle 180000000 at 0x17e68b76400>
1795489816
1
0
Ich habe jetzt einiges ausprobiert um unter anderem nur Serial oder Revision zu printen, aber ich kriege jedes Mal 0 als Ergebnis.
Habe leider keine Ahnung was ich ändern muss. Vielleicht könnt ihr mir auf die Sprünge helfen?
User avatar
Christoph Jung
Posts: 670
Joined: Sun Oct 08, 2006 3:43 pm
Location: Germany / Berlin
Contact:

Re: IO-Warrior56 nicht vollständig ansteuerbar mit Python

Post by Christoph Jung »

Dieses Skript läuft bei mir und gibt ein paar Daten aus

Code: Select all

import time, os, sys
import ctypes

#defines
IOWKIT56_SPECIAL_REPORT = ctypes.c_ubyte * 64
IOWKIT56_IO_REPORT = ctypes.c_ubyte * 8
SERIAL_NUMBER_BUFFER = ctypes.c_ubyte * 9

numPipe = ctypes.c_ulong(0) #Interface number, 0 = IO-Ports, 1 = Special modes
length = ctypes.c_ulong(8)	#Byte count for report (in this sample IO-Ports for IOW56)

print("Python version: ", sys.version)

#load/find iowkit
try:
	iowkit = ctypes.WinDLL(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'iowkit'))
except:
	try:
		iowkit = ctypes.WinDLL(os.path.join(os.curdir, 'iowkit'))
	except:
		iowkit = ctypes.WinDLL('iowkit')

#open iowkit and get first IO-Warrior device
ioHandle = iowkit.IowKitOpenDevice()
if ioHandle != 0:

	#Get number of IO-Warrior
	IowKit_NumbDevs = iowkit.IowKitGetNumDevs()
	print ("NumbDevs: ", str(IowKit_NumbDevs))

	#Get product ID of first IO-Warrior found on USB
	IowKit_ID = iowkit.IowKitGetProductId(ioHandle)
	print("Product ID: {0:02x}".format(IowKit_ID))

	#Revision
	IowKit_Revision = iowkit.IowKitGetRevision(ioHandle)
	print("Revision: {0:02x}".format(IowKit_Revision))

	#Serial
	SerNumb = ctypes.create_unicode_buffer("xxxxxxxx")
	IowKit_SerNumb = iowkit.IowKitGetSerialNumber(ioHandle, SerNumb)
	print ("SerNumb: ", str(SerNumb.value))

	# set read timeout to 1000 msecs
	status = iowkit.IowKitSetTimeout(ioHandle, ctypes.c_ulong(1000))

	#Create report. 1x report ID, 7x data bytes
	report = IOWKIT56_IO_REPORT(0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF)

	status = iowkit.IowKitWrite(ioHandle, numPipe, ctypes.byref(report), length)

else:
	print ("No IO-Warrior found")

# DON'T FORGETT TO CLOSE AT THE END OF THE SCRIPT!!!!!
iowkit.IowKitCloseDevice(ioHandle)
Die Ausgabe:
Python version: 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:16:59) [MSC v.1900 32 bit (Intel)]
NumbDevs: 1
Product ID: 1503
Revision: 2001
SerNumb: 10003EE5
Abteilung: Softwareentwicklung
Folge uns auf Twitter
Follow us on twitter
ebug38
Posts: 5
Joined: Thu Jun 27, 2019 2:19 pm

Re: IO-Warrior56 nicht vollständig ansteuerbar mit Python

Post by ebug38 »

Vielen Dank für die schnelle Antwort.

Ich habe das Script copy und pasted und erhalte folgende Ausgabe:

Python version: 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)]
NumbDevs: 1
Product ID: 00
Revision: 00
SerNumb: xxxxxxxx

Kann es sein, dass ich etwas übersehen habe oder an irgendwas denken sollte?
User avatar
Christoph Jung
Posts: 670
Joined: Sun Oct 08, 2006 3:43 pm
Location: Germany / Berlin
Contact:

Re: IO-Warrior56 nicht vollständig ansteuerbar mit Python

Post by Christoph Jung »

Ich weiß nicht, ob das was mit der Python version zu tun hat. Ich habe auf meinem Windows noch 3.5 drauf.
Ich arbeite sehr sehr selten mit Python und weiß daher nicht, wie sich die Versionen unterscheiden.
Die Funktion IowKitGetSerialNumber() gibt einen 8 Zeichen langen unicode zurück.
Abteilung: Softwareentwicklung
Folge uns auf Twitter
Follow us on twitter
ebug38
Posts: 5
Joined: Thu Jun 27, 2019 2:19 pm

Re: IO-Warrior56 nicht vollständig ansteuerbar mit Python

Post by ebug38 »

Ich werde testweise mal andere Pythonversionen ausprobieren.

Ich sehe, dass deine Ausgabe von 2015 ist.
Kann es sein, dass zwischenzeitlich etwas von eurer Seite (sowohl board als auch dll? - ich benutze die 64bit DLL) aus verändert wurde und es deswegen zu Komplikationen kommen kann?
User avatar
Christoph Jung
Posts: 670
Joined: Sun Oct 08, 2006 3:43 pm
Location: Germany / Berlin
Contact:

Re: IO-Warrior56 nicht vollständig ansteuerbar mit Python

Post by Christoph Jung »

Für die alten IO-Warrior gab es keine änderungen. Wir habe im aktuellen SDK zum IO-Warrior den IOW28 hinzugefügt und
dafür auch gleich die DLLs neu erstellt. Ich nutzte natrürlich diese und mein Python ist noch 32 Bit.

Am besten mal (wenn noch nicht geschehen) das neue SDK runterladen und dort die x64 DLL nehmen. Vielleicht liegts daran.
Ich schaffe es heute nicht mehr mich damit zu beschäftigen.
Abteilung: Softwareentwicklung
Folge uns auf Twitter
Follow us on twitter
ebug38
Posts: 5
Joined: Thu Jun 27, 2019 2:19 pm

Re: IO-Warrior56 nicht vollständig ansteuerbar mit Python

Post by ebug38 »

Habe Python mal downgraded und habe leider immer noch die gleiche Ausgabe. (natürlich mit aktualisierter Python Version).

Muss ich eventuell schon vorher etwas beachten? Vllt bestimmte PINs belegen oder sonstiges?
User avatar
Christoph Jung
Posts: 670
Joined: Sun Oct 08, 2006 3:43 pm
Location: Germany / Berlin
Contact:

Re: IO-Warrior56 nicht vollständig ansteuerbar mit Python

Post by Christoph Jung »

Ich habe etwas gebrauch um das hin zu bekommen, aber jetzt läuft es bei mir. Der Grund, warum es vorher geklappt hat war, dass ich Python und auch die DLL in 32 Bit benutz haben.
Bei 64 Bit (inkl. iowkit.dll) benötigt Python anscheinend zwingend die ctypes der Funktionen, sonst kommt nur Bogus raus. Ich habe jetzt "Python version: 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)]"
Hier das neue Skript:

Code: Select all

import time, os, sys
import ctypes

#defines
IOWKIT56_IO_REPORT = ctypes.c_ubyte * 8
IOWKIT56_IO_REPORT_SIZE = 8

IOWKIT56_SPECIAL_REPORT = ctypes.c_ubyte * 64
IOWKIT56_SPECIAL_REPORT_SIZE = 64

SERIAL_NUMBER_BUFFER = ctypes.c_ubyte * 9

#Interfaces
IOW_PIPE_IO_PINS = 0
IOW_PIPE_SPECAIL_MODE = 1

#ProductIDs for IO-Warrior devices
IOWKIT_PRODUCT_ID_IOW40 = 0x1500
IOWKIT_PRODUCT_ID_IOW24 = 0x1501
IOWKIT_PRODUCT_ID_IOW56 = 0x1503


print("Python version: ", sys.version)

#load/find iowkit
try:
	iowkit = ctypes.WinDLL(os.path.join(os.curdir, 'iowkit'))
except:
	try:
		iowkit = ctypes.WinDLL(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'iowkit'))	
	except:
		iowkit = ctypes.WinDLL('iowkit')

#Function headers for Python (x64) !IMPORTANT!

#IowKitOpen
iowkit.IowKitOpenDevice.restype = ctypes.c_voidp

#IowKitCloseDevice
iowkit.IowKitCloseDevice.argtypes = [ctypes.c_voidp]

#IowKitWrite()
iowkit.IowKitWrite.argtypes = [ctypes.c_voidp, ctypes.c_ulong, ctypes.c_voidp, ctypes.c_ulong]
iowkit.IowKitWrite.restype = ctypes.c_ulong

#IowKitRead()
iowkit.IowKitRead.argtypes = [ctypes.c_voidp, ctypes.c_ulong, ctypes.c_voidp, ctypes.c_ulong]
iowkit.IowKitRead.restype = ctypes.c_ulong

#IowKitReadNonBlocking()
iowkit.IowKitReadNonBlocking.argtypes = [ctypes.c_voidp, ctypes.c_ulong, ctypes.c_voidp, ctypes.c_ulong]
iowkit.IowKitReadNonBlocking.restype = ctypes.c_ulong

#IowKitReadImediate()
iowkit.IowKitReadImmediate.argtypes = [ctypes.c_voidp, ctypes.POINTER(ctypes.c_ulong)]
iowkit.IowKitReadImmediate.restype = ctypes.c_bool

#IowKitGetNumDevs
iowkit.IowKitGetNumDevs.restype = ctypes.c_ulong

#IowKitGetDeviceHandle
iowkit.IowKitGetDeviceHandle.argtypes = [ctypes.c_ulong]
iowkit.IowKitGetDeviceHandle.restype = ctypes.c_voidp

#IowKitgetProductID
iowkit.IowKitGetProductId.argtypes = [ctypes.c_voidp]
iowkit.IowKitGetProductId.restype = ctypes.c_ulong

#IowKitGetRevision
iowkit.IowKitGetRevision.argtypes = [ctypes.c_voidp]
iowkit.IowKitGetRevision.restype = ctypes.c_ulong

#IowKitGetSerianlNumber
iowkit.IowKitGetSerialNumber.argtypes = [ctypes.c_voidp, ctypes.c_voidp]
iowkit.IowKitGetSerialNumber.restype = ctypes.c_bool

#IowKitSetTimeout
iowkit.IowKitSetTimeout.argtypes = [ctypes.c_voidp, ctypes.c_ulong]
iowkit.IowKitSetTimeout.restype = ctypes.c_bool

#IowKitSetWriteTimeout
iowkit.IowKitSetWriteTimeout.argtypes = [ctypes.c_voidp, ctypes.c_ulong]
iowkit.IowKitSetWriteTimeout.restype = ctypes.c_bool

#IowKitVersion
iowkit.IowKitVersion.restype = ctypes.c_char_p


#open iowkit and get first IO-Warrior device
ioHandle = iowkit.IowKitOpenDevice()

#IO-Warrior found and get first handle from IowKitOpenDevice
if ioHandle != 0:
	print("Handle: {0:02x}".format(ioHandle))
	
	#Get number of IO-Warrior
	IowKit_NumbDevs = iowkit.IowKitGetNumDevs()
	print ("NumbDevs: " , str(IowKit_NumbDevs))

	#Get product ID of first IO-Warrior found on USB
	pid = iowkit.IowKitGetProductId(ioHandle)
	print("Product ID: {0:02x}".format(pid))
	
	#Revision
	revision = iowkit.IowKitGetRevision(ioHandle)
	print("Revision: {0:02x}".format(revision))
	
	#Serial
	SerNumb = ctypes.create_unicode_buffer("xxxxxxxx")
	IowKit_SerNumb = iowkit.IowKitGetSerialNumber(ioHandle, SerNumb)
	print ("SerNumb: " , str(SerNumb.value))

	# set read timeout to 1000 msecs
	status = iowkit.IowKitSetTimeout(ioHandle, ctypes.c_ulong(1000))
	
	#Create report. 1x report ID, 7x data bytes
	report = IOWKIT56_IO_REPORT(0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF)

	status = iowkit.IowKitWrite(ioHandle, IOW_PIPE_IO_PINS, ctypes.byref(report), IOWKIT56_IO_REPORT_SIZE)
	
else:
	print ("No IO-Warrior found")

# DON'T FORGETT TO CLOSE AT THE END OF THE SCRIPT!!!!!
iowkit.IowKitCloseDevice(ioHandle)
Meine Ausgabe:
Python version: 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)]
Handle: 26f54cd0018
NumbDevs: 1
Product ID: 1503
Revision: 2001
SerNumb: 10003EE5


Ich habe nicht alle Funktionen getestet, aber theoretisch sollte alles gehen.
Abteilung: Softwareentwicklung
Folge uns auf Twitter
Follow us on twitter
Post Reply