求大神指点CH375

箭神小傲 2013-07-05 10:06:31


[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");
}
}
}


}

这是网上的那段代码,为什么会在读的时候 死掉了呢?求指点
...全文
140 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
箭神小傲 2013-07-05
  • 打赏
  • 举报
回复
问题已经解决

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