Python と ctypes を使用してモーター制御システムにパッチを適用しようとしています。必要なことの 1 つは、テキスト入力を取得して 8 ビットの符号付き整数に変換することです。
以下は、私が呼び出そうとしている関数のドキュメントです。プログラムに入力するテキストは「EPOS2」です
データ型の定義は次のとおりです (「char*」は 8 ビットの符号付き整数に相当することに注意してください)。
では、'EPOS2' を -128 から 127 の間の値に変換するにはどうすればよいでしょうか?
最終的に私がやろうとしていることは、次のようなものです:
import ctypes #import the module
lib=ctypes.WinDLL(example.dll) #load the dll
VCS_OpenDevice=lib['VCS_OpenDevice'] #pull out the function
#per the parameters below, each input is expecting (as i understand it)
#an 8-bit signed integer (or pointer to an array of 8 bit signed integers,
#not sure how to implement that)
VCS_OpenDevice.argtypes=[ctypes.c_int8, ctypes.c_int8, ctypes.c_int8, ctypes.c_int8]
#create parameters for my inputs
DeviceName ='EPOS2'
ProtocolStackName = 'MAXON SERIAL V2'
InterfaceName = 'USB'
PortName = 'USB0'
#convert strings to signed 8-bit integers (or pointers to an array of signed 8-bit integers)
#code goes here
#code goes here
#code goes here
#print the function with my new converted input parameters
print VCS_OpenDevice(DeviceName,ProtocolStackName,InterfaceName,PortName)