Jump to content
Fractured

Array failure after Unit "Reboot"

Recommended Posts

 

SO...I am horrible at arrays, as many of you that have helped me know!! This program works like a champ, until I reboot the test unit...then....bleck!!!

I have it narrowed down to the _SwitchPos($hFile) function i have writen, which sends a SHOW STATUS command to the unit under test, recieves the status of all the attenuators and RF switches. Upon a reboot command it throws the ""K:\Work\AutoIT Scripts\Mine\Models\10204\Edit\Test\10204_Functions.au3" (184) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: $arr[$ii][$jj] = $cell[$jj]....

Ive tried resetting the  $arr to 0, redim, ubound, destoy it, kick it, tell it no dessert, but it refuses to function!! The only thing that worked was the _ScriptRestart()  function I found in the forums, but I dont think killing the script and restarting it is the most efficient way...plus you loose the data in the rich text window that needs to be kept and sent to a file for archive purposes....

Any help would be greatly appreciated..

This is the core of the script...

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=..\..\..\..\..\Icons\DXP_Options_PrinterSetup_ICON.ico
#AutoIt3Wrapper_Compression=3
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ============================ # Header # =============================================================
    Title ............: 10204 Core Test
    Description ......:
    Script Version ...:
    Author ...........: Charles Wright
    Language .........: English
    AutoIt Version ...: 3.3.14.5
    Notes ............:
    Version History ..: Alpha Build
#ce ============================ # Header # =============================================================

; ========================================================================================================
#Region Main Includes ------------------------------------------------------------------------------------
; ========================================================================================================
#include-once
#include <Array.au3>
#include <ButtonConstants.au3>
#include <ColorConstants.au3>
#include <CommInterface.au3>
#include <EditConstants.au3>
#include <FontConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiRichEdit.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <Restart.au3>
#include "10204_Functions.au3"
; ========================================================================================================
#EndRegion Main Includes ------------------------------------------------------------------------------------
; ========================================================================================================

Opt("GUIResizeMode", $GUI_DOCKAUTO)

; ========================================================================================================
#Region Main Variables -----------------------------------------------------------------------------------
; ========================================================================================================
$SoundFile = "C:\Windows\Media\Windows Ding.wav"
FileInstall("C:\Windows\Media\Windows Ding.wav", $SoundFile)
$MyIcon = "K:\Work\AutoIT Scripts\Icons\DXP_Options_PrinterSetup_ICON.ico" ;Load MyIcon for Menu Bar
FileInstall("K:\Work\AutoIT Scripts\Icons\DXP_Options_PrinterSetup_ICON.ico", $MyIcon) ; Install ico when compiled
Global $ClickConnect = 0, $StatusMemo = ""
Global $hFile
Global $aResult[0]
Global $aSTAT[0][1]
Global $sSwitchName
Global $sResult = ""
Global $SW1, $SW2, $SW3, $SW4, $SW5, $SW6, $SW7, $SW8, $SW9
; ========================================================================================================
#EndRegion Main Variables --------------------------------------------------------------------------------
; ========================================================================================================

; ========================================================================================================
#Region Main GUI Creation --------------------------------------------------------------------------------
; ========================================================================================================
$g_10204Test = GUICreate("10204 Test", 836, 694, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME))
GUISetBkColor(0xFFFBF0)
; ##### Connect and Edit Window #######################################################
GUICtrlCreateLabel("COM Port:", 144, 16, 77, 24, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$i_CommPort = GUICtrlCreateInput("", 226, 16, 41, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER))
$b_Connect = GUICtrlCreateButton("Connect", 273, 16, 75, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0xFF0000)
$b_Disconnect = GUICtrlCreateButton("Disconnect", 352, 16, 75, 25)
$b_Reboot = GUICtrlCreateButton("Reboot", 432, 16, 75, 25)
$g_hRichEdit = _GUICtrlRichEdit_Create($g_10204Test, "", 8, 48, 617, 297, _
        BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY))
