[StructLayout(LayoutKind.Sequential)]
public struct MEASURE_VALUE
{
public byte byDataInfo;
public byte byJudge;
public byte byTimZero;
public float fValue;
}
[StructLayout(LayoutKind.Sequential)]
public struct MEASURE_DATA
{
public byte byYear;
public byte byMonth;
public byte byDay;
public byte byHour;
public byte byMinute;
public byte bySecond;
public byte byMillsecond;
public uint dwPulseCnt;
public byte byTotalJudge;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public MEASURE_VALUE[] stMesureValue;
}
MEASURE_DATA stMeasureData = new MEASURE_DATA();
int rc = NativeMethods.GetMeasurementValue(ref stMeasureData);
我正在尝试在Pyton中使用带有ctypes的DLL。我想用这个库访问以太网端口并从那里获取数据。如上所述,我在C#中有例子。我用C#获得的数据是正确的,但我用Python得到的数据是错误的。当我进行各种更改时,我在Python中获得的数据在正常数据更改时不会改变。
c#:12.4359,-10000000000,-10000000000,-10000000000 ......
Python:7.174648137343064e-43,8.401298464324817e-45,1.401298464324817e-45,1.401298464324817e-45 ...
class MEASURE_VALUE(ctypes.Structure):
_fields_ = [
("byDataInfo", ctypes.c_ubyte),
("byJudge", ctypes.c_ubyte),
("byTimZero", ctypes.c_ubyte),
("fValue", ctypes.c_float)
]
class MEASURE_DATA(ctypes.Structure):
_fields_ = [
("byYear", ctypes.c_ubyte),
("byMonth", ctypes.c_ubyte),
("byDay", ctypes.c_ubyte),
("byHour", ctypes.c_ubyte),
("byMinute", ctypes.c_ubyte),
("bySecond", ctypes.c_ubyte),
("byMillsecond", ctypes.c_ubyte),
("dwPulseCnt", ctypes.c_ushort),
("byTotalJudge", ctypes.c_ubyte),
("stMesureValue", MEASURE_VALUE*16)
]
lib = ctypes.windll.LoadLibrary("LSIF.dll")
measureData = MEASURE_DATA()
result = lib.GetMeasurementValue(ctypes.byref(measureData))
你能帮我找出我弄错的地方吗?