Hi All,
i'm using base autoit for 1 years but never touch dllcall..
Recently, i just got a cheam I2C USB adapter (made in china), and want read/wirte the device by autoit code, doese anyone get time to take a look at...? OR, is there any i2c UDF...?
The .net code
public partial class Form1 : Form
{
[DllImport("USBIOX")]
extern static int USBIO_OpenDevice(int iIndex);
[DllImport("USBIOX.dll")]
public static extern bool USBIO_StreamI2C(int iIndex,int iWriteLength,byte[] iWriteBuffer,int iReadLength,byte[] oReadBuffer);
private void btnI2CRun_Click(object sender, EventArgs e)
{
bool mOpen=false;
int mIndex=0;
int hopen = USBIO_OpenDevice(0);
if (hopen == INVALID_HANDLE_VALUE)
mOpen = false;
else
mOpen = true;
if (USBIO_SetStream(mIndex, 0x81) == false)
{
MessageBox.Show("I2c clock set fail = 100KHz fail!");
return;
}
else
{
int mWRLen=2, mRdLen=3;
byte[] iBuff = new byte[3], buffer = new byte[2];
buffer[0] = 0x92;
buffer[1] = 0x31;
if (mOpen)
{
if (USBIO_StreamI2C(mIndex, mWRLen, buffer, mRdLen, iBuff) == false)
MessageBox.Show( "I2C stream read/write failīš");
else
{
if (mRdLen > 0) //get returned data
{
string buff=string.Empty;
int i;
for (i = 0; i < mRdLen; i++)
buff += iBuff[i].ToString() + ",";
}
}
}
}
}
Also, i found the full vb code from vendor, the point is how can i import the dll function in autit just like VB does?
e,g.
Declare Function USBIO_OpenDevice Lib "USBIOX.DLL" (ByVal iIndex As Long) As Long
Declare Sub USBIO_CloseDevice Lib "USBIOX.DLL" (ByVal iIndex As Long)
Declare Function USBIO_StreamI2C Lib "USBIOX.DLL" (ByVal iIndex As Long, ByVal iWriteLength As Long, ByRef iWriteBuffer As Any, ByVal iReadLength As Long, ByRef oReadBuffer As Any) As Boolean
USB2I2C_DEMO_VBEN.zip