Jump to content

Recommended Posts

Posted

Crashing problem solved... sort of...

I reported on random crashes using the com udf, back around page 14 of this thread. To recap, I was getting random crashes using the udf, on various combinations of three different computers and four different usb-serial adapters. It would also crash if the usb cable was unplugged.

Last week I found an old ethernet-serial adapter (on ethernet cable in, four serial ports out). I stuck that in in place of the usb adapter, and to date, no crashes. Life is good! :unsure:

Posted

Thanks again for your help. Your suggestione and code worked. Also you were correct about the difference between Hyperterminal's handling of data vs. mine. Thanks again....

Posted

Martin,

I've completed a couple projects using your CommMg file. I do have a question for clarification, though. I'm attempting to monitor two COM ports at once, simultaneously. I thought that's what the _CommSwitch() function was designed for, but I'm obviously missing something (simple), as right after the Main GUI comes up and the first data line comes in-- it completely crashes. Please take a look, and then school me in the workings of it-- and what I FAILED to script.

#cs======================================================================================
AutoIT3 v1.6.7
Script: Dual Com Port Monitor
Purpose: Primarily for capturing AT commands and responses from 263G, 463G, and Cellcom
Author:  Derek M. Norvell
#ce======================================================================================
#include<CommMg.au3>
#include <EditConstants.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiEdit.au3>

Opt("GUIOnEventMode", 1)
FileInstall("C:\CommMg\commg.dll",@TempDir & "\commg.dll",1)
_CommSetDLLPath(@TempDir & "\commg.dll")

;Global $sMaxLines, $setport1, $setport2

