Jump to content

Recommended Posts

Posted

Hi, I have a script that reads data from a serial port which sends a new line every second. I want to display that so used a GuiCtrlListView to do that. I also set that list to scroll once the system has 20 or more values. At the base of the Window I have put one button (Exit) and code to check to see if the button has been clicked. The data is flowing well from the instrument to my ListView and scrolling once it gets to 20 lines but the Select loop to check for a button press is very slow to react - several seconds, so the data continues to be added to the window well after the Exit button is pressed.

 

This is main loop in the script

while 1
   $Result=_CommGetLine(@CR,10000,10000)
   $Data=StringSplit($Result,@TAB)
      _GUICtrlListView_AddItem($idListview, $Data[1], $I)
      _GUICtrlListView_AddSubItem($idListview, $i, $Data[2], 1)
      _GUICtrlListView_AddSubItem($idListview, $i, $Data[3], 2)
      _GUICtrlListView_AddSubItem($idListview, $i, $Data[4], 3)
      _GUICtrlListView_AddSubItem($idListview, $i, $Data[5], 4)
      _GUICtrlListView_AddSubItem($idListview, $i, $Data[6], 5)
      _GUICtrlListView_AddSubItem($idListview, $i, $Data[7], 6)
      $i=$i+1
      If $I>20 then
         _GUICtrlListView_Scroll($idListview,0,100)
      Endif
sleep(10)
   $idMsg=GUIGetMsg()
;msgbox(1,"Message",$idmsg)
   Select
      Case $idMsg = $GUI_EVENT_CLOSE
         MsgBox($MB_SYSTEMMODAL, "", "Dialog was closed")
         ExitLoop

      case $idMsg=$idButton_Exit
         msgbox(1,"Info","Exit button clicked")
         Exit
   EndSelect
WEnd

Any help most appreciated

George

Posted

Hi,

Thanks for the suggestion.

Hmm! that did seem to be what was needed so added this line of code

AutoItSetOption("GUIOnEventMode",1)

but it made no difference. As it is an option I made sure it was done at the beginning of the script.

George

Posted

Here is something interesting. I uncommented my MsgBox line in the above code so that every time through the loop it presents the value of $idmsg

If I don't set GUIOnEventMode which means it is at the default of 0 then it presents the value of zero (most times) or -11 (2-3 times), every time until I click the "Exit" button when I get another couple of zero values then it goes to -7, then 4 then I get the message associated with that button and script Exits.

If GUIOnEventMode is set to 1 then it always give a value of zero and never gives the message associated with the button and hence never exits.

George

  • Moderators
Posted

GeorgeP,

As currently written, your script will run the _GUICtrlListView_Scroll function on every pass as you never reinitialise the loop variable after a scroll. Rather then scroll every 20 lines, I would suggest ensuring that the last entered line is visible using _GUICtrlListView_EnsureVisible - much more elegant IMHO.

How long does your _CommGetLine function take to return? It may well be that holding up the whole script. Can you check at intervals to see if there is new data ready for entry into the ListView?

Here is an short example script showing how I would arrange for the script to wait for a second while still allowing the exit options to remain active:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <GuiListView.au3>

$hGUI = GUICreate("Test", 500, 500)

$cLV = GUICtrlCreateListView("", 10, 10, 480, 300)
For $i = 0 To 7
    _GUICtrlListView_AddColumn($cLV, "Col " & $i)
Next

$cExit = GUICtrlCreateButton("Exit", 10, 450, 80, 30)

GUISetState()

Global $aData[8]

While 1

    $aData[1] = @SEC
    $aData[2] = @MSEC

    Local $iIndex = _GUICtrlListView_AddItem($cLV, $aData[1], $I)
    _GUICtrlListView_AddSubItem($cLV, $iIndex, $aData[2], 1)
    _GUICtrlListView_AddSubItem($cLV, $iIndex, $aData[3], 2)
    _GUICtrlListView_AddSubItem($cLV, $iIndex, $aData[4], 3)
    _GUICtrlListView_AddSubItem($cLV, $iIndex, $aData[5], 4)
    _GUICtrlListView_AddSubItem($cLV, $iIndex, $aData[6], 5)
    _GUICtrlListView_AddSubItem($cLV, $iIndex, $aData[7], 6)

    _GUICtrlListView_EnsureVisible($cLV, $iIndex)

    $nBegin = TimerInit()
    Do
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                MsgBox($MB_SYSTEMMODAL, "", "Dialog was closed")
                Exit
            Case $cExit
                MsgBox(1, "Info", "Exit button clicked")
                Exit
        EndSwitch
    Until TimerDiff($nBegin) > 1000

WEnd

Rather then using a timer, you could perhaps check in the Until line whether there is any data ready for processing and then proceed if so.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

Hi Melba23,

Thanks for the suggestions will try them later today. The script I wrote was just the initial bare bones of a project so will need some tiding up before completed. I like your idea of  _GUICtrlListView_EnsureVisible and the timer

The instrument providing the serial data feed produces one line per second so heaps of time to do processing.

Regards

George

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
  • Recently Browsing   0 members

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