C# cp210xc中GPIO的控制#
我需要使用Silicon Labs提供的C# cp210xc中GPIO的控制#,c#,.net,dll,usb,gpio,C#,.net,Dll,Usb,Gpio,我需要使用Silicon Labs提供的CP210xManufacturing.dll和CP210xRuntime.dll控制CP210x设备的GPIO引脚。 我设法打开和关闭设备并获取零件号。(在我的例子中是CP2105) 我想我成功地读取了闩锁,但我不确定。 我还调用了写锁存函数,没有返回错误,也没有任何引脚切换 根据提供的实用程序(CP21xxCustomizationUtility.exe),它显示两个端口都处于GPIO模式 这是我的密码: 使用制度; 使用System.Runtime.
CP210xManufacturing.dll
和CP210xRuntime.dll
控制CP210x设备的GPIO引脚。
我设法打开和关闭设备并获取零件号。(在我的例子中是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);
}
}
private static void ResetTelit()
{
Int32 numOfDevices=0;
Int32 retVal=CP210x.CP210x.GetNumDevices(参考numOfDevices);
IntPtr handle=IntPtr.Zero;
字节[]prtNum=新字节[1];
UInt16[]闩锁=新UInt16[8];
UInt16掩码=0x01;
如果(numOfDevices>0)
{
retVal=CP210x.CP210x.Open(0,参考句柄);
retVal=CP210x.CP210x.GetPartNumber(句柄,prtNum);
if(prtNum[0]==5)
{
retVal=CP210x.CP210x.ReadLatch(手柄,闩锁);
对于(Int32 idx=0;idx<16;idx++)
{
retVal=CP210x.CP210x.writerach(句柄,(UInt16)(掩码问题的答案是代码很好。代码正常。问题在于IC。CP2103的代码正常,但CP2105的情况不太好。似乎CP2105的设置有所不同。您是否尝试过将掩码设置为0xFF并将锁存位CP210x.CP210x.WriteLatch(句柄,掩码,(UInt16)移位(0x01@PaulF我插入了CP2103,代码可以正常工作。不,我正在为CP2105实现typedefs等。切换CP2103的引脚可以正常工作。所以我猜问题已经得到了回答。问题不是代码。。。