Jump to content

Serial Port /COM Port UDF


martin
 Share

Recommended Posts

Any progress on the issue with high port numbers?

[font="Impact"]Use the helpfile, It´s one of the best exlusive features of Autoit.[/font]http://support.microsoft.com/kb/q555375ALIBI Run - a replacement for the windows run promptPC Controller - an application for controlling other PCs[size="1"]Science flies us to the moon. Religion flies us into buildings.[/size][size="1"]http://bit.ly/cAMPZV[/size]
Link to comment
Share on other sites

  • 4 weeks later...

I have been working with the Com udf for awhile but lateley trying to get the com port to go on a Bluetooth Port Com7 is inbound and Com8 is outbound. It just doesn't seem to connect to the port. If I connect it to lets say Com 6. It connects but nothing happens.

Help....

post-21222-12507227770507_thumb.jpg

Link to comment
Share on other sites

  • 2 weeks later...

I have been working with the Com udf for awhile but lateley trying to get the com port to go on a Bluetooth Port Com7 is inbound and Com8 is outbound. It just doesn't seem to connect to the port. If I connect it to lets say Com 6. It connects but nothing happens.

Help....

Sorry I missed your post until now. It seems strange that the port is listed as available but then you are told it doesn't exist. I don't have time to look at it now but I will try to find some time in the next two or three of days.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

  • 4 weeks later...

Martin,

Very Nice UDF !!

Just tried your example program and it works perfect, this is just what I was looking for.

Thanks.

[list][font="Century Gothic"]If nothing is certain, everything is possible.[/font][/list][font="Century Gothic"]Experience is something you get, just after you need it.[/font]

Link to comment
Share on other sites

  • 1 month later...

Hey, I used to use this UDF a while ago, but now I'm getting this error when I try to run your example script (CommMG.au3 and commg.dll are in the same directory)

>"C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Users\magician13134\Desktop\Com\CommgExample.au3" /autoit3dir "C:\Program Files (x86)\AutoIt3" /UserParams    
+>11:29:31 Starting AutoIt3Wrapper v.2.0.0.3    Environment(Language:0409  Keyboard:00000409  OS:WIN_VISTA/  CPU:X64 OS:X64)
>Running AU3Check (1.54.14.0)  from:C:\Program Files (x86)\AutoIt3
+>11:29:31 AU3Check ended.rc:0
>Running:(3.3.0.0):C:\Program Files (x86)\AutoIt3\autoit3_x64.exe "C:\Users\magician13134\Desktop\Com\CommgExample.au3"    
error in get version
C:\Users\magician13134\Desktop\Com\CommgExample.au3 (190) : ==> Subscript used with non-Array variable.:
For $pl = 1 To $portlist[0]
For $pl = 1 To $portlist^ ERROR
->11:29:31 AutoIT3.exe ended.rc:1
+>11:29:33 AutoIt3Wrapper Finished
>Exit code: 1    Time: 3.165

I'm using Windows 7, does this have anything to do with it?

Link to comment
Share on other sites

;//~ I changed " ;//~ " the example , because an error messagebox appears all time:

;Example program showing how to use some of the commMg3.au3 UDF functions

;this example is a very simple terminal

;Version 2 26th July 2006

;line 245:
        If $msg = $BtnApply Then
            Local $sportSetError
            $comboflowsel = GUICtrlRead($ComboFlow)
            For $n = 0 To 2
                If $comboflowsel = $flowtype[$n] Then
                    $setFlow = $n
                    ConsoleWrite("flow = " & $setflow & @CRLF)
                    ExitLoop
                EndIf

            Next
            $setport = StringReplace(GUICtrlRead($CmboPortsAvailable),'COM','')
            ;//~ my if 0 added ;//~ because if not 0 no error.
            if 0 = _CommSetPort($setPort,$sportSetError,GUICtrlRead($CmBoBaud),GUICtrlRead($CmboDataBits),GUICtrlRead($CmBoParity),GUICtrlRead($CmBoStop),$setFlow) Then        
                ;//~ fuc. _CommSetPort($iPort, ByRef $sErr,..)
                ;//~ on success - returns 1 and sets $sErr to ''
                ;//~ on failure - returns 0 and with the error message in $sErr, and sets @error as follows
                ;//~ my console write instead of messagebox
                ConsoleWrite('Setport error = ' & $sportSetError & @CRLF)
                ;//~ old MsgBox(0,'Setport error = ',$sportSetError)
            EndIf
            ;//~ /end my if 0 add
            $mode = 1;
            ExitLoop
        EndIf
        ;stop user switching back to $form2

;//~ greatings from berlin

;//~ andi

Link to comment
Share on other sites

;//~ I changed " ;//~ " the example , because an error messagebox appears all time:

;Example program showing how to use some of the commMg3.au3 UDF functions

;this example is a very simple terminal

;Version 2 26th July 2006

