Jump to content

Continuous Polling


Recommended Posts

Hi there all!! Writing a script that uses VISA.udf to configure and read data from a Keysight U2000A USB Average Power Sensor. Everything is peachy except im not sure how to make the reading continuous...and still be able to send other configuration commands. i.e. have "real time" power readings and switch between other configuration options like the step detection, frequency, averaging modes, etc...

I havent writen the measurement function yet, since im not sure how to implement it. Any clue where to start would be great! No need to write code, just point in the right direction!!

Obligatory code!

; -- Created with ISN Form Studio 2 for ISN AutoIt Studio -- ;
#include <StaticConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiButton.au3>
#include <EditConstants.au3>
#include <ComboConstants.au3>
#include <Visa.au3>
#include <MsgBoxConstants.au3>
#include <GuiRichEdit.au3> ; Color Notes ...: Green = 65280 , Red = 255 , Blue = 16711680

;HMMM
;_viInteractiveControl()

; Presets
; Min = -90
; Max = -56
; Zero = Internal (INT)
; Mode = Average only (AVG only)
; Frequency = 50.0 M
; Averaging Mode = AUTO
; Averaging Count = 4
; Step Detect = Checked
; Unit = dBm
; Trigger = Free Run

; Variables
$PowerMeter = "USB0::0x0957::0x2A18::MY54480009::INSTR"
$h_session = 0
$h_instr = _viOpen($PowerMeter)
$ZeroModeFlag = 0 ;0 = Ext / 1 = Int
$StepDetectFlag = 0 ; 0 = Disables / 1 = Enabled

; Main Gui
$g_Core = GUICreate("HP Power Meter", 719, 457, -1, -1, -1, -1)
GUISetBkColor(0x060606, $g_Core)
GUICtrlCreateLabel("Calibration", 70, 40, 97, 22, -1, -1)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, "0xFFFFFF")
GUICtrlSetBkColor(-1, "-2")
GUICtrlCreateLabel("Zero Type:", 31, 80, 79, 20, -1, -1)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, "0xFFFFFF")
GUICtrlSetBkColor(-1, "-2")
$cb_Int = GUICtrlCreateCheckbox("Internal", 120, 80, 17, 20, -1, -1)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, "0xFFFFFF")
GUICtrlSetBkColor(-1, "0x060606")
GUICtrlCreateLabel("INT", 140, 80, 50, 15, -1, -1)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, "0xFFFFFF")
GUICtrlSetBkColor(-1, "-2")
GUICtrlSetData($cb_Int, $GUI_CHECKED)
$cb_Ext = GUICtrlCreateCheckbox("My Text", 181, 80, 17, 20, -1, -1)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, "0xFFFFFF")
GUICtrlSetBkColor(-1, "0x060606")
GUICtrlCreateLabel("EXT", 198, 80, 50, 24, -1, -1)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, "0xFFFFFF")
GUICtrlSetBkColor(-1, "-2")
$b_Zero = GUICtrlCreateButton("Zero", 70, 108, 100, 30, -1, -1)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, "0xFFFFFF")
GUICtrlCreateLabel("Channel Setup", 50, 170, 136, 23, -1, -1)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, "0xFFFFFF")
GUICtrlSetBkColor(-1, "-2")
GUICtrlCreateLabel("Mode:", 93, 206, 44, 26, $SS_RIGHT, -1)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, "0xFFFFFF")
GUICtrlSetBkColor(-1, "-2")
GUICtrlCreateLabel("Frequency (Hz):", 23, 252, 114, 24, $SS_RIGHT, -1)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, "0xFFFFFF")
GUICtrlSetBkColor(-1, "-2")
GUICtrlCreateLabel("Averaging Mode:", 11, 296, 129, 25, $SS_RIGHT, -1)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, "0xFFFFFF")
GUICtrlSetBkColor(-1, "-2")
GUICtrlCreateLabel("Step Detect:", 46, 344, 91, 22, $SS_RIGHT, -1)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, "0xFFFFFF")
GUICtrlSetBkColor(-1, "-2")
GUICtrlCreateLabel("Trigger Mode:", 31, 384, 109, 22, $SS_RIGHT, -1)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, "0xFFFFFF")
GUICtrlSetBkColor(-1, "-2")
$combo_Mode = GUICtrlCreateCombo("", 145, 201, 150, 25, -1, -1)
GUICtrlSetData(-1, "AVG only|Normal")
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$i_Frequency = GUICtrlCreateInput("My Text", 145, 252, 89, 25, -1, $WS_EX_CLIENTEDGE)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$combo_Measurement = GUICtrlCreateCombo("", 243, 249, 68, 28, -1, -1)
GUICtrlSetData(-1, "k|M|G")
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$combo_AvgMode = GUICtrlCreateCombo("", 145, 293, 150, 28, -1, -1)
GUICtrlSetData(-1, "AUTO|MANUAL|OFF")
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$cb_StepDetect = GUICtrlCreateCheckbox("My Text", 147, 344, 17, 20, -1, -1)
GUICtrlSetBkColor(-1, "0x060606")
GUICtrlSetState(-1, $GUI_CHECKED)
$combo_TrigMode = GUICtrlCreateCombo("", 145, 378, 150, 25, -1, -1)
GUICtrlSetData(-1, "Mein Text")
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$i_Reading = GUICtrlCreateInput("My Text", 401, 80, 228, 60, BitOR($ES_CENTER, $ES_READONLY), $WS_EX_CLIENTEDGE)
GUICtrlSetFont(-1, 25, 400, 0, "MS Sans Serif")
$g_hRichEdit = _GUICtrlRichEdit_Create($g_Core, "", 364, 193, 307, 213, _
        BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY))