; ##### TX1 Output Paths ##############################################################
GUICtrlCreateLabel("4.4.2", 40, 352, 39, 24)
GUICtrlSetFont(-1, 12, 400, 4, "MS Sans Serif")
$b_TX1 = GUICtrlCreateButton("TX1", 24, 376, 67, 25)
GUICtrlSetBkColor(-1, 0xBFCDDB)
$b_J11J17 = GUICtrlCreateButton("J11-J17", 24, 408, 67, 25)
GUICtrlSetBkColor(-1, 0xBFCDDB)
$b_J12J17 = GUICtrlCreateButton("J12-J17", 24, 440, 67, 25)
GUICtrlSetBkColor(-1, 0xBFCDDB)
$b_J13J17 = GUICtrlCreateButton("J13-J17", 24, 472, 67, 25)
GUICtrlSetBkColor(-1, 0xBFCDDB)
$b_J14J17 = GUICtrlCreateButton("J14-J17", 24, 504, 67, 25)
GUICtrlSetBkColor(-1, 0xBFCDDB)
$b_J15J17 = GUICtrlCreateButton("J15-J17", 24, 536, 67, 25)
GUICtrlSetBkColor(-1, 0xBFCDDB)
$b_J16J17 = GUICtrlCreateButton("J16-J17", 24, 568, 67, 25)
GUICtrlSetBkColor(-1, 0xBFCDDB)
$b_J16J17Amp = GUICtrlCreateButton("J16-J17 AMP", 24, 600, 67, 25)
GUICtrlSetBkColor(-1, 0xBFCDDB)
; ##### RX1 Input Paths ###############################################################
GUICtrlCreateLabel("4.4.3", 128, 352, 39, 24)
GUICtrlSetFont(-1, 12, 400, 4, "MS Sans Serif")
$b_RX1 = GUICtrlCreateButton("RX1", 112, 376, 67, 25)
GUICtrlSetBkColor(-1, 0xBFCDDB)
$b_J10J4 = GUICtrlCreateButton("J10-J4", 112, 408, 67, 25)
GUICtrlSetBkColor(-1, 0xBFCDDB)
$b_J10J5 = GUICtrlCreateButton("J10-J5", 112, 440, 67, 25)
GUICtrlSetBkColor(-1, 0xBFCDDB)
$b_J10J6 = GUICtrlCreateButton("J10-J6", 112, 472, 67, 25)
GUICtrlSetBkColor(-1, 0xBFCDDB)
$b_J10J7 = GUICtrlCreateButton("J10-J7", 112, 504, 67, 25)
GUICtrlSetBkColor(-1, 0xBFCDDB)
$b_J10J8 = GUICtrlCreateButton("J10-J8", 112, 536, 67, 25)
GUICtrlSetBkColor(-1, 0xBFCDDB)
$b_J10J9 = GUICtrlCreateButton("J10-J9", 112, 568, 67, 25)
GUICtrlSetBkColor(-1, 0xBFCDDB)
; ##### RX2 Input Paths ###############################################################
GUICtrlCreateLabel("4.4.4", 216, 352, 39, 24)
GUICtrlSetFont(-1, 12, 400, 4, "MS Sans Serif")
$b_J3J4 = GUICtrlCreateButton("J3-J4", 200, 376, 67, 25)
GUICtrlSetBkColor(-1, 0xBFCDDB)
$b_J3TERM = GUICtrlCreateButton("J3 TERM", 200, 408, 67, 25)
GUICtrlSetBkColor(-1, 0xBFCDDB)
$b_J3J18 = GUICtrlCreateButton("J3-J18", 200, 440, 67, 25)
GUICtrlSetBkColor(-1, 0xBFCDDB)
$b_J3J19 = GUICtrlCreateButton("J3-J19", 200, 472, 67, 25)
GUICtrlSetBkColor(-1, 0xBFCDDB)
$b_J3J20 = GUICtrlCreateButton("J3-J20", 200, 504, 67, 25)
GUICtrlSetBkColor(-1, 0xBFCDDB)
GUICtrlCreateLabel("COM Port:", 144, 16, 77, 24, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
; ##### Attenuator Test ###############################################################
GUICtrlCreateLabel("4.4.5", 304, 352, 39, 24)
GUICtrlSetFont(-1, 12, 400, 4, "MS Sans Serif")
$b_SetSwitch1 = GUICtrlCreateButton("Set Switches", 288, 376, 67, 25)
GUICtrlSetBkColor(-1, 0xBFCDDB)
; ##### Power Meters Test #############################################################
GUICtrlCreateLabel("4.4.6", 392, 352, 39, 24)
GUICtrlSetFont(-1, 12, 400, 4, "MS Sans Serif")
$b_SetSwitch2 = GUICtrlCreateButton("Set Switches", 376, 376, 75, 25)
GUICtrlSetBkColor(-1, 0xBFCDDB)
$b_PM1 = GUICtrlCreateButton("Query PM 1", 376, 408, 75, 25)
GUICtrlSetBkColor(-1, 0xBFCDDB)
$b_PM2 = GUICtrlCreateButton("Query PM 2", 376, 440, 75, 25)
GUICtrlSetBkColor(-1, 0xBFCDDB)
$i_PM1OffSet = GUICtrlCreateInput("", 376, 480, 73, 21)
$b_PM1OffSet = GUICtrlCreateButton("PM 1 Off Set", 376, 504, 75, 25)
GUICtrlSetBkColor(-1, 0xBFCDDB)
$i_PM2OffSet = GUICtrlCreateInput("", 376, 544, 73, 21)
$b_PM2OffSet = GUICtrlCreateButton("PM 2 Off Set", 376, 568, 75, 25)
GUICtrlSetBkColor(-1, 0xBFCDDB)
$b_AttnZero = GUICtrlCreateButton("Set Attn's to 0", 472, 376, 75, 25)
GUICtrlSetBkColor(-1, 0xBFCDDB)
GUICtrlCreateLabel("4.4.7", 488, 352, 39, 24)
GUICtrlSetFont(-1, 12, 400, 4, "MS Sans Serif")
$b_NFT1 = GUICtrlCreateButton("J16-J17", 568, 376, 59, 25)
GUICtrlSetBkColor(-1, 0xBFCDDB)
GUICtrlCreateLabel("4.4.9", 584, 352, 39, 24)
GUICtrlSetFont(-1, 12, 400, 4, "MS Sans Serif")
$b_NFT2 = GUICtrlCreateButton("J3-J18", 568, 408, 59, 25)
GUICtrlSetBkColor(-1, 0xBFCDDB)
$b_NFT3 = GUICtrlCreateButton("J10-J9", 568, 440, 59, 25)
GUICtrlSetBkColor(-1, 0xBFCDDB)

; Switch 1 Position Markers =================================================================================
GUICtrlCreateLabel("SW 1", 712, 40, 43, 24, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetFont(-1, 12, 400, 4, "MS Sans Serif")
Global $abS1[7]
For $bS1 = 1 + 0 To 6
    $abS1[$bS1] = GUICtrlCreateButton($bS1, 625 + ($bS1 * 27), 64, 27, 24)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    GUICtrlSetBkColor(-1, 0xFFFBF0)
Next
; ===========================================================================================================
; Switch 2 Position Markers =================================================================================
GUICtrlCreateLabel("SW 2", 712, 104, 43, 24, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetFont(-1, 12, 400, 4, "MS Sans Serif")
Global $abS2[7]
For $bS2 = 1 + 0 To 6
    $abS2[$bS2] = GUICtrlCreateButton($bS2, 625 + ($bS2 * 27), 128, 27, 24)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    GUICtrlSetBkColor(-1, 0xFFFBF0)
Next
; ===========================================================================================================
; Switch 3 Position Markers =================================================================================
GUICtrlCreateLabel("SW 3", 712, 160, 43, 24, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetFont(-1, 12, 400, 4, "MS Sans Serif")
Global $abS3[3]
For $bS3 = 1 + 0 To 2
    $abS3[$bS3] = GUICtrlCreateButton($bS3, 680 + ($bS3 * 27), 183, 27, 24)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    GUICtrlSetBkColor(-1, 0xFFFBF0)
Next
; ===========================================================================================================
; Switch 4 Position Markers =================================================================================
GUICtrlCreateLabel("SW 4", 711, 227, 43, 24, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetFont(-1, 12, 400, 4, "MS Sans Serif")
Global $abS4[3]
For $bS4 = 1 + 0 To 2
    $abS4[$bS4] = GUICtrlCreateButton($bS4, 680 + ($bS4 * 27), 250, 27, 24)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    GUICtrlSetBkColor(-1, 0xFFFBF0)
Next
; ===========================================================================================================
; Switch 5 Position Markers =================================================================================
GUICtrlCreateLabel("SW 5", 713, 283, 43, 24, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetFont(-1, 12, 400, 4, "MS Sans Serif")
Global $abS5[3]
For $bS5 = 1 + 0 To 2
    $abS5[$bS5] = GUICtrlCreateButton($bS5, 680 + ($bS5 * 27), 307, 27, 24)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    GUICtrlSetBkColor(-1, 0xFFFBF0)
Next
; ===========================================================================================================
; Switch 6 Position Markers =================================================================================
GUICtrlCreateLabel("SW 6", 713, 349, 43, 24, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetFont(-1, 12, 400, 4, "MS Sans Serif")
Global $abS6[3]
For $bS6 = 1 + 0 To 2
    $abS6[$bS6] = GUICtrlCreateButton($bS6, 680 + ($bS6 * 27), 373, 27, 24)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    GUICtrlSetBkColor(-1, 0xFFFBF0)
Next
; ===========================================================================================================
GUICtrlCreateLabel("ATTN 1", 672, 440, 119, 24, $SS_CENTER)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$i_Attn1 = GUICtrlCreateInput("", 664, 472, 121, 32, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUICtrlCreateLabel("ATTN 2", 672, 520, 119, 24, $SS_CENTER)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$i_Attn2 = GUICtrlCreateInput("", 664, 544, 121, 32, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
; ===========================================================================================================
$b_OutFile = GUICtrlCreateButton("Send To File", 544, 16, 75, 25)
GUICtrlSetBkColor(-1, 0xBFCDDB)
GUISetState(@SW_SHOW)
; ===========================================================================================================
GUICtrlCreateLabel("Manual Command", 328, 616, 113, 20, $SS_CENTER)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$i_Manual = GUICtrlCreateInput("", 112, 640, 521, 21)
$b_Manual = GUICtrlCreateButton("Send", 640, 640, 75, 25)
GUICtrlSetBkColor(-1, 0xBFCDDB)
; ===========================================================================================================
_DisplayPorts($g_hRichEdit)
; ========================================================================================================
#EndRegion Main GUI Creation --------------------------------------------------------------------------------
; ========================================================================================================

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $b_Connect
            If $ClickConnect = 0 Then
                _ConnectSet($i_CommPort)
                _SwitchPos($hFile)
            Else
                SoundPlay($SoundFile)
                _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 255)
                _GUICtrlRichEdit_AppendText($g_hRichEdit, "You are already Connected." & @CRLF)
            EndIf

            If $ClickConnect = "1" Then
                GUICtrlSetBkColor($b_Connect, $COLOR_GREEN)
            Else
                GUICtrlSetBkColor($b_Connect, $COLOR_RED)
            EndIf
        Case $b_Disconnect
            If $ClickConnect = 0 Then
                SoundPlay($SoundFile)
                _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 255)
                _GUICtrlRichEdit_AppendText($g_hRichEdit, "You are already Disconnected." & @CRLF)
                GUICtrlSetState($b_Connect, $GUI_FOCUS)
            Else
                _CommAPI_ClosePort($hFile)
                GUICtrlSetBkColor($b_Connect, $COLOR_RED)
                _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 255)
                _GUICtrlRichEdit_AppendText($g_hRichEdit, "User Disconnected." & @CRLF)
                $ClickConnect = 0
            EndIf
        Case $b_Reboot
            $uInput = "REBOOT"
            _UnitSend($uInput)
            _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 16711680)
            _UnitRecieve($StatusMemo)
            ;_ScriptRestart()       Debug Only
            _SwitchPos($hFile)
            ; ### 4.4.2 ###############################################################################
        Case $b_TX1
            $uInput = "SetSwitch 4 1 0; SetSwitch 5 1 0; SetAttenuator 1 0"
            _UnitSend($uInput)
            _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 16711680)
            _UnitRecieve($StatusMemo)
            _SwitchPos($hFile)
        Case $b_J11J17
            $uInput = "SetSwitch 1 1 0"
            _UnitSend($uInput)
            _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 16711680)
            _UnitRecieve($StatusMemo)
            _SwitchPos($hFile)
        Case $b_J12J17
            $uInput = "SetSwitch 1 2 0"
            _UnitSend($uInput)
            _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 16711680)
            _UnitRecieve($StatusMemo)
            _SwitchPos($hFile)
        Case $b_J13J17
            $uInput = "SetSwitch 1 3 0"
            _UnitSend($uInput)
            _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 16711680)
            _UnitRecieve($StatusMemo)
            _SwitchPos($hFile)
        Case $b_J14J17
            $uInput = "SetSwitch 1 4 0"
            _UnitSend($uInput)
            _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 16711680)
            _UnitRecieve($StatusMemo)
            _SwitchPos($hFile)
        Case $b_J15J17
            $uInput = "SetSwitch 1 5 0"
            _UnitSend($uInput)
            _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 16711680)
            _UnitRecieve($StatusMemo)
            _SwitchPos($hFile)
        Case $b_J16J17
            $uInput = "SetSwitch 1 6 0"
            _UnitSend($uInput)
            _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 16711680)
            _UnitRecieve($StatusMemo)
            _SwitchPos($hFile)
        Case $b_J16J17Amp
            $uInput = "SetSwitch 1 6 0; SetSwitch 4 2 0; SetSwitch 5 2 0"
            _UnitSend($uInput)
            _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 16711680)
            _UnitRecieve($StatusMemo)
            _SwitchPos($hFile)
            ; ### 4.4.3 ###############################################################################
        Case $b_RX1
            $uInput = "SetSwitch 6 1 1; SetSwitch 3 1 1; SetAttenuator 2 0"
            _UnitSend($uInput)
            _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 16711680)
            _UnitRecieve($StatusMemo)
            _SwitchPos($hFile)
        Case $b_J10J4
            $uInput = "SetSwitch 3 2 1; SetSwitch 2 1 1"
            _UnitSend($uInput)
            _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 16711680)
            _UnitRecieve($StatusMemo)
            _SwitchPos($hFile)
        Case $b_J10J5
            $uInput = "SetSwitch 2 2 1"
            _UnitSend($uInput)
            _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 16711680)
            _UnitRecieve($StatusMemo)
            _SwitchPos($hFile)
        Case $b_J10J6
            $uInput = "SetSwitch 2 3 1"
            _UnitSend($uInput)
            _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 16711680)
            _UnitRecieve($StatusMemo)
            _SwitchPos($hFile)
        Case $b_J10J7
            $uInput = "SetSwitch 2 4 1"
            _UnitSend($uInput)
            _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 16711680)
            _UnitRecieve($StatusMemo)
            _SwitchPos($hFile)
        Case $b_J10J8
            $uInput = "SetSwitch 2 5 1"
            _UnitSend($uInput)
            _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 16711680)
            _UnitRecieve($StatusMemo)
            _SwitchPos($hFile)
        Case $b_J10J9
            $uInput = "SetSwitch 2 6 1"
            _UnitSend($uInput)
            _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 16711680)
            _UnitRecieve($StatusMemo)
            _SwitchPos($hFile)
            ; ### 4.4.4 ###############################################################################
        Case $b_J3J4
            $uInput = "SetSwitch 3 1 1"
            _UnitSend($uInput)
            _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 16711680)
            _UnitRecieve($StatusMemo)
            _SwitchPos($hFile)
        Case $b_J3TERM
            $uInput = "SetSwitch 3 2 1"
            _UnitSend($uInput)
            _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 16711680)
            _UnitRecieve($StatusMemo)
            _SwitchPos($hFile)
        Case $b_J3J18
            $uInput = "SetSwitch 3 2 1"
            _UnitSend($uInput)
            _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 16711680)
            _UnitRecieve($StatusMemo)
            _SwitchPos($hFile)
        Case $b_J3J19
            $uInput = "SetSwitch 3 2 1"
            _UnitSend($uInput)
            _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 16711680)
            _UnitRecieve($StatusMemo)
            _SwitchPos($hFile)
        Case $b_J3J20
            $uInput = "SetSwitch 3 2 1"
            _UnitSend($uInput)
            _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 16711680)
            _UnitRecieve($StatusMemo)
            _SwitchPos($hFile)
            ; ### 4.4.5 ###############################################################################
        Case $b_SetSwitch1
            $uInput = "SetSwitch 1 1 0; SetSwitch 4 1 0; SetSwitch 5 1 0; SetSwitch 6 1 1; SetSwitch 2 6 1; SetAttenuator 1 0; SetAttenuator 2 0"
            _UnitSend($uInput)
            _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 16711680)
            _UnitRecieve($StatusMemo)
            _SwitchPos($hFile)
            ; ### 4.4.6 ###############################################################################
        Case $b_SetSwitch2
            $uInput = "RFSW ALL 1; RFSW 6 2; ATTN 1 0"
            _UnitSend($uInput)
            _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 16711680)
            _UnitRecieve($StatusMemo)
            _SwitchPos($hFile)
        Case $b_PM1
            $uInput = "QueryPowerMeter 1"
            _UnitSend($uInput)
            _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 16711680)
            _UnitRecieve($StatusMemo)
        Case $b_PM2
            $uInput = "QueryPowerMeter 2"
            _UnitSend($uInput)
            _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 16711680)
            _UnitRecieve($StatusMemo)
        Case $b_PM1OffSet
            $PM1OS = GUICtrlRead($i_PM1OffSet)
            $uInput = "PWRMTR OFFSET 1 " & $PM1OS
            _UnitSend($uInput)
            _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 16711680)
            _UnitRecieve($StatusMemo)
        Case $b_PM2OffSet
            $PM2OS = GUICtrlRead($i_PM2OffSet)
            $uInput = "PWRMTR OFFSET 2 " & $PM2OS
            _UnitSend($uInput)
            _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 16711680)
            _UnitRecieve($StatusMemo)
            ; ### 4.4.7 ###############################################################################
        Case $b_AttnZero
            $uInput = "SetSwitch 1 6 0; SetAttenuator 1 0; SetAttenuator 2 0"
            _UnitSend($uInput)
            _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 16711680)
            _UnitRecieve($StatusMemo)
            _SwitchPos($hFile)
            ; ### 4.4.9 ###############################################################################
        Case $b_NFT1
            $uInput = "SetSwitch 1 6 0; SetSwitch 4 2 0; SetSwitch 5 2 0; SetAttenuator 1 0"
            _UnitSend($uInput)
            _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 16711680)
            _UnitRecieve($StatusMemo)
            _SwitchPos($hFile)
        Case $b_NFT2
            $uInput = "SetSwitch 3 2 0"
            _UnitSend($uInput)
            _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 16711680)
            _UnitRecieve($StatusMemo)
            _SwitchPos($hFile)
        Case $b_NFT3
            $uInput = "SetSwitch 6 1 1; SetSwitch 2 6 1; SetAttenuator 2 0"
            _UnitSend($uInput)
            _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 16711680)
            _UnitRecieve($StatusMemo)
            _SwitchPos($hFile)
        Case $b_Manual
            $uInput = GUICtrlRead($i_Manual)
            _UnitSend($uInput)
            _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 16711680)
            _UnitRecieve($StatusMemo)
            _SwitchPos($hFile)
            GUICtrlSetData($i_Manual, "", "")
    EndSwitch