$setflow = 2;default to no flow control
Dim $FlowType[3] = ["XOnXoff", "Hardware (RTS, CTS)", "NONE"]
;======###  Part 2: Com Port Monitor  ###======================================================
#Region ### START Koda GUI section ### Form=C:\Documents and Settings\jzeller\Desktop\PortMonitor.kxf
$Form2 = GUICreate("COM Port Monitor", 633, 466, 190, 121)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form2Close")
$Edit1 = GUICtrlCreateEdit("", 8, 56, 289, 401, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_READONLY,$ES_WANTRETURN,$WS_HSCROLL,$WS_VSCROLL))
GUICtrlSetData(-1, "")
GUICtrlSetFont(-1, 10, 400, 0, "Courier")
$Edit2 = GUICtrlCreateEdit("", 320, 56, 305, 401, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_READONLY,$ES_WANTRETURN,$WS_HSCROLL,$WS_VSCROLL))
GUICtrlSetData(-1, "")
GUICtrlSetFont(-1, 10, 400, 0, "Courier")
GUISetState(@SW_HIDE)
#EndRegion ### END Koda GUI section: Part 2: Com Port Monitor   ###
;======###  End Part 2: Com Port Monitor  ###======================================================
;======###  Part 1, COM port Setup  ###===================================================
#Region ### START Koda GUI section:  Part 1, COM port Setup### Form=
$Form1 = GUICreate("COM Port Setup", 322, 449, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$Group1 = GUICtrlCreateGroup("Com Port A Setup", 8, 8, 305, 193)
$CmboPortsAvailable1 = GUICtrlCreateCombo("", 16, 56, 105, 25)
$CmBoBaud1 = GUICtrlCreateCombo("9600", 16, 112, 105, 25)
GUICtrlSetData(-1, "1200|4800|9600|19200|38400")
$CmBoStop1 = GUICtrlCreateCombo("1", 160, 56, 105, 25)
GUICtrlSetData(-1, "1|1.5|2")
$CmBoParity1 = GUICtrlCreateCombo("None", 160, 112, 105, 25)
GUICtrlSetData(-1, "None|Odd|Even")
$Label1 = GUICtrlCreateLabel("Set COM Port", 16, 32, 109, 17)
$Label2 = GUICtrlCreateLabel("Set BAUD Rate", 16, 88, 103, 17)
$Label3 = GUICtrlCreateLabel("Set Stop Bit(s)", 160, 32, 103, 17)
$Label4 = GUICtrlCreateLabel("Set Parity", 160, 88, 105, 17)
$ComboFlow1 = GUICtrlCreateCombo("None", 16, 168, 105, 25)
GUICtrlSetData(-1, "None|X On/X Off|Hardware (RTS, CTS)")
$Label5 = GUICtrlCreateLabel("Set Flow Control", 16, 144, 105, 17)
$Label11 = GUICtrlCreateLabel("Data Bits", 160, 144, 47, 17)
$CmboDataBits1 = GUICtrlCreateCombo("8", 160, 168, 105, 25)
GUICtrlSetData(-1, "7|8")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Com Port B Setup", 8, 208, 305, 193)
$Label6 = GUICtrlCreateLabel("Set COM Port", 16, 232, 69, 17)
$CmboPortsAvailable2 = GUICtrlCreateCombo("", 16, 256, 105, 25)
$Label7 = GUICtrlCreateLabel("Set BAUD Rate", 16, 288, 79, 17)
$CmBoBaud2 = GUICtrlCreateCombo("9600", 16, 312, 105, 25)
GUICtrlSetData(-1, "1200|4800|9600|19200|38400")
$Label8 = GUICtrlCreateLabel("Set Stop Bit(s)", 168, 232, 71, 17)
$CmBoStop2 = GUICtrlCreateCombo("1", 160, 256, 113, 25)
GUICtrlSetData(-1, "1|1.5|2")
$Label9 = GUICtrlCreateLabel("Set Parity", 160, 288, 49, 17)
$CmBoParity2 = GUICtrlCreateCombo("None", 160, 312, 121, 25)
GUICtrlSetData(-1, "None|Odd|Even")
$Label10 = GUICtrlCreateLabel("Set Flow Control", 16, 344, 81, 17)
$ComboFlow2 = GUICtrlCreateCombo("None", 16, 368, 105, 25)
GUICtrlSetData(-1, "None|X On/X Off|Hardware (RTS, CTS)")
$Label12 = GUICtrlCreateLabel("Data Bits", 160, 344, 47, 17)
$CmboDataBits2 = GUICtrlCreateCombo("8", 160, 368, 113, 25)
GUICtrlSetData(-1, "7|8")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("OK", 96, 408, 97, 33, $WS_GROUP)
GUICtrlSetOnEvent(-1, "Button1Click")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section:  Part 1, COM port Setup ###=====

    $portlist = _CommListPorts(0);find the available COM ports and write them into the ports combo
    If @error = 1 Then
        MsgBox(0, 'trouble getting portlist', 'Program will terminate!')
        Exit
    EndIf

    For $pl = 1 To $portlist[0]
        GUICtrlSetData($CmboPortsAvailable1, $portlist[$pl]);_CommListPorts())
        GUICtrlSetData($CmboPortsAvailable2, $portlist[$pl]);_CommListPorts())
    Next
    GUICtrlSetData($CmboPortsAvailable1, $portlist[1]);show the first port found
    GUICtrlSetData($CmboPortsAvailable2, $portlist[1]);show the first port found
    GUICtrlSetData($ComboFlow1, $FlowType[$setflow])
    GUICtrlSetData($ComboFlow2, $FlowType[$setflow])
    $retval = 0

    While 1
        $msg = GUIGetMsg()
        If $msg = $Button1 Then

            $comboflowsel = GUICtrlRead($ComboFlow1)
            $comboflowse2 = GUICtrlRead($ComboFlow2)
            For $n = 0 To 2
                If $comboflowsel = $FlowType[$n] Then
                    $setflow = $n
                    ConsoleWrite("flow = " & $setflow & @CRLF)
                    ExitLoop
                    EndIf
            Next
            For $m = 0 To 2
                If $comboflowse2 = $FlowType[$n] Then
                    $setflow = $m
                    ConsoleWrite("flow = " & $setflow & @CRLF)
                    ExitLoop
                EndIf

            Next
        EndIf

    WEnd
