求救大神,你们怎么做的??
我在VB.NET下编写读取I2C设备的程序,发现CH341StreamI2C函数不能用,
CH341StreamI2C函数内的缓存的类型,设置结构体/数组/Object都不行,读不到函数/报错
VB下代码如下
Type arrRBuffer
buf(mMAX_BUFFER_LENGTH - 1) As Byte
End Type
Dim iBuff As arrRBuffer
Dim buffer As arrRBuffer
If (CH341StreamI2C(mIndex, mWrLen, buffer, mRdLen, iBuff) = False) Then
MsgBox "流模式读写数据失败!", vbExclamation, "CH341"
函数
Declare Function CH341StreamI2C Lib "CH341DLL.DLL" (ByVal iIndex As Long, ByVal iWriteLength As Long, ByRef iWriteBuffer As Any, ByVal iReadLength As Long, ByRef oReadBuffer As Any) As Boolean
' CH341StreamI2C 处理I2C数据流,2线接口,时钟线为SCL引脚,数据线为SDA引脚(准双向I/O),速度约56K字节
' iIndex, 指定CH341设备序号
' iWriteLength, 准备写出的数据字节数
' iWriteBuffer, 指向一个缓冲区,放置准备写出的数据,首字节通常是I2C设备地址及读写方向位
' iReadLength, 准备读取的数据字节数
' oReadBuffer 指向一个缓冲区,返回后是读入的数据
仿照VB写VB.NET如下
Public Structure arrRBuffer
Public buf() As Byte
End Structure
Dim iBuff As arrRBuffer
Dim buffer As arrRBuffer
CH341StreamI2C(0, 1, buffer, 2, iBuff)
函数
_
Public Function CH341StreamI2C(ByVal iIndex As Integer, ByVal iWriteLength As Integer, ByRef iWriteBuffer As arrRBuffer, ByVal iReadLength As Integer, ByRef oReadBuffer As arrRBuffer) As Boolean
' CH341StreamI2C 处理I2C数据流,2线接口,时钟线为SCL引脚,数据线为SDA引脚(准双向I/O),速度约56K字节
' iIndex, 指定CH341设备序号
' iWriteLength, 准备写出的数据字节数
' iWriteBuffer, 指向一个缓冲区,放置准备写出的数据,首字节通常是I2C设备地址及读写方向位
' iReadLength, 准备读取的数据字节数
' oReadBuffer 指向一个缓冲区,返回后是读入的数据
End Function