GeorgeP Posted January 24, 2022 Posted January 24, 2022 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
Nine Posted January 24, 2022 Posted January 24, 2022 Make it OnEvent Mode. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy
GeorgeP Posted January 25, 2022 Author Posted January 25, 2022 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
GeorgeP Posted January 25, 2022 Author Posted January 25, 2022 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
Nine Posted January 25, 2022 Posted January 25, 2022 Refer to event mode in there : https://www.autoitscript.com/wiki/Managing_Multiple_GUIs “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy
Moderators Melba23 Posted January 25, 2022 Moderators Posted January 25, 2022 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: expandcollapse popup#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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
GeorgeP Posted January 25, 2022 Author Posted January 25, 2022 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now