;======###  End Part 1: Com Port Setup  ###====================================================
;======### Script Functions  ###===============================================================
Func Button1Click()
    If GUICtrlRead($CmboPortsAvailable1) = GUICtrlRead($CmboPortsAvailable2) Then
    MsgBox(16,"COM Port Error:  ", "COM Ports cannot be the same")
    Return
    EndIf
    GUISetState(@SW_HIDE, $Form1)
    Local $sportSetError1, $sportSetError2
     $setport1 = StringReplace(GUICtrlRead($CmboPortsAvailable1), 'COM', '')
            _CommSetPort($setport1, $sportSetError1, GUICtrlRead($CmBoBaud1), GUICtrlRead($CmboDataBits1), GUICtrlRead($CmBoParity1), GUICtrlRead($CmBoStop1), $setflow)
            If $sportSetError1 = '' Then
                MsgBox(262144, 'Connected ','to COM' & $setport1)
            Else
                MsgBox(262144, 'Setport error = ', $sportSetError1)
            EndIf
            $mode = 1;
            $setport2 = StringReplace(GUICtrlRead($CmboPortsAvailable2), 'COM', '')
            _CommSetPort($setport2, $sportSetError2, GUICtrlRead($CmBoBaud2), GUICtrlRead($CmboDataBits2), GUICtrlRead($CmBoParity2), GUICtrlRead($CmBoStop2), $setflow)
           If $sportSetError2 = '' Then
                MsgBox(262144, 'Connected ','to COM' & $setport2)
            Else
                MsgBox(262144, 'Setport error = ', $sportSetError2)
            EndIf
            $mode = 1;

    GUISetState(@SW_SHOW, $Form2)
        $TimeStamp = @HOUR & ":" & @MIN & ":" & @SEC & ":" & @MSEC & ":    "
        While 1
            _CommSwitch(1)
            RemoveFirstLine($Edit1,40)
            $instr = _CommGetLine(@CR,1000,40)
            If $instr <> '' Then
            GUICtrlSetData($Edit1, $TimeStamp & $instr & @CRLF)
            EndIf
            _CommSwitch(2)
            RemoveFirstLine($Edit2,40)
            If $instr <> '' Then
            $instr = _CommGetLine(@CR,1000,40)
            GUICtrlSetData($Edit2, $TimeStamp & $instr & @CRLF)
            EndIf
            #cs

                $instr = StringReplace($instr,@CR,@CRLF)
                _GUICtrlEdit_AppendText($Edit1, $TimeStamp & $instr)
                EndIf


                If $instr <> '' Then
                $instr = StringReplace($instr,@CR,@CRLF)
                _GUICtrlEdit_AppendText($Edit2, $TimeStamp & $instr)
                EndIf
                #ce
        WEnd
    EndFunc

Func RemoveFirstLine($editctrl,$sMaxLines)
    ; get number of lines:
    $numOfLines = _GUICtrlEdit_GetLineCount($editctrl)
        If $numOfLines > $sMaxLines Then
        ;see if that number is greater than our $sMaxLines we want
            $newtext = ""
            ; variable that will hold the new text.
            For $i = 1 To $sMaxLines Step 1
                ; start at 1, because we are getting rid of the first line.
                $tmp = $newtext
                ;temp variable
                If $i < $sMaxLines Then
                    $newtext = $tmp & _GUICtrlEdit_GetLine($editctrl, $i) & @CRLF
                Else
                    $newtext = $tmp & _GUICtrlEdit_GetLine($editctrl, $i)
                EndIf
            Next
            _GUICtrlEdit_SetText($editctrl, "")
            ; clear the edit control of text.
            _GUICtrlEdit_SetText($editctrl, $newtext)
            ; set the edit control text with new text.
        EndIf
EndFunc

Func Form1Close()
    Exit
EndFunc
Func Form2Close()
    Exit
EndFunc

It's not 100% complete, but it says it's connected to the com port, and appears to get data (once). Thanks in advance for your help!

Posted

OK I think I'm on to something...

I think my error is in the applying of the settings from setup to the Monitor window itself. What I'm finding is-- If I only have one of the ports actually connected to my data source, the data only displays in the edit window when it's setup as the second comport. Whatever is in the first com port setup doesn't display anything, as if its configuring it for the first com, and then immediately overwriting that with the second com's settings. Here's the section of code I'm referring to:

;====## Configure Port Settings per $Form1 ##===========================================
    Local $sportSetError1, $sportSetError2
    
    $setport1 = StringReplace(GUICtrlRead($CmboPortsAvailable1), 'COM', '')
        _CommSetPort($setport1, $sportSetError1, GUICtrlRead($CmBoBaud1), GUICtrlRead($CmboDataBits1), GUICtrlRead($CmBoParity1), GUICtrlRead($CmBoStop1), $setflow)
            If $sportSetError1 = '' Then
                MsgBox(262144, 'Connected ','to COM' & $setport1)
            Else
                MsgBox(262144, 'Setport error = ', $sportSetError1)
            EndIf
            $mode = 1;
    $setport2 = StringReplace(GUICtrlRead($CmboPortsAvailable2), 'COM', '')
        _CommSetPort($setport2, $sportSetError2, GUICtrlRead($CmBoBaud2), GUICtrlRead($CmboDataBits2), GUICtrlRead($CmBoParity2), GUICtrlRead($CmBoStop2), $setflow)
            If $sportSetError2 = '' Then
                MsgBox(262144, 'Connected ','to COM' & $setport2)
            Else
                MsgBox(262144, 'Setport error = ', $sportSetError2)
            EndIf
            $mode = 2;
        ;====## End Configure Port Settings ##=====================================================

