Jump to content

saget

Members
  • Posts

    10
  • Joined

  • Last visited

Everything posted by saget

  1. 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
  2. Seems it have conflict with my self-update function, the .exe process did't exit after run(), the will be two same name exe process when add OnAutoItErrorRegister.... Func _Self_Update($newfile,$oldfile) Local $newfile_time=Number(FileGetTime($newfile,0,1)) Local $oldfile_time=Number(FileGetTime($oldfile,0,1)) Local $newfile_ver=FileGetVersion($newfile) Local $oldfile_ver=FileGetVersion($oldfile) Local $newfile_cp=FileGetShortName($newfile) Local $oldfile_cp=FileGetShortName($oldfile) If FileExists($newfile) And $newfile_time > $oldfile_time Then Local $if_update = MsgBox(1,"Auto-Update", StringReplace($exe_file_name,".exe","") & @CRLF & @CRLF & "New version available, please click OK to update!" & @CRLF & _ @CRLF & "Current version: " & @TAB & $oldfile_ver & _ @CRLF & "New version:" & @TAB & $newfile_ver ) If $if_update = 2 Then Return FileDelete(@TempDir & 'rst.bat') FileWrite(@TempDir & 'rst.bat', 'ping 127.0.0.1 >nul' & @CRLF _ & 'copy /y ' &$newfile_cp &' ' & $oldfile_cp & @CRLF _ & $oldfile_cp & @CRLF _ & 'echo by pcbar') Run(@TempDir & 'rst.bat', "", @SW_HIDE) Exit EndIf EndFunc
  3. wow, thanks for sharing, i have been using COMMGvv2 [by Martin Gibson] for years. And, the only bug for COMMMGvv2 is it seems not handling error package very well. i will try urs in my appliaction!~
  4. o my god! pretty cool!!!!
  5. same problem, hope autoit can support QT framework in future....
  6. y, _ComSendByte already works perfect~~ thanks again!
  7. It works!!!!!!!!! thanks so much, dear martin! It should be sent 1by1..?! - -!!! PS: This code is for USB switch turn ON/OFF external device power~~ XD
  8. cool !! powerfull man! powerfull autoit! thx
  9. Hi all, I am working on a project which requires serial communication. i got vb code works: ##################### Public Function tx_read_frame(data_type As Byte, data1 As Byte, data2 As Byte, data3 As Byte, data4 As Byte) Static Byteout(0 To 7) As Byte, i As Byte Dim sum As Integer Byteout(0) = &H55 Byteout(1) = 1 Byteout(2) = data_type Byteout(3) = data1 Byteout(4) = data2 Byteout(5) = data3 Byteout(6) = data4 sum = 0 For i = 0 To 6 Step 1 sum = sum + Byteout(i) Next Byteout(7) = sum Mod 256 main_form.MSComm1.InBufferCount = 0 main_form.MSComm1.Output = Byteout End Function ################## it didn't work when i try transfer to autoit... ################## Func _RX_READ_FRAME($type, $data1, $data2, $data3, $data4) Local $i, $sum, $Byteout_Array[8], $JXX_ARRAY[1] $Byteout_Array[0] = 0x55 $Byteout_Array[1] = Hex(1, 2) $Byteout_Array[2] = Hex($type, 2) $Byteout_Array[3] = Hex($data1, 2) $Byteout_Array[4] = Hex($data2, 2) $Byteout_Array[5] = Hex($data3, 2) $Byteout_Array[6] = Hex($data4, 2) $sum = 0 For $i = 0 To 6 Step 1 $sum = $sum + $Byteout_Array[$i] Next $Byteout_Array[7] = Mod($sum , 256) $Com_Object.Output = "0x55"&$Byteout_Array[1]&$Byteout_Array[2]&$Byteout_Array[3]&$Byteout_Array[4]&$Byteout_Array[5]&$Byteout_Array[6]&$Byteout_Array[7] EndFunc ################## any help...? thx a lot!
  10. printer UDF download link broken...??
×
×
  • Create New...