求大神指点CH375

箭神小傲 箭神小傲 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区


[DllImport("CH375DLL.dll")]
static extern IntPtr CH375OpenDevice(int i);//初始化

[DllImport("CH375DLL.dll", EntryPoint = "CH375ResetDevice")]
static extern bool CH375ResetDevice(ulong iIndex );//复位USB设备

[DllImport("CH375DLL.DLL", EntryPoint = "CH375ReadData", ExactSpelling = false, SetLastError = true)]
public static extern bool CH375ReadData(Int16 iIndex, [MarshalAs(UnmanagedType.LPArray)] byte[] oBuffer, [MarshalAs(UnmanagedType.LPArray)] Int32[] ioLength);//读单片机缓存

[DllImport("CH375DLL.DLL", EntryPoint = "CH375WriteData", ExactSpelling = false, SetLastError = true)]
public static extern bool CH375WriteData(Int16 iIndex, [MarshalAs(UnmanagedType.LPArray)] byte[] iBuffer, [MarshalAs(UnmanagedType.LPArray)] Int32[] ioLength); //写单片机缓存

[DllImport("CH375DLL.dll", EntryPoint = "CH375CloseDevice")]
static extern void CH375CloseDevice( // 关闭CH375设备
ulong iIndex);


private void button1_Click(object sender, EventArgs e)
{
CH375OpenDevice(0);//初始化(0为设备号)
byte[] str = new byte[20]; //用于开设单片机缓冲区
Int32[] len = new Int32[1];//读写长度
len[0] = 20;



str[0] = 6;str[1] = 4;str[2] = 1;//缓冲区写入值641
if (CH375WriteData(0, str, len))//写入单片机缓存
{
//读取刚才写入的数据
if (CH375ReadData(0, str, len))
{
string s = str[0].ToString();
string s2 = str[1].ToString();
string s3 = str[2].ToString();
if (s == "6" && s2 == "4" && s3 == "1")
{
MessageBox.Show("OK");
}
else
{
MessageBox.Show("ERROR");
}
}
}


}

这是网上的那段代码,为什么会在读的时候 死掉了呢?求指点
...全文

相关推荐

评论 1
收藏 已收藏
分享
返回顶部
箭神小傲
C# 111,129 成员 642,539 内容