GUISetState(@SW_SHOW, $Form2)
        $TimeStamp = @HOUR & ":" & @MIN & ":" & @SEC & ":" & @MSEC & ":    "
        While 1
            _CommSwitch(2)
            $instr = _CommGetLine()
            ;RemoveFirstLine($Edit1,$sMaxLines)
            $TimeStamp = @HOUR & ":" & @MIN & ":" & @SEC & ":    "
            If $instr <> '' Then
                $instr = StringReplace($instr,@CR,@CRLF)
                _GUICtrlEdit_AppendText($Edit2, $TimeStamp & $instr)
            EndIf
            _CommSwitch(1)
            $instr = _CommGetLine()
            RemoveFirstLine($Edit1,$sMaxLines)
            $TimeStamp = @HOUR & ":" & @MIN & ":" & @SEC & ":    "
            If $instr <> '' Then
                $instr = StringReplace($instr,@CR,@CRLF)
                _GUICtrlEdit_AppendText($Edit1, $TimeStamp & $instr)
            EndIf


        WEnd
    EndFunc
Posted

Martin,

I find your CommMg to be quite useful, but (obviously) I need some assistance.

For my first project using your stuff, I simply modified the example to fit my purposes. I would like to limit the total number of lines visible in the edit box by clearing the the oldest data (first line) while still adding the newest data to the bottom of the edit box. Is there a 'good' way to accomplish this?

Thanks

N0RVLL

We got it working! Here's what we did:
Func RemoveFirstLine($editctrl, $sMaxLines)
    ; get number of lines:
    $numOfLines = _GUICtrlEdit_GetLineCount($editctrl)
        If $numOfLines > $sMaxLines Then
            ; see if that number is greater than our $sMaxLines we want
                $newtext = ""
                ; variable that will hold the new text.
            For $i = 1 To $sMaxLines Step 1
                ; start at 1, because we are getting rid of the first line.
                $tmp = $newtext
                ;temp variable
                If $i < $sMaxLines Then
                    $newtext = $tmp & _GUICtrlEdit_GetLine($editctrl, $i) & @CRLF
                Else
                    $newtext = $tmp & _GUICtrlEdit_GetLine($editctrl, $i)
                EndIf

            Next
            _GUICtrlEdit_SetText($editctrl, "")
            ; clear the edit control of text.
            _GUICtrlEdit_SetText($editctrl, $newtext)
            ; set the edit control text with new text.
        EndIf
EndFunc

A good buddy of mine (one of the ones who got me started with AutoIT) figured it out-- it took a few tries for each of us, as what "should have" worked didn't work like we wanted it to.

Posted

NORVLL,

The main problem you still have is to do with using more than one COM port, so I will explain that. But first I notice that you are using OnEvent mode and so the main while loop should be replaced with

While 1
   sleep(100)
wend

because in OnEVent mode GuiGetMsg only ever returns 0.

The way to use more than one COM port with my UDF is a little strange because when I first wrote the udf and dll I didn't think about using multiple ports. In fact I only wrote it to see if could actually make a dll which worked and I've been stuck with the consequences. However, once you understand how to deal with more than one port it isn't so hard and if it seems a bit cumbersome then it is easy to write a wrapper function to make it all more ob vious. I will give an example later.

First you need to understand the way multiple serial ports are dealt with

WIth the udf there are 50 channels. 50 is simply a number I considered would be enough and no-one has complained so far, not that it would probably make any difference; anyone who wants to deal with more than 50 ports at a time is obviously mad and can be ignored.

The channels are numbered 1 to 50. The channel number is independent of the COM port number, but for convenience you could make it the same.

You select channels using CommSwitch($channelNumber). Read the comments in the udf. When the dll starts channel 1 is always selected until you change it.

All the commands in the udf, apart from CommSwitch, are directed to the currently selected channel. So if you only use one COM port you can use the udf without using CommSwitch or knowing anything about it.

If you need 2 com ports, say 8 and 11 this is an example of how you do it (pseudo code)

