#NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile=Mircomvirtualprint2.exe #AutoIt3Wrapper_Compile_Both=y #AutoIt3Wrapper_Res_Comment=CHANGES PARSING TO REFLECT SUPER STUFF #AutoIt3Wrapper_Res_Description=Virtual printer and parser #AutoIt3Wrapper_Res_Fileversion=1.0.0.24 #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=p #AutoIt3Wrapper_Res_LegalCopyright=Robert Harwood 2010 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include #include #include 'CommMG.au3';or If you save the commMg.dll In the @scripdir use ;#include @ScriptDir & '\commg.dll' #include #include #include #include #include Opt("WINTITLEMATCHMODE", 3) OnAutoItExitRegister("alldone") HotKeySet("{ESC}", "alldone") Global $oExcelDoc = '' ;use for excel funtion and parsing routine Global $hnd = '' ;used for logging file Global $counter = '' ;used in excel function and parsing routine Global $address = '' ;used in excel function and parsing routine Global $excellocation = '' ;used to store location of excel executable Global $filename = '' ;used for file picker Global $Input1 = '' Global $BtnSend = '' Global $sCell2value = '' $result = '' ;used for any returned error message setting port Const $settitle = "VIRTUAL PRINT- set Port", $maintitle = "Virtual Print" $setflow = 2 ;default to no flow control Dim $FlowType[3] = ["XOnXoff", "Hardware (RTS, CTS)", "NONE"] #Region main program #Region ### START Koda GUI section ### Form=d:\my documents\miscdelphi\commg\ExampleComm.kxf $Form2 = GUICreate("Virtual Print", 473, 370, 339, 333, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_SYSMENU, $WS_CAPTION, $WS_OVERLAPPEDWINDOW, $WS_TILEDWINDOW, $WS_POPUP, $WS_POPUPWINDOW, $WS_GROUP, $WS_TABSTOP, $WS_BORDER, $WS_CLIPSIBLINGS)) $helpmenu = GUICtrlCreateMenu("Help") $aboutitem = GUICtrlCreateMenuItem("About", $helpmenu) $Edit1 = GUICtrlCreateEdit("", 10, 25, 449, 223, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_READONLY, $ES_WANTRETURN, $WS_HSCROLL, $WS_VSCROLL)) $BtnSend = GUICtrlCreateButton("Send", 380, 273, 53, 30, $BS_FLAT) $Btnreset = GUICtrlCreateButton("Reset", 425, 273, 53, 30, $BS_FLAT) $Input1 = GUICtrlCreateInput("", 18, 279, 361, 21) $Checkbox1 = GUICtrlCreateCheckbox("Add LF to incoming CR", 340, 4, 150, 17) $Checkbox2 = GUICtrlCreateCheckbox("Log to file", 105, 4, 100, 17) $Checkbox3 = GUICtrlCreateCheckbox("Enable Sounds", 205, 4, 100, 17) $Checkbox4 = GUICtrlCreateCheckbox("Auto update", 18, 260, 100, 17) ;$Checkbox5 = GUICtrlCreateCheckbox("Auto Panel Silence", 30, 260, 100, 17) GUICtrlSetState($Checkbox1, $GUI_CHECKED) GUICtrlSetState($Checkbox2, $GUI_UNCHECKED) GUICtrlSetState($Checkbox3, $GUI_UNCHECKED) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) $BtnSetPort = GUICtrlCreateButton("Set Port", 16, 312, 73, 30, $BS_FLAT) $BtnSilence = GUICtrlCreateButton("Silence Alarms", 150, 312, 73, 30, $BS_FLAT) $Label21 = GUICtrlCreateLabel("Received text", 34, 6, 70, 17) $Label31 = GUICtrlCreateLabel("commg.dll version unknown", 272, 328, 135, 17) GUICtrlSetColor(-1, 0x008080) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### WinSetTitle($Form2, "", $maintitle) ; get excel path and write to ini file If FileExists("C:\fireutils\settings.ini") Then $hinin = FileOpen("C:\fireutils\settings.ini", 0) $excellocation = FileRead($hinin) FileClose($hinin) Else SplashTextOn("Notice", "Please wait for comm dialog to appear before proceeding, this message should only appear the first time you use this program", -1, -1, -1, -1, 4, "", 24) Sleep(10000) SplashOff() $excellocation = _Find("excel.exe") $hiniout = FileOpen("c:\fireutils\settings.ini", 1) FileWrite($hiniout, $excellocation) FileFlush($hiniout) FileClose($hiniout) EndIf ; if ini file exist get location from there else run find then write ini file for future reading that way we only need to find once While SetPort(0) = -1 If MsgBox(4, 'Port not set', 'Do you want to quite the program?') = 6 Then Exit WEnd ;GUISwitch($Form2) ConsoleWrite("stage 1" & @CRLF) GUICtrlSetData($Label31, 'using ' & _CommGetVersion(1)) ConsoleWrite("stage 2" & @CRLF) Events() GUICtrlSetBkColor($Edit1, 0x000000) ;black GUICtrlSetColor($Edit1, 0xffffff) ; white GUICtrlSetState($Edit1, $GUI_FOCUS) While 1 ;get characters returning when @CR received (@CR is included in the return!) $instr = _CommGetLine() ;_CommGetLine([$endChar=@CR,$maxchar = 0, $maxtime = 0) If $instr <> '' Then ;if we got something from serial port If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then $instr = StringReplace($instr, @CR, @CRLF) ; see if we want crlf ;*****************This section does the stream parsing for colour codes based on data returned and if logging ;****************is required log the data to a file ;*************************************************************************************************************** ;******************************************* ALARM ******************************************************* ;*************************************************************************************************************** Select Case StringInStr($instr, 'PULL STATION ACT') Or StringInStr($instr, 'Alarm activated') Or StringInStr($instr, 'ALARM ACTIVE') Or StringInStr($instr, 'WATERFLOW ACTIVE') ;EST3 SYNTAX ; process alarm condition GUICtrlSetColor($Edit1, 0xff0000) ; Red If GUICtrlRead($Checkbox3) = $GUI_CHECKED Then ;if sound is enabled SoundPlay("c:\fireutils\sounds\Whopfast.wav") ; Alert user to alarm condtion can be silenced by button EndIf If GUICtrlRead($Checkbox2) = $GUI_CHECKED Then ;if file logging on FileWrite($hnd, $instr) FileFlush($hnd) EndIf GUICtrlSetData($Edit1, $instr, 1) ;send data to screen If GUICtrlRead($Checkbox4) = $GUI_CHECKED Then ;If the autoupdate checkboX is checked $Cardstart = StringInStr($instr, "Loop") + 4; read stream for card address $CARDADD = StringMid($instr, $Cardstart, 2) $panelstart = StringInStr($instr, "P:") + 2 $PANELADD = StringMid($instr, $panelstart, 1) If $PANELADD < "10" Then $panelstart = $panelstart + 1 $PANELADD = StringMid($instr, $panelstart, 1) EndIf $devicestart = StringInStr($instr, "ss") + 4 MsgBox(262144, 'Debug line ~' & @ScriptLineNumber, 'Selection:' & @CRLF & ' $devicestart' & @CRLF & @CRLF & 'Return:' & @CRLF & $devicestart) ;### Debug MSGBOX $DEVICEADD = StringMid($instr, $devicestart-1, 3) MsgBox(262144, 'Debug line ~' & @ScriptLineNumber, 'Selection:' & @CRLF & ' $DEVICEADD' & @CRLF & @CRLF & 'Return:' & @CRLF & $DEVICEADD) ;### Debug MSGBOX $address = $CARDADD & $DEVICEADD MsgBox(262144, 'Debug line ~' & @ScriptLineNumber, 'Selection:' & @CRLF & ' $address' & @CRLF & @CRLF & 'Return:' & @CRLF & $address) ;### Debug MSGBOX ;MsgBox(0, "", $Cardstart, 2) ;MsgBox(0, "", $panelstart, 2) ;MsgBox(0, "", $DEVICEADD, 2) ;ConsoleWrite($Cardstart & @CRLF) ;ConsoleWrite($panelstart & @CRLF) ;ConsoleWrite($address & @CRLF) For $i = 1 To $counter - 1 ;Loop ;$sCellValue = _ExcelReadCell($oExcelDoc, $i, 4) $sCellValue = _Excel_RangeRead($oExcelDoc, Default, "R" & cstr($i) & "C4") ;MsgBox(262144, 'Debug line ~' & @ScriptLineNumber, 'Selection:' & @CRLF & ' $sCellValue' & @CRLF & @CRLF & 'Return:' & @CRLF & $sCellValue) ;### Debug MSGBOX ;$sCell2value = _ExcelReadCell($oExcelDoc, $i, 11) $sCellValue = _Excel_RangeRead($oExcelDoc, Default, "R" & cstr($i) & "C11") ;MsgBox(262144, 'Debug line ~' & @ScriptLineNumber, 'Selection:' & @CRLF & ' $sCell2value' & @CRLF & @CRLF & 'Return:' & @CRLF & $sCell2value) ;### Debug MSGBOX If $sCellValue == $address And $sCell2value == "" Then ;_ExcelWriteCell($oExcelDoc, "X", $i, 11) _Excel_RangeWrite($oExcelDoc, Default, "X", "R" & cstr($i) & "C11") ;$oExcelDoc.ActiveSheet.Range("K" & $i).Select ;_ExcelWriteCell($oExcelDoc, "P", $i, 11) $oExcelDoc.Windows(1).Visible = True $oExcelDoc.saved = 1 ; Prevent questions from excel to save the file ;$oExcelDoc.close ;MsgBox(0, "", "update complete", 2) EndIf Next ;*******insert code for silence in here ;**************************************** ;If GUICtrlRead($Checkbox5) = $GUI_CHECKED Then ;ShellExecute("relayset.exe","-s########,01-t1000","c:\fireutils") ;endif ;**************************************** EndIf ;*************************************************************************************************************** ;******************************************* TROUBLE *********************************************************** ;*************************************************************************************************************** Case StringInStr($instr, 'TRBL') ;Watch for this string in serial data ;; process Trouble condition GUICtrlSetColor($Edit1, 0xffff00) ; yellow If GUICtrlRead($Checkbox2) = $GUI_CHECKED Then ;if file logging on FileWrite($hnd, $instr) FileFlush($hnd) EndIf If GUICtrlRead($Checkbox3) = $GUI_CHECKED Then ;if sound is enabled Beep(500, 100) EndIf GUICtrlSetData($Edit1, $instr, 1) ;send data to screen If GUICtrlRead($Checkbox4) = $GUI_CHECKED Then ;If the autoupdate checkboX is checked $Cardstart = StringInStr($instr, "Loop") + 2 $CARDADD = StringMid($instr, $Cardstart, 1) $panelstart = StringInStr($instr, "P:") + 2 $PANELADD = StringMid($instr, $panelstart, 2) If $PANELADD < "10" Then $panelstart = $panelstart + 1 $PANELADD = StringMid($instr, $panelstart, 1) EndIf $devicestart = StringInStr($instr, "Address") + 2 $DEVICEADD = StringMid($instr, $devicestart, 3) $address = $CARDADD & $DEVICEADD ;ConsoleWrite($Cardstart & @CRLF) ;ConsoleWrite($panelstart & @CRLF) ;ConsoleWrite($address & @CRLF) For $i = 1 To $counter - 1 ;Loop ;ConsoleWrite($i ) ;$sCellValue = _ExcelReadCell($oExcelDoc, $i, 4) MsgBox(262144, 'Debug line ~' & @ScriptLineNumber, 'Selection:' & @CRLF & ' $sCellValue' & @CRLF & @CRLF & 'Return:' & @CRLF & $sCellValue) ;### Debug MSGBOX ;$sCell2value = _ExcelReadCell($oExcelDoc, $i, 11) MsgBox(262144, 'Debug line ~' & @ScriptLineNumber, 'Selection:' & @CRLF & ' $sCell2value' & @CRLF & @CRLF & 'Return:' & @CRLF & $sCell2value) ;### Debug MSGBOX If $sCellValue == $address And $sCell2value == "" Then MsgBox(4, 'We are here', 'Passed the if statement') ;_ExcelWriteCell($oExcelDoc, "X", $i, 14) ;$oExcelDoc.ActiveSheet.Range("N" & $i).Select ;$oExcelDoc.Windows(1).Visible = True ;$oExcelDoc.saved = 1 ; Prevent questions from excel to save the file ;$oExcelDoc.close ;MsgBox(0, "", "update complete", 2) EndIf Next EndIf ;*************************************************************************************************************** ;******************************************* Supervisory ******************************************************* ;*************************************************************************************************************** Case StringInStr($instr, 'SUPERVISORY ACT') Or StringInStr($instr, 'GATEVALVE ACT') Or StringInStr($instr, 'SECURITY ACT') Or StringInStr($instr, 'TAMPER ACT') ;same as above ;; process supervisory condition GUICtrlSetColor($Edit1, 0xffff00) ; yellow If GUICtrlRead($Checkbox2) = $GUI_CHECKED Then FileWrite($hnd, $instr) FileFlush($hnd) EndIf If GUICtrlRead($Checkbox3) = $GUI_CHECKED Then Beep(500, 100) EndIf GUICtrlSetData($Edit1, $instr, 1) If GUICtrlRead($Checkbox4) = $GUI_CHECKED Then ;If the autoupdate checkboX is checked $Cardstart = StringInStr($instr, "Loop") + 2 $CARDADD = StringMid($instr, $Cardstart, 1) $panelstart = StringInStr($instr, "P:") + 2 $PANELADD = StringMid($instr, $panelstart, 2) If $PANELADD < "10" Then $panelstart = $panelstart + 1 $PANELADD = StringMid($instr, $panelstart, 1) EndIf $devicestart = StringInStr($instr, "Address") + 2 $DEVICEADD = StringMid($instr, $devicestart, 3) $address = $CARDADD & $DEVICEADD ConsoleWrite($Cardstart & @CRLF) ConsoleWrite($panelstart & @CRLF) ConsoleWrite($address & @CRLF) For $i = 1 To $counter - 1 ;Loop ;ConsoleWrite($i ) ;$sCellValue = _ExcelReadCell($oExcelDoc, $i, 4) ;ConsoleWrite($scellvalue) ;$sCell2value = _ExcelReadCell($oExcelDoc, $i, 5) If $sCellValue == $address And $sCell2value == "" Then ; _ExcelWriteCell($oExcelDoc, "P", $i, 11) ; $oExcelDoc.ActiveSheet.Range("K" & $i).Select ;_ExcelWriteCell($oExcelDoc, "P", $i, 11) ; $oExcelDoc.Windows(1).Visible = True ; $oExcelDoc.saved = 1 ; Prevent questions from excel to save the file ;$oExcelDoc.close ;MsgBox(0, "", "update complete", 2) EndIf Next EndIf Case StringInStr($instr, 'RESTORED') Or StringInStr($instr, 'RST') ;same as above ;; process restored condition GUICtrlSetColor($Edit1, 0x7FFF00) ; Green If GUICtrlRead($Checkbox2) = $GUI_CHECKED Then FileWrite($hnd, $instr) FileFlush($hnd) EndIf If GUICtrlRead($Checkbox3) = $GUI_CHECKED Then Beep(500, 100) EndIf GUICtrlSetData($Edit1, $instr, 1) Case Else GUICtrlSetColor($Edit1, 0xffffff) ; set text to white for all normal display If GUICtrlRead($Checkbox2) = $GUI_CHECKED Then ;Check for logging FileWrite($hnd, $instr) FileFlush($hnd) EndIf GUICtrlSetData($Edit1, $instr, 1) ;send data to screen EndSelect EndIf WEnd ; ********************************When we are done close things off *************************************** If GUICtrlRead($Checkbox2) = $GUI_CHECKED Then FileClose($hnd) EndIf If GUICtrlRead($Checkbox4) = $GUI_CHECKED Then $oExcelDoc.saved = 1 $oExcelDoc.close $oExcelDoc = 0 EndIf AllDone() Func port11() ; no ideas what this does was part of comm example script ;MsgBox(0,'now set to channel',_CommSwitch(2)) _commSwitch(2) $s2 = "1 2 3 4" ;_CommGetString() ConsoleWrite("comm1 gets " & $s2 & @CRLF) _CommSendString($s2) _CommSwitch(1) EndFunc ;==>port11 #EndRegion main program Func Events() Opt("GUIOnEventMode", 1) GUISetOnEvent($GUI_EVENT_CLOSE, "justgo") GUICtrlSetOnEvent($BtnSend, "SendEvent") GUICtrlSetOnEvent($BtnSetPort, "SetPortEvent") GUICtrlSetOnEvent($BtnSilence, "Silence") GUICtrlSetOnEvent($Checkbox4, "AutoUpdate") GUICtrlSetOnEvent($Checkbox2, "Logfile") GUICtrlSetOnEvent($aboutitem, "About") EndFunc ;==>Events Func SetPortEvent() SetPort() ;needed because a parameter is optional for setport so we can't use "setport" for the event GUICtrlSetState($Edit1, $GUI_FOCUS) EndFunc ;==>SetPortEvent Func AutoUpdate() ;*******************This is for checking the number of records in the excel file If GUICtrlRead($Checkbox4) = $GUI_UNCHECKED Then $oExcelDoc.saved = 1 $oExcelDoc.close $oExcelDoc = 0 EndIf If GUICtrlRead($Checkbox4) = $GUI_CHECKED Then ; if we turn on the autoupdate function $filename = FileOpenDialog("File picker", "c:\fireutils", "All (*.csv;*.xls)|", 1 + 4) ; pick the spreadsheet to use If @error Then MsgBox(4096, "", "No File(s) chosen") Else $filename = StringReplace($filename, "|", @CRLF) ;MsgBox(4096,"","You chose " & $filename) ;$excellocation, EndIf ShellExecute($filename) If Not FileExists($filename) Then ; Just a check to be sure.. MsgBox(0, "Excel Data Test", "Error: Can't find file " & $filename) Exit EndIf ; open the spreadsheet for viewing Local $oExcel = _Excel_Open() Local $oExcelDoc = _Excel_BookOpen($oExcel, $filename) ;$oExcelDoc = ObjGet($filename) ; Get an Excel Object from an existing filename ;$oExcelDoc.Visible = 1 If (Not @error) And IsObj($oExcelDoc) Then ; Check again if everything went well ; NOTE: $oExcelDoc is a "Workbook Object", not Excel itself! $oExcelDoc.Windows(1).Visible = 1; Set the first worksheet in the workbook visible $oExcelDoc.Application.Visible = 1; $oDocument = $oExcelDoc.Worksheets(1) ; We use the 'Default' worksheet ;$oDocument = $oExcelDoc.Worksheets(1) ; We use the 'Default' worksheet old code ;may change if we go to another spreadsheet $counter = 1 While(_Excel_RangeRead($oExcelDoc, Default, "R" & cstr($i) & "C4")) ;While (_ExcelReadCell($oExcelDoc, $counter, 4) <> "") ; get the number of devices in the sheet so that we $counter = $counter + 1 ;know what the top end is when we parse MsgBox(4096, "", $counter) ;ConsoleWrite($counter) WEnd Else MsgBox(0, "Excel Data Test", "Error: Could not open " & $filename & " as an Excel Object.") EndIf EndIf EndFunc ;==>AutoUpdate Func Logfile() ;*******************This function turns on and off file logging If GUICtrlRead($Checkbox2) = $GUI_UNCHECKED Then FileClose($hnd) ConsoleWrite("close log file" & @CRLF) EndIf If GUICtrlRead($Checkbox2) = $GUI_CHECKED Then ConsoleWrite("open log file" & @CRLF) $hnd = FileOpen("Virtualprintlog.txt", 1) EndIf EndFunc ;==>Logfile Func justgo() Exit EndFunc ;==>justgo Func SendEvent() ;send the text in the input and append CR _CommSendstring(GUICtrlRead($Input1) & @CR) GUICtrlSetData($Input1, '') ;clear the input ;GUICtrlSetState($edit1,$GUI_FOCUS);sets the caret back in the terminal screen EndFunc ;==>SendEvent Func Silence() ;stop the sound from alarms etc SoundPlay("") EndFunc ;==>Silence Func About() ;Display version info $ver = FileGetVersion("c:\fireutils\virtualprint.exe") MsgBox(0, "About", "File version:" & $ver & " Written by Robert Harwood using AutoIt Gui Creator (C) 2010") EndFunc ;==>About Func AllDone() ;MsgBox(0,'will close ports','') _Commcloseport() ;MsgBox(0,'port closed','') Exit EndFunc ;==>AllDone Func _Find($s, $d = @HomeDrive) ;only way I could find to locate the excel. exe file If StringRight($d, 1) <> "\" Then $d &= "\" Local $h = FileFindFirstFile($d & "*") If $h = -1 Then Return 0 While 1 $t = FileFindNextFile($h) If $t = $s Then Return $d & $t $t = $d & $t If @error Then Return 0 * FileClose($h) If StringInStr(FileGetAttrib($t), "D") Then $tmp = _Find($s, $t) If $tmp <> "0" Then Return $tmp ContinueLoop EndIf WEnd FileClose($h) Return 0 EndFunc ;==>_Find Func _FindAll($s, $d = @HomeDrive) If Not IsDeclared("sRet") Then Static $sRet = "" EndIf If StringRight($d, 1) <> "\" Then $d &= "\" Local $h = FileFindFirstFile($d & "*") If $h = -1 Then Return "" While 1 $t = FileFindNextFile($h) If @error Then ExitLoop If $t = $s Then $sRet &= @CRLF & $d & $t $t = $d & $t If StringInStr(FileGetAttrib($t), "D") Then $tmp = _FindAll($s, $t) WEnd FileClose($h) Return $sRet EndFunc ;==>_FindAll ; Function SetPort($mode=1) ; Creates a form for the port settings ;Parameter $mode sets the return value depending on whether the port was set ;Returns 0 if $mode <> 1 ; -1 If` the port not set and $mode is 1 Func SetPort($mode = 1) ;if $mode = 1 then returns -1 if settings not made Opt("GUIOnEventMode", 0) ;keep events for $Form2, use GuiGetMsg for $Form3 #Region ### START Koda GUI section ### Form=d:\my documents\miscdelphi\commg\examplecommsetport.kxf $Form3 = GUICreate("virtual Print - set Port", 422, 279, 329, 268, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_GROUP, $WS_BORDER, $WS_CLIPSIBLINGS, $DS_MODALFRAME), BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE)) $Group1 = GUICtrlCreateGroup("Set COM Port", 18, 8, 288, 252) $CmboPortsAvailable = GUICtrlCreateCombo("", 127, 28, 145, 25) $CmBoBaud = GUICtrlCreateCombo("9600", 127, 66, 145, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL, $CBS_SORT, $WS_VSCROLL)) GUICtrlSetData(-1, "10400|110|115200|1200|128000|14400|150|15625|1800|19200|2000|2400|256000|28800|3600|38400|4800|50|56000|57600|600|7200|75") $CmBoStop = GUICtrlCreateCombo("1", 127, 141, 145, 25) GUICtrlSetData(-1, "1|2|1.5") $CmBoParity = GUICtrlCreateCombo("none", 127, 178, 145, 25) GUICtrlSetData(-1, "odd|even|none") $Label2 = GUICtrlCreateLabel("Port", 94, 32, 23, 17) $Label3 = GUICtrlCreateLabel("baud", 89, 70, 28, 17) $Label4 = GUICtrlCreateLabel("No. Stop bits", 52, 145, 65, 17) $Label5 = GUICtrlCreateLabel("parity", 88, 182, 29, 17) $CmboDataBits = GUICtrlCreateCombo("8", 127, 103, 145, 25) GUICtrlSetData(-1, "7|8") $Label7 = GUICtrlCreateLabel("No. of Data Bits", 38, 107, 79, 17) $ComboFlow = GUICtrlCreateCombo("NONE", 127, 216, 145, 25) GUICtrlSetData(-1, "NONE|XOnXOff|Hardware (RTS, CTS)") $Label1 = GUICtrlCreateLabel("flow control", 59, 220, 58, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) $BtnApply = GUICtrlCreateButton("Apply", 315, 95, 75, 35, $BS_FLAT) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $BtnCancel = GUICtrlCreateButton("Cancel", 316, 147, 76, 35, $BS_FLAT) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### WinSetTitle($Form3, "", $settitle) ;ensure a change to Koda design doesn't stop script working $mainxy = WinGetPos($Form2) WinMove($Form3, "", $mainxy[0] + 20, $mainxy[1] + 20) $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($CmboPortsAvailable, $portlist[$pl]) ;_CommListPorts()) Next GUICtrlSetData($CmboPortsAvailable, $portlist[1]) ;show the first port found GUICtrlSetData($ComboFlow, $FlowType[$setflow]) _GUICtrlComboBox_SetMinVisible($CmBoBaud, 10) ;restrict the length of the drop-down list $retval = 0 While 1 $msg = GUIGetMsg() If $msg = $BtnCancel Then If Not $mode Then $retval = -1 ExitLoop EndIf 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', '') _CommSetPort($setport, $sportSetError, GUICtrlRead($CmBoBaud), GUICtrlRead($CmboDataBits), GUICtrlRead($CmBoParity), GUICtrlRead($CmBoStop), $setflow) If $sportSetError = '' Then MsgBox(262144, 'Connected ', 'to COM' & $setport) Else MsgBox(262144, 'Setport error = ', $sportSetError) EndIf $mode = 1 ; ExitLoop EndIf ;stop user switching back to $form2 If WinActive($maintitle) Then ConsoleWrite('main is active' & @CRLF) If WinActivate($settitle) = 0 Then MsgBox(0, 'not found', $settitle) EndIf WEnd GUIDelete($Form3) WinActivate($maintitle) Events() Return $retval EndFunc ;==>SetPort