GUICtrlSetFont(-1, 9, 400, 0, "MS Sans Serif")

GUISetState(@SW_SHOW)

_viExecCommand($h_instr, "*RST", 4000) ; Places the U2000 Series power sensor in a known state.

$s_IDNQ = _viExecCommand($h_instr, "*IDN?", 10000) ; Allows the U2000 Series power sensor to identify itself.

_viExecCommand($h_instr, "*CLS", 4000) ; The SCPI registers (Questionable Status, Operation Status, and all the other SCPI registers),
; the Standard Event Status Register, the Status Byte, and the Error/Event Queue are all cleared.

$s_SystErrQ = _viExecCommand($h_instr, "SYST:ERR?", 10000) ; Checks the U2000 Series power sensor system error queue.

_GUICtrlRichEdit_AppendText($g_hRichEdit, $s_IDNQ & @CRLF)
_GUICtrlRichEdit_AppendText($g_hRichEdit, $s_SystErrQ & @CRLF)

_viExecCommand($h_instr, "*CLS", 4000)

; Check CAL Type ======================================================================================================================
$s_CALQ = _viExecCommand($h_instr, "CAL:ZERO:TYPE?", 10000) ; This query returns the current zeroing type, either “INT” or “EXT”.

_GUICtrlRichEdit_AppendText($g_hRichEdit, "Zeroing/CAL = " & $s_CALQ & @CRLF)

$s_slCALQ = StringLeft($s_CALQ, 3)

If $s_slCALQ = "INT" Then
    GUICtrlSetState($cb_Int, $GUI_CHECKED)
    $ZeroModeFlag = 1
    GUICtrlSetState($cb_Ext, $GUI_UNCHECKED)
Else
    GUICtrlSetState($cb_Ext, $GUI_CHECKED)
    $ZeroModeFlag = 0
    GUICtrlSetState($cb_Int, $GUI_UNCHECKED)
EndIf
; ===============================================================================================================================================

; Check Step Detect Status ======================================================================================================================
$s_StepDetect = _viExecCommand($h_instr, "AVER:SDET?", 10000) ; Queries whether step detection is on or off.

If $s_StepDetect = 0 Then
    GUICtrlSetState($cb_StepDetect, $GUI_UNCHECKED)
    $StepDetectFlag = 0
