Please enable JavaScript to view this site.

DAQFactory User's Guide

Navigation: 5 Sequences & Scripting

5.27 System Functions & Variables

Scroll Prev Top Next More

There are quite a few useful system functions and variables available from within sequences to help you develop your application.  

SendMessage(Message, [Param1], [Param2]): this function sends a message to all the screen components that are listening for the given message.  Please see the section in Pages and Components that discusses user components and component functions for more information.

StartThread(Function, [Name = ""], [Priority = 3]): this function will start the given function (specified as a string) in a new thread.  Its similar to sequence.mySequence.begin() except that you can create multiple threads for a single sequence function, and you can pass parameters when starting the thread.  The disadvantage of using this method is that you have no feedback or control over the thread except through the following two functions.  There is no indication in the workspace that your thread is running and you cannot debug the thread.  Function should be a string with the function call with parameters.  Name can be any valid DAQFactory name and is used for stopping or getting the status of the thread.  You should make sure your threads have unique names.  You do not have to name your thread, but you won't be able to stop or get the status of the thread.  The function will either need to reach its end, which kills the thread, or you'll need to quit DAQFactory or load another document.  Priority matches the numbers listed in the drop down when editing a sequence, where 0 is the lowest, and 5 the highest priority.  Example: StartThread("MyFunction(x,3)",MyThread,5)  Note that the function call MUST be a string.

StopThread(Name): Stops the given thread if it is running.  

GetThreadRunning(Name): Returns a 1 if the thread exists and is running, and 0 if not.

GetThreadStatus(Name): Returns a string with the current status of the given thread, or a message indicating that the thread doesn't exist.  The current status string is similar to the string in the sequence table and includes the current function and line being executed.

Note: when creating a user component or user object, you can also use the StartLocalThread(), StopLocalThread(), GetLocalThreadRunning() and GetLocalThreadStatus() functions.  These functions work the exact same way, but the thread runs in the context of the component or object and will automatically terminate if the component or object is deleted.  You can also use the same thread name in different components.  User components and objects can use the above global functions, but the created thread will run in the global context and won't be encapsulated in the user component or object.

The following functions all start with System..  Some of these functions must be called from the main application thread, which means they really can only be called from an event of many components.  

Variables:

System.AppDate: returns the time stamp when the document was last saved.  This is in DAQFactory time, seconds since 1970.

System.AppPath: returns the full path to the DAQFactory executable as a string.  For example, "c:\DAQFactory\DAQFactory.exe"

System.AppVersion: set or read the version number of your application.  You can use this to do versioning of your application.  By default, a new application is assigned version number 1.0 and every time you save, it will increment this number by 0.01.  You can alternatively set this variable to any version number you want.  The first time you save after assigning this variable a value, the version number won't be incremented and the value you specified will be used. After that, the number will be automatically incremented.

System.DisplayCursor:  set to display or hide the Windows cursor.  This is useful for touch screen applications where a cursor is not desired.  Set to 1 (the default) to display the cursor.  Set to 0 to hide it.  Note that this does not affect cursors in other applications, just DAQFactory.

System.FullScreen:  set to 1 to switch to full screen, and to 0 to get out of full screen.  This is a write-only variable.

System.SafeMode: returns 1 if in safe mode, or 0 if not.  Can be set to 1 to enable set mode, but cannot be set to 0.  The only way to leave safe mode is through the DAQFactory menu.  This is for security reasons.  

System.ShowPaintMouseErrors: if 0 (the default), then any script errors in MouseMove or Paint component events are not sent to the command / alert window.  To see these errors, set this variable to 1.  MouseMove and Paint events can occur very rapidly and any error can cause a continuous stream of repeated errors in the Command / Alert Window.  This variable stops that.

System.SequencePrint: set to 1 (the default) to enable the ? statement in a sequence.  Set to 0 to have all ? statements in all sequences ignored.

Functions:

System.SecondInstanceCheck(name): returns 1 if this is the first instance that has used this name, otherwise 0.  Use this to make sure that you haven't started your application multiple times on the same computer.

System.Quit(): call this function to quit DAQFactory.

System.Reboot(): call this function to reboot the local computer.  There is no way to stop the reboot.  There is a 30 second delay before it occurs.

System.Shutdown(): call this function to shutdown the local computer.  There is no way to stop the shutdown.  There is a 30 second delay before it occurs.

System.GetDAQFactoryMemoryUsage(): call this function to retrieve the current DAQFactory memory usage.  The numbers provided are pretty technical but do give you a general idea on how the application is doing memory wise.  This function returns an object with the following member variables: WorkingSetSize, PeakWorkingSetSize, PagefileUsage, PeakPagefileUsage, and PageFaultCount.