CommSetport (8,... ; now channel 1 is using COM8 because channel 1 is selected by default

CommGetString(... ;it will read from COM8

ComSwitch(2) ; we select channel2. Initially it is not assiciated with any com port so anything apart from CommSetPort will fail!

CommSetPort(11,.... ; now channel 2 is using COM11

CommGetString(... ; read a string from COM11

CommSwitch(1.. ; select channel1, ie COM8

CommGetString(... ; read from COM8 again.

To keep the channel numbers and port numbers the same (assuming you don't go above COM50) you could instead do this

CommSwitch(8)

CommSetport (8,... ; now channel 8 is using COM8

CommGetString(... ;it will read from COM8

ComSwitch(11) ; we select channel 11. Initially it is not assiciated with any com port so anything apart from CommSetPort will fail!

CommSetPort(11).... ; now channel 11 is using COM11

CommGetString(... ; read a string from COM11

CommSwitch(8).. ; select channel8, ie COM8

CommGetString(... ; read from COM8 again.

If the CommSwitch seems a bit of a pain then you could hide it by writing functions which allow you to pass the Com port number, eg

Func CommGetSTringEx($iPort, $par1, $par2, ...
    If CommSwitch($iPort) = $iPort Then; if switched ok
        Return CommGetString($par1, $par2, ...
    Else
        Return SetError(-21, 0, '')
    EndIf
EndFunc   ;==>CommGetSTringEx

Which of course I could have done in my udf but Mr Procrastination has prevented me against my will.

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.
Posted

can you post the working code? This'll be a big help to me for a script I need!!

thanks!

Working code for what? Whatever it is, it's very unlikely. That's like asking someone who makes bricks to supply you with a house.

There is, or should be, an example script with the download and there is information on each function in the udf.

If you need to use more than one COM port and you don't understand my explanation of how the channels work, then you need to tell me what part you don't understand so that I can try to make a better job of the explanation.

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.
Posted

I was referring to NORVLL's script

furthermore I'm getting a portlist error on every example script on here. is there a problem with the udf? I just downloaded the newest version

I'm trying to make a script that retrieves all active COM Ports and their names and put em in a text file.

Posted

I was referring to NORVLL's script

furthermore I'm getting a portlist error on every example script on here. is there a problem with the udf? I just downloaded the newest version

I'm trying to make a script that retrieves all active COM Ports and their names and put em in a text file.

I've obviously not seen your script; but I've got money that says your script doesn't know where the commg.dll file is... kinda important, that is.

  • 3 weeks later...
Posted

I must only switch between 115200 and 300 baud and vice versa!

Must I closecomport before and then open again or .... ?

You can use _CommSetPort to change any settings but I would make sure the buffers are empty first.

_CommClosePort closes all ports and closes the dll so if you are using more than one port it is to be avoided.

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.
Posted (edited)

You can use _CommSetPort to change any settings but I would make sure the buffers are empty first.

_CommClosePort closes all ports and closes the dll so if you are using more than one port it is to be avoided.

I use only one com port and switch between 115200/300 baud.

p.s.I work with high speed/low speed quartz (12MHz/cc36kHz) on silabs c8051F330 micro! And switch betwen baud rates on the fly!

Before I use _CommClosePort and then _CommSetPort again but autoit exe application crashes down! Now I use only CommSetPort and it working ok!

p.s.2

why application crash if I ClosePort and then SetPort again?

Edited by microera
Posted (edited)

I use only one com port and switch between 115200/300 baud.

p.s.I work with high speed/low speed quartz (12MHz/cc36kHz) on silabs c8051F330 micro! And switch betwen baud rates on the fly!

Before I use _CommClosePort and then _CommSetPort again but autoit exe application crashes down! Now I use only CommSetPort and it working ok!

Good :huh2:

p.s.2

why application crash if I ClosePort and then SetPort again?

I don't know.

If you use _CommClosePort it closes the dll but then when you use _CommSetPort it will open the dll again if needed.

The functions GetVersion and ListPorts also open the dll again if needed.

All other functions return with @error set to 1 if the dll is not open so I don't know why your script crashes, but maybe you are not checking @erro or you are using an old verion of the udf. Otherwise please give me more information, or a working example, and I will try to uderstand the problem.

Edited by martin
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.
Posted

Hi Martin,

Well... my little gui that uses your Commg UDF's is working fabulously. There is only one problem remaining for me to figure out: the script crashes if I unplug the USB cable while running in a tight loop. When not in a tight loop the script checks the comm port before any accesses happen and go to an error handler function. When in a tight loop even though I always check to comm port the script still crashes. I've done some research and found that there is a problem in Microsoft's .net comm port libraries that cause an exception under certain circumstances - like when the USB cable is suddenly unplugged. But I'm not a software engineer and don't have time to become one to debug this.

The error code in AutoIt's console is: !>10:48:13 AutoIT3.exe ended.rc:255

So.... I'm wondering if you've heard from any other folks about this issue since the last thread? Also wondering if you or someone you know would be interested indoing some paid consulting on my project? I'd like to have someone take ownership of this project long term for debugging, future feature enhancements, and customer support. I'd prefer to have an expert familiar with AutoIt, and a big plus would be someone familiar with RFID but that's not required.

Cheers,

Doug

Posted

Hi Martin,

Well... my little gui that uses your Commg UDF's is working fabulously. There is only one problem remaining for me to figure out: the script crashes if I unplug the USB cable while running in a tight loop. When not in a tight loop the script checks the comm port before any accesses happen and go to an error handler function. When in a tight loop even though I always check to comm port the script still crashes. I've done some research and found that there is a problem in Microsoft's .net comm port libraries that cause an exception under certain circumstances - like when the USB cable is suddenly unplugged. But I'm not a software engineer and don't have time to become one to debug this.

The error code in AutoIt's console is: !>10:48:13 AutoIT3.exe ended.rc:255

So.... I'm wondering if you've heard from any other folks about this issue since the last thread? Also wondering if you or someone you know would be interested indoing some paid consulting on my project? I'd like to have someone take ownership of this project long term for debugging, future feature enhancements, and customer support. I'd prefer to have an expert familiar with AutoIt, and a big plus would be someone familiar with RFID but that's not required.

Cheers,

Doug

Hi Doug,

My view so far has been that it's a problem which affects few people, and if you pull the usb lead out of a PC which is using the device then it shouldn't be a surprise that something goes wrong. I could deal with the situation better perhaps, and I admit that the error shouldn't cause AutoIt to crash.

So at the moment you have to stop your program or prepare it in some way to close the port before you unplug the usb cable.

In case it could be of help to you have a look at post #361.

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.
Posted

Hi Doug,

My view so far has been that it's a problem which affects few people, and if you pull the usb lead out of a PC which is using the device then it shouldn't be a surprise that something goes wrong. I could deal with the situation better perhaps, and I admit that the error shouldn't cause AutoIt to crash.

So at the moment you have to stop your program or prepare it in some way to close the port before you unplug the usb cable.

In case it could be of help to you have a look at post #361.

Hi Martin,

I agree this is not a problem with your Commg UDF's. This is a Microsoft issue that has been present since W98 and is still not fixed in W7. Something to do with the virtual comm port stack not notifying that the USB connection has been unplugged. Anyway, I'm going to try to find a workaround to this and will post here if I'm able to find one. It's funny, the Microsoft support post on this basically says "yes, it's a bug and we're not going to fix it, so don't unplug the USB device while your program is running.."

Thanks,

Doug

  • 2 weeks later...
Posted

Martin,

I have fixed a few minor annoyances in your sample comm app. Works great as a basic terminal app. Thank you very much for the work on this. From reading all of the other posts it appears that the dll will now support non-standard baud rates. Is that correct? Is there any maximum baud rate that will work? I have an device that I am trying to control at 1M (The device supports up to 2Mbps). It is a USB serial interface to a car network. I have modified your sample app and it works reliably at 115,200bps, and your sample app only goes to 256kbs.

Thank you,

Mark Cheavens

Posted

Martin,

I have fixed a few minor annoyances in your sample comm app. Works great as a basic terminal app. Thank you very much for the work on this. From reading all of the other posts it appears that the dll will now support non-standard baud rates. Is that correct? Is there any maximum baud rate that will work? I have an device that I am trying to control at 1M (The device supports up to 2Mbps). It is a USB serial interface to a car network. I have modified your sample app and it works reliably at 115,200bps, and your sample app only goes to 256kbs.

Thank you,

Mark Cheavens

Mark,

The dll will set any baud rate less than 2000000 (2MBaud). Most devices won't operate anything like fast. The hardware in the sender and the receiver will determine the maximum speed you can use. It looks like I should have set <= 2000000 but I find it hard to believe a serial port will work reliably at that speed if at all and I very much doubt a PC can deal with it.

You can easily add other baud rates to the sample script by adding them in the GuiCtrlSetDat line after $CmboBaud = GuiCtrCreateCombo.

Apart from restricting the baud rates in my sample app, if you tell me what other annoyances there are I will think about whether to change the example; it has never had much attention from me.

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.

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
×
×
  • Create New...