WEnd

 

This is the Functions that contain the error....

; ========================================================================================================
#Region Main Includes ------------------------------------------------------------------------------------
; ========================================================================================================
#include-once
#include <Array.au3>
#include <ColorConstants.au3>
#include <CommInterface.au3>
#include <File.au3>
#include <GuiRichEdit.au3>
; ========================================================================================================
#EndRegion Main Includes ------------------------------------------------------------------------------------
; ========================================================================================================

; ========================================================================================================
#Region Main Variables -----------------------------------------------------------------------------------
; ========================================================================================================
Global $i_CommPort, $SoundFile, $g_hRichEdit, $Edit1, $hFile
Global $abS1, $abS2, $abS3, $abS4, $abS5, $abS6, $ii, $jj
Global $i_Attn1, $i_Attn2
Local $b_Holder1, $b_Holder2, $b_Holder3, $b_Holder4, $b_Holder5, $b_Holder6

; ========================================================================================================
#EndRegion Main Variables -----------------------------------------------------------------------------------
; ========================================================================================================

; #FUNCTION# ==============================================================================================
; Name ..........: _ConnectSet
; =========================================================================================================
Func _ConnectSet($i_CommPort)

    Global $uPort = GUICtrlRead($i_CommPort)

    If $uPort = "" Then
        SoundPlay($SoundFile) ; Error Alert
        _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 255)
        _GUICtrlRichEdit_AppendText($g_hRichEdit, "Please Enter a ComPort." & @CRLF)
        _GUICtrlRichEdit_AppendText($g_hRichEdit, "---------------------------------------" & @CRLF)
        $ClickConnect = 0 ; Connection Flag - no connection
        Return
    EndIf

    Local Const $iPort = "" & $uPort & ""
    Local Const $iBaud = "115000"
    Local Const $iParity = "0"
    Local Const $iByteSize = "8"
    Local Const $iStopBits = "1"

    $ClickConnect = 1 ; Connection Flag - connection established

    Global $hFile = _CommAPI_OpenCOMPort($iPort, $iBaud, $iParity, $iByteSize, $iStopBits) ; Ref commAPI

    _CommAPI_ClearCommError($hFile)
    If @error Then Exit SetError(@error, @ScriptLineNumber)

    _CommAPI_PurgeComm($hFile)
    If @error Then Exit SetError(@error, @ScriptLineNumber)

    _CommAPI_TransmitString($hFile, "*IDN?" & @CR) ; _CommAPI_TransmitData(Const $hFile, Const $sData)
    Local $sResult = _CommAPI_ReceiveString($hFile, 1000) ;_CommAPI_ReceiveString(Const $hFile[, $iTimeout = 1[, $iMaxLength = 0[, $sSeparator = ""]]])

    If Not $sResult = "" Then
        $ClickConnect = "1"
    Else
        $ClickConnect = "0"
    EndIf

    _CommAPI_ClearCommError($hFile)
    If @error Then Return SetError(@error, @ScriptLineNumber)

    _CommAPI_PurgeComm($hFile)
    If @error Then Return SetError(@error, @ScriptLineNumber)

    _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 16711680)
    _GUICtrlRichEdit_AppendText($g_hRichEdit, $sResult)
    _GUICtrlRichEdit_AppendText($g_hRichEdit, "---------------------------------------" & @CRLF)
