各位大哥大姐好:
USB接口函数原型: [DllImport("SiUSBXp.dll", EntryPoint = "SI_Write")]
public static extern int SI_Write
(UInt32 cyHandle,
ref Byte lpBuffer,
Int32 dwBytesToWrite,
ref Int32 lpdwBytesWritten,
Int32 lpOverlapped);public static uint hUSBDevice;
byte[] dataSent = new byte[] { (byte)0x80, (byte)0x04, (byte)0x01, (byte)0x00, (byte)0x00 };//我声明的数组;
int toBeWritten = 64;
int written = 0;
Status = SI_Write(hUSBDevice,ref dataSent, toBeWritten, ref written, 0);//我调用的;
如果通过返回值是SI_SUCCESS.
总是不对,提示byte无法转换成byte[]. 以前没做过 ,这个问题搞了几天不知道怎么搞的.哪为大侠知道帮下忙,拜托了,小弟感激不尽.
C#写的调用的是CP2102单片机接口函数.接口函数原形不能改的.
USB接口函数原型: [DllImport("SiUSBXp.dll", EntryPoint = "SI_Write")]
public static extern int SI_Write
(UInt32 cyHandle,
ref Byte lpBuffer,
Int32 dwBytesToWrite,
ref Int32 lpdwBytesWritten,
Int32 lpOverlapped);public static uint hUSBDevice;
byte[] dataSent = new byte[] { (byte)0x80, (byte)0x04, (byte)0x01, (byte)0x00, (byte)0x00 };//我声明的数组;
int toBeWritten = 64;
int written = 0;
Status = SI_Write(hUSBDevice,ref dataSent, toBeWritten, ref written, 0);//我调用的;
如果通过返回值是SI_SUCCESS.
总是不对,提示byte无法转换成byte[]. 以前没做过 ,这个问题搞了几天不知道怎么搞的.哪为大侠知道帮下忙,拜托了,小弟感激不尽.
C#写的调用的是CP2102单片机接口函数.接口函数原形不能改的.
public static extern int SI_Write
(UInt32 cyHandle,
byte[]lpBuffer,
Int32 dwBytesToWrite,
ref Int32 lpdwBytesWritten,
Int32 lpOverlapped);
就可以了2 或者 用IntPtr
你好:
SI_Write函数是可以写了
但是我想写一个SI_Read函数把写的字符数组读出来该怎么写呢?
函数原型是;
[DllImport("SiUSBXp.dll")]
public static extern int SI_Read
(UInt32 cyHandle,
ref Byte lpBuffer,
Int32 dwBytesToRead,
ref Int32 lpdwBytesReturned,
Int32 lpOverlapped);
byte[] dataRead = new byte[64];
int read = 0;
int toBeRead = 64;
我写的
Status = SI_Read(hUSBDevice,dataRead, toBeRead, ref read, 0);
我把 ref Byte lpBuffer改成byte[] lpbuffer了.怎么读不出来啊;
请教一下; 你要有类似的USB接口调用发来我看下,我用的是CP2102
我油箱是[email protected]
谢谢;
去掉显式转化
byte[] dataSent = new byte[] {0x80,0x04,0x01,0x00,0x00 };//我声明的数组;
看看
从你的错误提示来看,应该是你弄错了数据对应类型,在C里面的指针内存,常常是数组类型,而不是所谓的C#里面的引用。
SI_Read 函数也没出错, 但是程序运行就是返回不出来数据
还有别的什么原因吗? 和缓冲区和波特率有关系吗?
调用的USB接口函数中没有设置缓冲区和拨特率的接口函数. 该怎么做呢
一个问题困惑几天了,不知道哪里出错了. 有哪位做过类似的给点经验.大哥大姐帮帮忙 ,马上就揭贴了.
我做的是调用USB接口函数,SI_Write写入一个BYTE型字符串,在单片机计算后,在SI_Read 返回. 新手,实在是新手.
添加引用一下,然后就可以直接声明方法了,根据
dll里提供的参数来写就好了
public static extern int SI_Read
(UInt32 cyHandle,
Byte[] lpBuffer,
Int32 dwBytesToRead,
ref Int32 lpdwBytesReturned,
Int32 lpOverlapped); [DllImport("SiUSBXp.dll", EntryPoint = "SI_Write")]
public static extern int SI_Write
(UInt32 cyHandle,
Byte[] lpBuffer,
Int32 dwBytesToWrite,
ref Int32 lpdwBytesWritten,
Int32 lpOverlapped);
byte[] dataSent = new byte[] { 0x80, 0x04, 0x01,0xc2, 0xb0 };
byte[] dataRead = new byte[64];
int toBeWritten = 64, toBeRead = 64;
int written = 0;
int read = 0;
toBeWritten = 5;
Status =SI_Write(hUSBDevice, dataSent, toBeWritten, ref written, 0);
toBeRead=6;
Status =SI_Read(hUSBDevice, dataRead, toBeRead, ref read,0);
各位大哥大姐看下,上面的CP2102 DLL,下面是调用的,函数SI_Write(hUSBDevice, dataSent, toBeWritten, ref written, 0)没问题,就是SI_Read(hUSBDevice, dataRead, toBeRead, ref read,0)有问题,返回不到数据,如果成功返回的应该是SI_SUCCESS,程序在运行也没问题,就是接受不到返回值,这是为什么啊? 各位大侠看看: 马上揭贴了,朋友们帮忙啊
通讯速率是不是就是波特率啊/那该怎么设置呢? 以前用C++写的波特率是9600。现在要用C#写那个软件,但是哪个USB接口中对C#没提供设置波特率的函数啊。我该怎么设置通讯速率呢? 大家帮帮忙,迷惑几天了,应该就是关键一点没弄明白了。等待啊。
你这个USB接口是哪里的啊?