;line 245:
        If $msg = $BtnApply Then
            Local $sportSetError
            $comboflowsel = GUICtrlRead($ComboFlow)
            For $n = 0 To 2
                If $comboflowsel = $flowtype[$n] Then
                    $setFlow = $n
                    ConsoleWrite("flow = " & $setflow & @CRLF)
                    ExitLoop
                EndIf

            Next
            $setport = StringReplace(GUICtrlRead($CmboPortsAvailable),'COM','')
            ;//~ my if 0 added ;//~ because if not 0 no error.
            if 0 = _CommSetPort($setPort,$sportSetError,GUICtrlRead($CmBoBaud),GUICtrlRead($CmboDataBits),GUICtrlRead($CmBoParity),GUICtrlRead($CmBoStop),$setFlow) Then        
                ;//~ fuc. _CommSetPort($iPort, ByRef $sErr,..)
                ;//~ on success - returns 1 and sets $sErr to ''
                ;//~ on failure - returns 0 and with the error message in $sErr, and sets @error as follows
                ;//~ my console write instead of messagebox
         ConsoleWrite('Setport error = ' & $sportSetError & @CRLF)
         ;//~ old MsgBox(0,'Setport error = ',$sportSetError)
     EndIf
     ;//~ /end my if 0 add
            $mode = 1;
            ExitLoop
        EndIf
        ;stop user switching back to $form2

;//~ greatings from berlin

;//~ andi

Thanks for telling me, I'll look at it over the next couple of days.

It looks like the versions linked to and the example are all a bit of a mess at the moment and out of date so I need to sort it out.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Hi Martin

Great UDF ! Unfortunatedly only today I discovered your UDF, after more than 3 years using NETCommOCX...

I think it shoud be in the distributions UDF...

I didn't test yours yet, but reading the func definitions, they address all points I had to do "magics" in the past with NETCommOCX.

The timeouts, buffer max sizes, wait/notwait, byte/string management, it was done by a person that probably use serial ports a lot?

I can tell you it is realy great, as I use a lot serial ports to comunicate with PIC (microcontrolers) projects, sending/receiving bytes, hex, strings, mixed things, terminated and not terminated strings, etc., etc.

The second great point is the no need to install any dll, sometimes is a problem to be alowed to install NETCommOCX...

Maybe just one sugestion: the dll to be able to be in another folder, maybe an extra func call to set that place... if not called, all stays as today...

Thanks for this piece of code

Jose

Link to comment
Share on other sites

  • 2 weeks later...

thank you for your help,

i wish to use this udf to send visca control commands to a sony pan/tilt/zoom camera.