EndFunc   ;==>_ConnectSet

; #FUNCTION# ==============================================================================================
; Name ..........: _DisplayPorts
; =========================================================================================================
Func _DisplayPorts($g_hRichEdit)
    Local $sCommPorts = _CommAPI_GetCOMPorts() ; ref https://www.autoitscript.com/wiki/CommAPI_Examples
    Local $uCommPorts = "COM Ports:" & @LF & $sCommPorts & @LF
    _GUICtrlRichEdit_AppendText($g_hRichEdit, "---------------------------------------" & @CRLF & @CRLF)
    _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 16711680)
    _GUICtrlRichEdit_AppendText($g_hRichEdit, $uCommPorts)
    _GUICtrlRichEdit_AppendText($g_hRichEdit, "---------------------------------------" & @CRLF)
    _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 16711680)
EndFunc   ;==>_DisplayPorts

; #FUNCTION# ==============================================================================================
; Name ..........: _UnitSend
; =========================================================================================================
Func _UnitSend($uInput)

    _CommAPI_ClearCommError($hFile)
    If @error Then Return SetError(@error, @ScriptLineNumber)

    _CommAPI_PurgeComm($hFile)
    If @error Then Return SetError(@error, @ScriptLineNumber)

    _CommAPI_TransmitString($hFile, $uInput & @CR) ; _CommAPI_TransmitData(Const $hFile, Const $sData)
    If @error Then Return SetError(@error, @ScriptLineNumber)

    Sleep(500)

    GUICtrlSetData($uInput, "")
