Jump to content

USB communication and exchange of informations


Recommended Posts

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

Link to comment
Share on other sites

:shifty: From your script: $var = DriveGetType( "C:\Windows\System32\driverslibusb0.sys" )

Were you able to get the Drive-type of a Driver?

Check the help file for DriveGetType() function.

Edited by MKISH

----------------------------------------

:bye: Hey there, was I helpful?

----------------------------------------

My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...