Мне нужно управлять контактами GPIO устройства CP210x, используя CP210xManufacturing.dll
и CP210xRuntime.dll
, предоставленные Silicon Labs. Мне удается открыть и закрыть устройство и получить номер детали. (в моем случае CP2105).
Я думаю, что успешно прочитал защелку, но я не уверен. Я также вызываю функцию фиксации записи, и никакой ошибки не возвращается, и никакие контакты не переключаются.
По предоставленной утилите (CP21xxCustomizationUtility.exe) показывает, что оба порта находятся в режиме GPIO.
Вот мой код: использование системы; с помощью System.Runtime.InteropServices;
namespace CP210x
{
public class CP210x
{
[DllImport("CP210xManufacturing.dll")]
private static extern Int32 CP210x_GetNumDevices(ref Int32 numOfDevices);
public static Int32 GetNumDevices(ref Int32 numOfDevices)
{
return CP210x_GetNumDevices(ref numOfDevices);
}
[DllImport("CP210xManufacturing.dll")]
private static extern Int32 CP210x_Open(Int32 deviceNum, ref IntPtr handle);
public static Int32 Open(Int32 deviceNum, ref IntPtr handle)
{
return CP210x_Open(deviceNum, ref handle);
}
[DllImport("CP210xManufacturing.dll")]
private static extern Int32 CP210x_Close(IntPtr handle);
public static Int32 Close(IntPtr handle)
{
return CP210x_Close(handle);
}
[DllImport("CP210xManufacturing.dll")]
private static extern Int32 CP210x_GetPartNumber(IntPtr handle, Byte[] lpbPartNum);
public static Int32 GetPartNumber(IntPtr handle, Byte[] lpbPartNum)
{
return CP210x_GetPartNumber(handle, lpbPartNum);
}
[DllImport("CP210xRuntime.dll")]
private static extern Int32 CP210xRT_WriteLatch(IntPtr handle, UInt16 mask, UInt16 latch);
public static Int32 WriteLatch(IntPtr handle, UInt16 mask, UInt16 latch)
{
return CP210xRT_WriteLatch(handle, mask, latch);
}
[DllImport("CP210xRuntime.dll")]
private static extern Int32 CP210xRT_ReadLatch(IntPtr handle, UInt16[] lpLatch);
public static Int32 ReadLatch(IntPtr handle, UInt16[] lpLatch)
{
return CP210xRT_ReadLatch(handle, lpLatch);
}
}
}
и функция в моем классе, вызывающая методы DLL:
private static void ResetTelit()
{
Int32 numOfDevices = 0;
Int32 retVal = CP210x.CP210x.GetNumDevices(ref numOfDevices);
IntPtr handle = IntPtr.Zero;
Byte[] prtNum = new Byte[1];
UInt16[] latch = new UInt16[8];
UInt16 mask = 0x01;
if (numOfDevices > 0)
{
retVal = CP210x.CP210x.Open(0, ref handle);
retVal = CP210x.CP210x.GetPartNumber(handle, prtNum);
if (prtNum[0] == 5)
{
retVal = CP210x.CP210x.ReadLatch(handle, latch);
for (Int32 idx = 0; idx < 16; idx++)
{
retVal = CP210x.CP210x.WriteLatch(handle, (UInt16)(mask << idx), 0x01);
}
}
retVal = CP210x.CP210x.Close(handle);
}
}
Я понимаю, что проблема может быть в оболочке DLL, но не могу понять.
См. раздел Типы данных Windows. В этом помогает оболочка DLL.
См. CP21xxCustomizationUtility. Он содержит библиотеки DLL.
Google «silicon labs an169», чтобы получить Руководство программиста USBXpress®.
Так вот вопрос что тут не так? Как переключать контакты GPIO?