System.GetDAQFactoryVersion(): call this function to retrieve details about the DAQFactory executable build.  This is useful for version control when you have DAQFactory running on multiple systems.  This function returns an object with the following member variables: BuildNumber, MajorRelease, MinorRelease and Version.

System.GetWindowsVersion(): call this function to retrieve details about the version of Windows DAQFactory is running in.  This function uses details in the Windows registry to retrieve this information.  The function returns an object with the following member variables: BuildNumber, DisplayRelease, Edition, MajorRelease, MinorRelease, ProductNumber.  

System.IsDST(): call this function to retrieve the current Daylight Savings Time setting of the system.  Returns 1 if DST would be in effect for the current DAQFactory time, and 0 if not.  Please note: DAQFactory does not adjust for DST no matter what the system settings.  DAQFactory picks up the Windows system time at startup and then after that uses a high precision counter to determine the time.  Any changes to the Windows system time, including DST, will not affect DAQFactory time.  If DST is in effect when DAQFactory starts, all time in DAQFactory will be DST until you restart.  The IsDST() function simply looks at the current DAQFactory time and determines from it if it is the time of year when DST would be in effect or not.

System.IsRuntime(): call this function to determine if we are in runtime mode or not.  Returns 1 if in runtime, 0 if in development.

System.SaveDocument(): calling this function does the same thing as hitting File - Save from the main menu.  It is designed to be used in runtime mode to save user component properties, and thus make user runtime configurable components.  

System.SaveWithData(): calling this function does the same thing as hitting File - Save with Data from the main menu.  

System.HideSystemMenu(): call this function to hide the system menu from the title bar of DAQFactory.  This would mostly be used in Runtime mode to keep a user from exiting the application.  Make sure you provide an on-screen button or other method to quit your application.

System.Maximize(): call this function to expand the DAQFactory window to take up the entire screen, similar to clicking the Maximize button on the window.  This is not the same as Full Screen mode which doesn't display the Windows title bar.

System.Minimize(): call this function to minimize your DAQFactory window.

System.DeviceConfigDialog(): call this function to display the Device Configuration dialog.  This must be done from the main application thread.

System.Connection.Add(Name,Address,[Password],[Fullstream]): the last two parameters are optional and default to blank and 0.  Creates a new connection (provided one with the same name does not already exist) with the given name, address, password and fullstream setting (0 or 1)

System.Connection.Reset(Name): Resets the given connection.  Closes the connection then attempts to reconnect.  This does the same thing as clicking the Reset Connection button in the connection view.

System.Connection.Delete(Name): deletes the named connection if it exists.  You can’t delete the Local or V connection.  If you want to create a runtime that connects to a computer with a varying IP address, call Delete followed by Add with the new IP address and same connection name.

Application: The above three functions can be used in the runtime version of DAQFactory to connect to an unknown remote computer.

System.Connection.Default(Name): sets the default connection to the given Name. For example: System.Connection.Default("Local")

System.ShellExecute(File, [Operation], [Parameter], [Path], [Show]): Performs a system shell command allowing you to start other programs from within DAQFactory.  This calls the Windows API ShellExecute command.  

File can be an executable file, folder, or a document provided the document extension is assigned to an application (i.e. MyDoc.txt would probably run Notepad). File is the only required parameter.  

Operation is a string and can be:

"edit": launches an editor and opens the file for editing. File must be a document and not an executable.

"explore": opens the folder specified in File in Explorer.

"open": opens the specified File.  In this case, the file can be an executable (which will be run), a document or folder.  This is the default.

"print": prints the document specified by File. File must be a document.  

Parameter is used if File is an executable and determines which command line parameters are passed to the executable.  It is a string and defaults empty.

Path is the default directory used.  It is a string and defaults empty.

Show determines how the shell will display itself.  It is a string and can be:

"hide": does not display the executable at all, not even in the Windows task bar.  If the executable does not automatically terminate itself, the only way to stop it is  using the Processes tab of the Windows Task Manager.  This setting is best used when printing documents.

"minimize": opens File, but minimizes it.

"maximize": opens File and maximizes the window.

"normal": opens File in whatever way it normally opens.  This is the default setting.

"noactivate": same as normal, but DAQFactory remains on top and in focus.

System.Sound.Play(.wav file name):  plays the given wave file.  If a file is currently playing, that sound will stop and the new one will start

System.Sound.Stop(): stops any playing sound

System.DelayUpdate(): causes the system to stop redrawing the current page.  This is useful if you want to move a number of components around at once without having the user see each individual component move.  Use ResumeUpdate() to continue drawing the screen.

