Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

USB communication and exchange of informations

$
0
0
hi,

I need help to create a autoit programm to communicate with a PLC connect by USB.
I found help to communicate with TCP ethernet comunication but it is different with USB.
Firstly i need to recognize the differents devices (and my PLC). I found an UDF to use COM port.
I did a little programm to recognize with the file : commg.dll

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>
#include-once
#include<CommMG.au3>
;*******************************************************************************************************************************************************************
Func quitter()
    $quitter = True
EndFunc
HotKeySet("^q","quitter")

$var = DriveGetType( "C:\Windows\system32\drivers\libusb0.sys" )
MsgBox(4096, "Drive Type:", $var)
$var2 = DriveGetDrive( "all" )
MsgBox(4096,"", "Found " & $var2[0] & " drives")
$GUI2 = GUICreate("Gui 2", 500, 100, 300, 200)
$Label2 = GUICtrlCreateLabel("Port", 94, 32, 23, 17)
$CmboPortsAvailable = GUICtrlCreateCombo("", 127, 28, 145, 25)
$portlist = _CommListPorts(0);find the available COM ports and write them into the ports combo
For $pl = 1 To $portlist[0]
    GUICtrlSetData($CmboPortsAvailable, $portlist[3]);_CommListPorts())
    Next
GUISetState(@SW_SHOW,$GUI2)
sleep(10000)


I used this function wich is in the include commMG.au3:

Global $fPortOpen = False
Global $hDll
Global $DLLNAME = 'commg.dll'

Func _CommListPorts($iReturnType = 1)
   Local $vDllAns, $lpres
    If Not $fPortOpen Then
ConsoleWrite($DLLNAME & @LF)
    $hDll = DllOpen($DLLNAME)
    If $hDll = -1 Then
  
  
  SetError(2)
    $sErr = 'Failed to open commg2_2.dll'
    Return 0;failed
    EndIf
    $fPortOpen = True
    EndIf
    If $fPortOpen Then
    $vDllAns = DllCall($hDll, 'str', 'ListPorts')
    If @error = 1 Then
    SetError(1)
    Return ''
  Else
    ;mgdebugCW($vDllAns[0] & @CRLF)
    If $iReturnType = 1 Then
    Return $vDllAns[0]
    Else
    Return StringSplit($vDllAns[0], '|')
    EndIf

    EndIf
    Else
    SetError(1)
    Return ''
    EndIf

Viewing all articles
Browse latest Browse all 12506

Trending Articles