(http://networkvideocentre.com/downloads/others/CLEVID30E.pdf)

the visca command is in hex; (eg. 8101044700010F0FFF)

what is the best way to send this through the port to the camera using this udf?;

convert it to a series of bytes and send them one at a time? is this correct?

it is not clear to me exactly when, or how often i have to open and close the port for communication;

should i do this once in my program, or for each control message, or for every byte? which is the proper way to use this udf?

jonbell

Link to comment
Share on other sites

thank you for your help,

i wish to use this udf to send visca control commands to a sony pan/tilt/zoom camera.

(http://networkvideocentre.com/downloads/others/CLEVID30E.pdf)

the visca command is in hex; (eg. 8101044700010F0FFF)

what is the best way to send this through the port to the camera using this udf?;

convert it to a series of bytes and send them one at a time? is this correct?

it is not clear to me exactly when, or how often i have to open and close the port for communication;

should i do this once in my program, or for each control message, or for every byte? which is the proper way to use this udf?

jonbell

You only neede to open the port once in your script, then send data whenever you need to. Close the port when your script ends.

The easiest way to send the hex bytes is to use _CommSendByte and send one byte at a time. If you have a lot of hex data to send then _CommSendByteArray is better and much faster but it's a little more complicated to set up.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

i have been having the same problem as ghost21 when interfacing a bluetooth device over serial port through your UDF's use of your dll..

However, your dll works fine for comm when the same device is attached by cable connection.. would really like to see your dll work with bluetooth devices..

Link to comment
Share on other sites

i have been having the same problem as ghost21 when interfacing a bluetooth device over serial port through your UDF's use of your dll..

However, your dll works fine for comm when the same device is attached by cable connection.. would really like to see your dll work with bluetooth devices..

At the moment I don't know why there is a problem.

I've uploaded the latest version of the udf and the dll and it might be worth seeing if there is any difference though I wouldn't expect there to be.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

  • 4 weeks later...
  • 2 weeks later...

Thanks you Martin for this udf/dll. I use it to dial phones via Bluetooth. Was using netcomm before but I was worried about some serious issues like bsod when accessing non existent port. Your solution is a must !

By the way, anyone know a way to dial a phone via Bluetooth with a free hand set already connected (via BT too) ? It throw unknown error accessing port, I believe it's because the phone is already connected to the free hand set. Perhaps with COM and calling some BT dll directly ?

Link to comment
Share on other sites

@Martin

Just seen something strange with the dll (a bug / crash ?) :

When I try to dial to a BT com port while the BT manager app is not launched (but with BT device connected, so the dll see to com port), and trying to execute _CommSendString($DialString, 1) my app quit unexpectedly. If I execute _CommSendString($DialString, 0), It doesn't quit but instead continue with no error raised. Then if I execute my func a second time, this time I get an unknown error accessing port.

here my simple dial func :

Func _dial($pNum, $portNumber)

    $pNum = _cleanUpPhoneNumber($pNum, 1, 0)

    If $pNum = 0 Then
        MsgBox(262144+48, "Information", "Le numéro de téléphone est incorrect, impossible de composer")
        Return 0
    EndIf

    Local $sportSetError

    $DialString = "ATD" & $pNum & ";" & @CR

    _CommSetPort($portNumber, $sportSetError, 9600, 8, 0, 1, 0)

    If @error Then
        MsgBox(262144+16, "Erreur", "Impossible d'initialiser le port COM" & $portNumber")
        Return 0
    EndIf

    _CommPortConnection()

    If @error Then
        MsgBox(262144+16, "Impossible de connecter le port COM" & $portNumber, "Le port n'est pas connecté")
        return 0
    EndIf

    _CommSendString($DialString, 1)

    If @error Then
        MsgBox(262144+16, "Erreur", "Probléme lors de la composition du numero")
        Return 0
    EndIf

    Sleep(500);Attend un peu avant de fermer le port afin que la numerotation se fasse
    _CommClosePort()

    Return 1

EndFunc
Link to comment
Share on other sites

Thanks you Martin for this udf/dll. I use it to dial phones via Bluetooth. Was using netcomm before but I was worried about some serious issues like bsod when accessing non existent port. Your solution is a must !

Glad you found it useful.

I really aught to try it myself for something somewhen; so far all I've done is write it and respond to questions and problems then modify it, but I've never used it.;)

By the way, anyone know a way to dial a phone via Bluetooth with a free hand set already connected (via BT too) ? It throw unknown error accessing port, I believe it's because the phone is already connected to the free hand set. Perhaps with COM and calling some BT dll directly ?

No idea.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

@Martin

Just seen something strange with the dll (a bug / crash ?) :

When I try to dial to a BT com port while the BT manager app is not launched (but with BT device connected, so the dll see to com port), and trying to execute _CommSendString($DialString, 1) my app quit unexpectedly. If I execute _CommSendString($DialString, 0), It doesn't quit but instead continue with no error raised. Then if I execute my func a second time, this time I get an unknown error accessing port.

here my simple dial func :

Func _dial($pNum, $portNumber)

    $pNum = _cleanUpPhoneNumber($pNum, 1, 0)

    If $pNum = 0 Then
        MsgBox(262144+48, "Information", "Le numéro de téléphone est incorrect, impossible de composer")
        Return 0
    EndIf

    Local $sportSetError

    $DialString = "ATD" & $pNum & ";" & @CR

    _CommSetPort($portNumber, $sportSetError, 9600, 8, 0, 1, 0)

    If @error Then
        MsgBox(262144+16, "Erreur", "Impossible d'initialiser le port COM" & $portNumber")
        Return 0
    EndIf

    _CommPortConnection()

    If @error Then
        MsgBox(262144+16, "Impossible de connecter le port COM" & $portNumber, "Le port n'est pas connecté")
        return 0
    EndIf

    _CommSendString($DialString, 1)

    If @error Then
        MsgBox(262144+16, "Erreur", "Probléme lors de la composition du numero")
        Return 0
    EndIf

    Sleep(500);Attend un peu avant de fermer le port afin que la numerotation se fasse
    _CommClosePort()

    Return 1

EndFunc

It depends. When you run the BT manager app I assume that if you look in Device Manager you will see the COM port for the phone.

Is the port still there without th eBT manager app running? I assume it is.

What does _cleanUpPhoneNumber($pNum, 1, 0) do?

Can you add some lines Like ConsoleWrite("step 1" & @CR) so that you can tell how far the script gets in the function?

Or do you know that it's crashing on the line

_CommSendString($DialString, 1)

?

If so I'll send you a dll to try to get more information. (But not tonight as it's late for me and even later for you I think.)

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Yes when the device is connected the ports are present in device manager, even when the BT manager is not loaded. I believe that until they get initialized by the BT manager, they are not usable at all, even when I try to connect via a terminal app.

this one just assure the phone number to be dialed is valid, it remove some dot or space, check numbers count. They came from a DB filled by a third party.

Well, I already done some tests while activating the debug msg. It either hang at "pre sendstring" (and then I need to kill the task) or the app quit at same line when I execute _CommSetTimeouts() before _CommSendString()

If the BT manager is launched there is no problem at all, but I would trap this scenario in case my users didn't run their BT manager first.

No need to hurry, you've done already a lot !

Have a nice day

Link to comment
Share on other sites

Yes when the device is connected the ports are present in device manager, even when the BT manager is not loaded. I believe that until they get initialized by the BT manager, they are not usable at all, even when I try to connect via a terminal app.

If so then I don't have any hope that my udf will be able to do anything untill the BT manager is loaded. So maybe your best defense is to check that the BT manager process exists? (and maybe load it if needed.)

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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

×
×
  • Create New...