Else
    GUICtrlSetState($cb_StepDetect, $GUI_CHECKED)
    $StepDetectFlag = 1
Endif
; ===============================================================================================================================================

; Check Format
$s_Format = _viExecCommand($h_instr, "FORM?", 10000) ;
_GUICtrlRichEdit_AppendText($g_hRichEdit, "Data Formated to " & $s_Format & @CRLF)                  ; Data Format = ASC<NR3> / REAL
$s_FormatBord = _viExecCommand($h_instr, "FORM:READ:BORD?", 10000)
_GUICtrlRichEdit_AppendText($g_hRichEdit, "Current byte order setting is " & $s_FormatBord & @CRLF) ;Byte Order = NORM / SWAP

_IntCal() ;This query causes the U2000 Series power sensor to perform a zeroing and return a result.

While 1
    $msg = GUIGetMsg()
    Switch $msg

        Case $GUI_EVENT_CLOSE
            _viClose($h_instr)
            Exit
        Case $cb_Int
            If _IsChecked($cb_Int) Then ;0 = Ext / 1 = Int
                $ZeroModeFlag = 1
            Else
                $sZeroModeFlag = 0
            EndIf
        Case $cb_Ext
            If _IsChecked($cb_Ext) Then ;0 = Ext / 1 = Int
                $ZeroModeFlag = 0
            Else
                $sZeroModeFlag = 1
            EndIf
        Case $b_Zero
            If $ZeroModeFlag = 1 Then
                _IntCal()
            Else
                _ExtCal()
            EndIf
        Case $cb_StepDetect
            If _IsChecked($cb_StepDetect) Then
                _viExecCommand($h_instr, "AVER:SDET ON", 10000) ; Queries whether step detection is on or off.
            Else
                _viExecCommand($h_instr, "AVER:SDET OFF", 10000) ; Queries whether step detection is on or off.
            Endif
        ;Case $combo_AvgMode



    EndSwitch
WEnd

Func _IsChecked($idControlID)
    Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED
EndFunc   ;==>_IsChecked

Func _IntCal()
    _viExecCommand($h_instr, "CAL:ZERO:TYPE INT", 10000)
    $s_CAL = _viExecCommand($h_instr, "CAL?", 20000) ;This query causes the U2000 Series power sensor to perform a zeroing and return a result.
    _GUICtrlRichEdit_AppendText($g_hRichEdit, $s_CAL & @CRLF)
    If $s_CAL = 0 Then
        _GUICtrlRichEdit_AppendText($g_hRichEdit, "Zeroing has passed." & @CRLF)
    Else
        _GUICtrlRichEdit_AppendText($g_hRichEdit, "Zeroing has failed." & @CRLF)
    EndIf
EndFunc   ;==>_IntCal

Func _ExtCal()
    _viExecCommand($h_instr, "CAL:ZERO:TYPE EXT", 10000)
    $s_CAL = _viExecCommand($h_instr, "CAL?", 20000) ;This query causes the U2000 Series power sensor to perform a zeroing and return a result.
    _GUICtrlRichEdit_AppendText($g_hRichEdit, $s_CAL & @CRLF)
    If $s_CAL = 0 Then
        _GUICtrlRichEdit_AppendText($g_hRichEdit, "Zeroing has passed." & @CRLF)
    Else
        _GUICtrlRichEdit_AppendText($g_hRichEdit, "Zeroing has failed." & @CRLF)
    EndIf
EndFunc   ;==>_ExtCal

 

Link to comment
Share on other sites

  • Developers

Maybe adding an AdlibRegister() after having created the GUI with Controls, and have that Func update the power reading each xxxx mseconds?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

It actually is pretty strait forward: With AdlibRegister() you "schedule" a Func to be run each xxx msecs as defined in the second parameter.
The only thing to remember is that Autoit3 is single threaded, so the current process is interrupted for the period the Func runs.

Jos 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...