EndFunc   ;==>_UnitSend

; #FUNCTION# ==============================================================================================
; Name ..........: _UnitRecieve
; =========================================================================================================
Func _UnitRecieve($StatusMemo)


    Local $sResult = _CommAPI_ReceiveString($hFile, 5000) ;_CommAPI_ReceiveString(Const $hFile[, $iTimeout = 1[, $iMaxLength = 0[, $sSeparator = ""]]]) *1000
    If @error Then Return SetError(@error, @ScriptLineNumber, $sResult)

    Sleep(500)

    If $StatusMemo = "" Then
        _GUICtrlRichEdit_AppendText($g_hRichEdit, $sResult & @CRLF)
        _GUICtrlRichEdit_AppendText($g_hRichEdit, "---------------------------------------" & @CRLF)
    Else
        _GUICtrlRichEdit_AppendText($g_hRichEdit, $StatusMemo & @CRLF)
        _GUICtrlRichEdit_AppendText($g_hRichEdit, $sResult & @CRLF)
        _GUICtrlRichEdit_AppendText($g_hRichEdit, "---------------------------------------" & @CRLF)
    EndIf

    Return $sResult
EndFunc   ;==>_UnitRecieve

; #FUNCTION# ==============================================================================================
; Name ..........: _OutFile
; =========================================================================================================
Func _OutFile()
    $MyDocsFolder = "::{450D8FBA-AD25-11D0-98A8-0800361B1103}" ;Declares The variable $MyDocsFolder
    $savewhere = FileSaveDialog("Save to...", $MyDocsFolder, "Rich Text Files (*rtf)", 2, "10204 Command Test sn") ;opens a dialog where you want to save your file
    If StringInStr($savewhere, ".rtf") Then ;checks if the file extention is already there
        _FileCreate($savewhere) ;creates the file in directory selected (I'm not sure if it's necessary or not)
        $savetofile = _GUICtrlRichEdit_StreamToFile($g_hRichEdit, $savewhere)
    Else ;else adds file extention
        $savewhere = $savewhere & ".rtf"
        _FileCreate($savewhere) ;creates the file in directory selected (I'm not sure if it's necessary or not)
        $savetofile = _GUICtrlRichEdit_StreamToFile($g_hRichEdit, $savewhere)
    EndIf ;Ends the if
