Jump to content
Sign in to follow this  

Wait Until Variable Contains Data

Recommended Posts


So it's been a long time since I've done any scripting, and even back then I probably wouldn't have known the answer to this.

Long story short I'm trying to log data from a COM port by using plink...I've gotten it setup to where I can launch plink and access the STDOUT and ultimately log it to a file. Eventually I'll be placing it a few places, but this is still proof of concept.

Here is the current code:

#include <Array.au3>
#include <Constants.au3>
#include <String.au3>
$_PlinkHandle=Run(@ComSpec&" /c "&@ScriptDir&"\"&$sPlink&" "&$sSession,"",@SW_SHOWDEFAULT,7)
While 1
If $sData<>"" Then

So I'm pretty sure that's not the best way to go at it...Without that Sleep(1000) it chews up 12% of my quad core CPU, and without that $sData<>"" it just fills the log file with whitespace.

The problem is that this is receiving data at any random time (It's logging PBX call data) so I'm not sure the best way to handle it. I was thinking if there is a way to wait until the variable contains data, and maybe key in on the LF/CR. The way I see this there is the potential to get the data split across two lines since it could hit the sleep right in the middle of getting the data.

Totally open to a better way of doing this, I'm comfortable in my noobness when it comes to scripting. I've been at this for a few hours (Don't worry, it started with messy MsgBox's and has quickly progressed to this point...Had to get back in sync) and I'm just out of steam.

Also, since this may impact your response, the idea is this stays running 24/7 and just collects the data that the PBX sends after each call. There could be a bunch in a row (I haven't been able to simulate that yet, not too worried though) at any random interval. One thing I was worried about is if the variable containing the data would grow out of control over time. So far it seems like in my loop that after each FileWriteLine it's emptied?

Share this post

Link to post
Share on other sites

maybe this is the solution

Global $Var
AdlibRegister('CheckVar') ;Function which will be called every 250ms to check $Var
While 1

Func CheckVar()
If $Var Then
ConsoleWrite('VarContains Data'&@CR) ;Say the user that the Var contains data
AdlibUnRegister('CheckVar') ;Unregister the Function
Exit -1 ;Exit with the Code -1

feel free to ask any doubts


Phoenix XL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

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
Sign in to follow this