System.ResumeUpdate(): allows the system to continue updating the current page.  We strongly recommend using a try/catch block around a DelayUpdate / ResumeUpdate pair to ensure that pages are updated if there is an error:

 

try

   System.DelayUpdate()

   ... do a bunch of stuff

   System.ResumeUpdate()

catch()

   System.ResumeUpdate()

endcatch

System.SetFocus(): forces the system focus back to the Page view of DAQFactory.  It does not switch the view, so if you are not viewing a Page, this function doesn't do much.  This function is primarily designed for use with the browser component.  There are instances when the browser component will take focus away from the page it is on which will cause mouse and keyboard events that you might be trying to capture to be directed to the browser instead of to DAQFactory.  Calling SetFocus will restore focus to the DAQFactory page and allow those events to be capture by your script.

System.ColorSelectDialog() : displays the standard color selection dialog and returns the selected color or an empty value if the user hits cancel.  

System.EntryDialog(Prompt, [RangeMin],  [RangeMax], [DefaultValue], [HelpFile]): displays a dialog to request a value from the user.  All parameters except Prompt are optional.  The prompt is what is displayed in the box. RangeMax/Min are optional checks on the user input. DefaultValue is the value initially displayed in the edit box. HelpFile is the name of an HTML help file to display below the dialog.  This can either be a fully specified path, or relative to the DAQFactory installation.  The resulting string value is returned, or an empty value if the user hits cancel.  

System.PasswordEntryDialog(Prompt, [Title]): this is similar to EntryDialog(), but for entering *'ed out passwords.

System.HelpWindow(HTML file, [x1], [y1], [x2], [y2]): displays a window with the specified HTML file. X1, Y1, X2, Y2 determine the coordinates of the window.  The default is centered.

System.MessageBox(Message, [Type], [Help]): this displays a standard windows message box, or a DAQFactory style message box with help.  The first parameter is required, the others are optional.  The message is what is displayed in the box.  The type can be one of the following:

"Help", "AbortRetryIgnore", "OKCancel", "RetryCancel","YesNo", or "YesNoCancel"

These determine what buttons are displayed.  The default and "Help" just display an OK button.  If the "Help" type is selected, the Help parameter should contain either the DAQFactory installation path relative or absolute path to an HTML help file to display.  This function returns one of the following depending on which button the user presses:

"OK", "Cancel", "Ignore", "No", "Yes", "Abort", or "Retry"

System.ErrorMessage(Message): this generates an Alert within DAQFactory with the given message.  This does not generate an error within a sequence, but just sends the given message to the Alert window.  To generate a catchable error in sequence code, use throw().

System.MessagePump(): this function services the windows message pump.  This is a somewhat advanced function.  The windows message pump is what handles things like mouse clicks and the like.  If you have a quick sequence in a screen component, or you call a sequence as a function from a screen component action, then the script runs in the primary thread of the application.  This is the same thread that handles the message pump for DAQFactory, so while the script is running, DAQFactory will appear "hung" because it won't respond to mouse clicks or anything else.  It isn't hung, its just busy running your script.  You can avoid this by servicing the message pump rather often (say at least every 0.1 seconds) simply by calling this function.  If your script is really fast and finishes quickly, than this function is not needed, but if you really want to do something that takes a while from the primary thread, this function is available.

Notes:

Although you can call most of the above functions from a sequence, for the ones that require a user response (MessageBox(), HelpWindow(), EntryDialog() and ColorSelectDialog()) you must be very careful.  First of all, having windows popup without the user clicking on something can be annoying to the user, but there are other issues:

Two big things to watch for are loops that repetitively call these functions, and using the wait() function.  The best way to show the potential problem is with examples:

 

while (1)

  page.page_0.backcolor = System.ColorSelectDialog()

   .. some other quick stuff

   delay(1)

endwhile 

In the above loop, the user will essentially be prompted for a color every second.  Because the delay is so short, and the color select box is modal, meaning the user can't access the reset of DAQFactory while it is displayed, the user won't be able to stop the sequence because the color box will redisplay every second.

This is compounded more if you use a wait() function instead of delay because the wait() will go to 0 because the user interface is slow, and the user will be continually prompted and will not be able to escape.  So, in general NEVER use wait() in a sequence that contains one of these user interface functions.

A few other things to think about:

- If another sequence stops a sequence that is waiting for a user response, the sequence will stop, but the window requesting the user response will remain.  When the user closes this window, any return value is discarded

- If another sequence calls one of these functions while a window is already displayed, the new window will appear on top and will have to be dismissed before the user can get back to the first one.