EndFunc   ;==>_OutFile

; #FUNCTION# ==============================================================================================
; Name ..........: _SwitchPos($hFile)
; =========================================================================================================
Func _SwitchPos($hFile)

    _CommAPI_ClearCommError($hFile)
    If @error Then Return SetError(@error, @ScriptLineNumber)

    _CommAPI_PurgeComm($hFile)
    If @error Then Return SetError(@error, @ScriptLineNumber)

    _CommAPI_TransmitString($hFile, "SHOW STAT" & @CR) ; _CommAPI_TransmitData(Const $hFile, Const $sData) - Works for show set and show stat
    If @error Then Exit SetError(@error, @ScriptLineNumber)

    Sleep(500)

    $sResult = _CommAPI_ReceiveString($hFile, 1000) ;_CommAPI_ReceiveString(Const $hFile[, $iTimeout = 1[, $iMaxLength = 0[, $sSeparator = ""]]])
    If @error Then Exit SetError(@error, @ScriptLineNumber, $sResult)

    $srString = StringReplace($sResult, @CRLF & @CRLF, @CRLF)
    $srString = StringReplace($srString, "SHOW STAT", "")
    $srString = StringReplace($srString, "ATTN", "")
    $srString = StringReplace($srString, ">", "")
    $srString = StringReplace($srString, @CRLF, "|")
    $srString = StringStripWS($srString, $STR_STRIPLEADING + $STR_STRIPTRAILING + $STR_STRIPSPACES)

    $aSTATtemp = StringSplit($srString, "|", 2)

    Local $cols = 3
    Local $arr[1][$cols]
    Local $cell
    For $ii = 0 To UBound($aSTATtemp, 1) - 1
        $cell = StringSplit($aSTATtemp[$ii], " ", 2)
        ReDim $arr[UBound($arr, 1) + 1][$cols]
        For $jj = 0 To UBound($cell, 1) - 1
            $arr[$ii][$jj] = $cell[$jj]
        Next
    Next
    _ArrayDelete($arr, UBound($arr, 1) - 1)
    _ArrayColDelete($arr, 0)

    $aSTAT = $arr

    Local $num = 0

    $ATTN1 = $aSTAT[1][1]
    GUICtrlSetData($i_Attn1,$ATTN1)
    $ATTN2 = $aSTAT[2][1]
    GUICtrlSetData($i_Attn2,$ATTN2)
    $SW1 = $aSTAT[3][1]
    $SW2 = $aSTAT[4][1]
    $SW3 = $aSTAT[5][1]
    $SW4 = $aSTAT[6][1]
    $SW5 = $aSTAT[7][1]
    $SW6 = $aSTAT[8][1]
    $SW7 = $aSTAT[9][1]
    $SW8 = $aSTAT[10][1]
    $SW9 = $aSTAT[11][1]

    For $i = 0 To UBound($abS1) - 1
        GUICtrlSetBkColor($abS1[$i], 0xFFFBF0)
    Next
    GUICtrlSetBkColor($abS1[$SW1], $COLOR_RED)

    For $i = 0 To UBound($abS2) - 1
        GUICtrlSetBkColor($abS2[$i], 0xFFFBF0)
    Next
    GUICtrlSetBkColor($abS2[$SW2], $COLOR_RED)

    For $i = 0 To UBound($abS3) - 1
        GUICtrlSetBkColor($abS3[$i], 0xFFFBF0)
    Next
    GUICtrlSetBkColor($abS3[$SW3], $COLOR_RED)

    For $i = 0 To UBound($abS4) - 1
        GUICtrlSetBkColor($abS4[$i], 0xFFFBF0)
    Next
    GUICtrlSetBkColor($abS4[$SW4], $COLOR_RED)

    For $i = 0 To UBound($abS5) - 1
        GUICtrlSetBkColor($abS5[$i], 0xFFFBF0)
    Next
    GUICtrlSetBkColor($abS5[$SW5], $COLOR_RED)

    For $i = 0 To UBound($abS6) - 1
        GUICtrlSetBkColor($abS6[$i], 0xFFFBF0)
    Next
    GUICtrlSetBkColor($abS6[$SW6], $COLOR_RED)

