Jump to content

N0RVLL

Members
  • Posts

    6
  • Joined

  • Last visited

Everything posted by N0RVLL

  1. 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.
  2. It WORKS! I've just got a couple little kinks to work out, and it'll be 100% operational. Thanks!!
  3. 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.
  4. 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
  5. 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!
  6. 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
×
×
  • Create New...