Object generation 5.30 comes with some more script functions supporting error handling. We have generated a simple demo application in CODE which looks like this:
While some measurement routines (list of spectrometers) and other procedures produce error messages by themselves you can generate error message by a script command:
- raise error message,0,1,This is wrong – user tried do divide by 0
- raise error message,0,2,This is a warning only ..
Here the first integer parameter indicates the type of error, the second one the classification. ‘1’ means ‘critical error’, ‘2’ stands for warning.
The script command ‘verify function value’ automatically raises an error message if the condition the function value is out of range. You can add the keyword ‘silent’ to suppress a dialog popping up – in this case the classification is ‘Warning’. Without the keyword you get a dialog and classification ‘critical error’:
- verify function value,of(1),0.3,0.4,reflectance maximum,silent
- verify function value,of(1),0.3,0.4,reflectance maximum
Error messages get a timestamp and are collected in an array until the script command ‘clear error messages’ is executed.
If you use CODE to acquire spectra with a spectrometer object you can generate measurement reports which collect all measured spectra for a sample – these are JSON files. Should there be warnings issued by the measurement scripts the corresponding error messages are stored in the ‘error section’ of the JSON files as well.
The new view element ‘error messages view’ shows error messages in a view.
The new OLE command export_spectra_via_variants has been introduced in both SCOUT and CODE (object generation 5.14). The command takes 5 parameters:
- input: the index of the spectrum object in the list of spectra (counting 1, 2, 3, …)
- output: a variant array holding the spectral positions (e.g. wavelengths)
- output: a variant array with simulated spectral values
- output: a variant array with measured spectral values at the same spectral positions as the simulated values, obtained by linear interpolation between the closest available points
- output: a string with the spectral unit
In object generation 4.97 we have implemented a new mechanism to pass error messages from SCOUT and CODE to OLE automation clients.
While it runs the OLE server (i.e. SCOUT or CODE) collects error messages in a list. We have introduced a view object (type ‘Error messages view’) to display the current list of error messages in a view.
Any OLE client (LabView, Excel, …) can retrieve information about the number of error messages, their type and text content. There is also a classification to separate critical errors and warnings. Once the OLE client has finished error handling it can clear the list in the OLE server.
When I try to start the software I get the message: ‘This program can be used as OLE server only!’. What does that mean?
The program has been installed with a passport file which allows to run the program as OLE server only. It cannot be started as a normal desktop application.
Very likely you have downloaded the software from our website and installed it on your system. The download packages do not contain valid passport files, i.e. valid user licences. After the installation, you have to copy a valid passport file into the program directory.
In the case of SCOUT, the passport file is called scout_passport.wtp. If you installed CODE the name is code_passport.wtp.
In the case of a software purchase you should have received a passport file from us either by e-mail or with the setup CD. If you are evaluating the software you should have received a passport file with a demo licence by e-mail.
I try to use CODE in VisualBasic but I get the error message ‘ActiveX can’t create the object’?
First check if the name of the OLE automation server in the VisualBasic command is correct. The server name of CODE is ‘code.colors’.
If this does not solve the problem, the registration of the OLE automation server is probably incorrect for some reason. When you run the setup program, CODE is registered as OLE automation server automatically. If this action failed, a call of the server in VisualBasic does not work. In this case you can do the registration manually.
Start a Windows command line by clicking on the Windows key on your keyboard followed by the letter ‘r’ (for run). You must have administrator rights to do registrations. If you are logged-in as a normal user, you can right-click the command line in ‘Start/accessories’ and select the option ‘Run as administrator’. Once the command line is available, type in the command
“c:\program files\code.exe” /regserver
where you should make sure that you use the double quotes as shown. The path of the program file code.exe must be adapted to your system, of course, i.e. it should point to the location of your code program.
If you work with different CODE versions on one computer, you might want to use the command
in order to explicitly de-register a code program as OLE server.