EndFunc   ;==>_SwitchPos

 

Share this post


Link to post
Share on other sites
Posted (edited)
ConsoleWrite($sResult)
    $srString = StringReplace($sResult, @CRLF & @CRLF, @CRLF)
    $srString = StringReplace($srString, "SHOW STAT", "")
    $srString = StringReplace($srString, "ATTN", "")
    $srString = StringReplace($srString, ">", "")
    $srString = StringReplace($srString, @CRLF, "|")
    $srString = StringStripWS($srString, $STR_STRIPLEADING + $STR_STRIPTRAILING + $STR_STRIPSPACES)
    ConsoleWrite($srString & @CRLF)
    $aSTATtemp = StringSplit($srString, "|", 2)

Can you insert the 2 Consolewrite lines and check if the output is correct ?

 

And since you use $cols for your columms you should also use it for your loop instead of Ubound($cell, 1) - 1

Edit : Unless you expect a diffrent number of cells every time*

Local $cols = 3
    Local $arr[1][$cols]
    Local $cell
    For $ii = 0 To UBound($aSTATtemp, 1) - 1
        $cell = StringSplit($aSTATtemp[$ii], " ", 2)
        ReDim $arr[UBound($arr, 1) + 1][$cols]
        For $jj = 0 To $cols - 1 ; <===== use $cols
            $arr[$ii][$jj] = $cell[$jj]
        Next
    Next
    _ArrayDelete($arr, UBound($arr, 1) - 1)
    _ArrayColDelete($arr, 0)

 

Edited by Jojo-OP2

Share this post


Link to post
Share on other sites

ok..figured out some of it...When the unit reboots, it sends the name, serial number, and other info back to the script...I didnt filter that info out so it actually was getting added to the show stat array....causing the error...Thanks @Jojo-OP2, used the console....working now to filter the response from the unit!  Thanks @jdelaney, still learning the error checking of arrays!!

Share this post


Link to post
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

×
×
  • Create New...