且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在python中将字符串转换为8位带符号整数

更新时间:2023-11-07 13:56:40

您的接口需要 char * 是C字符串。等效的 ctypes 类型为 c_char_p 。使用:

Your interface takes char* which are C strings. The equivalent ctypes type is c_char_p. Use:

import ctypes
lib = ctypes.WinDLL('example.dll')
VCS_OpenDevice = lib.VCS_OpenDevice
VCS_OpenDevice.argtypes = [ctypes.c_char_p,ctypes.c_char_p,ctypes.c_char_p,ctypes.c_char_p]

DeviceName ='EPOS2'
ProtocolStackName = 'MAXON SERIAL V2'
InterfaceName = 'USB'
PortName = 'USB0'

print VCS_OpenDevice(DeviceName,ProtocolStackName,InterfaceName,PortName)

此外, WinDLL 通常仅Windows系统DLL才需要。如果在C头文件中将接口声明为 __ stdcall ,则 WinDLL 是正确的;否则,请使用 CDLL

Also, WinDLL is normally only needed for Windows system DLLs. If your interfaces are declared __stdcall in the C header file, WinDLL is correct; otherwise, use CDLL.

此外,您的返回码记录为 DWORD ** ,这有点奇怪。为什么不使用 DWORD ?如果 DWORD * 是正确的,要访问返回值所指向的DWORD的值,可以使用:

Additionally, your return code is documented as a DWORD*, which is a bit strange. Why not DWORD? If DWORD* is correct, to access the value of the DWORD pointed to by the return value, you can use:

VCS_OpenDevice.restype = POINTER(c_uint32)
retval = VCS_OpenDevice(DeviceName,ProtocolStackName,InterfaceName,PortName)
print retval.contents.value