A specific example can be looked up in section 11.2
Remarks
• Old JScripts
If you use old JScripts for DOASIS that were programmed for an older version of
DOASIS, it might happen that the script won’t run if they use the dispTools-, dispIO
or other disp-Objects. These objects are not supported and replaced by equivalent
functions in newer DOASIS-Versions.
However, if you want to use these old scripts nevertheless, you can create a project file
referencing the ”system.js” and the old script. Then, also old scripts will run without
problems. But there is no guarantee.
50
Chapter 10
JScripts communicating with
hardware
10.1
Reading in data from a serial port (e.g. GPS data)
The following script was developed in order read in the signal of a GPS device. In this
example, only the data from the GPS is displayed in the Output window. In order to
extract the position coordinates and time, specified parts of the data have to be used. This
will not be shown here.
51
import System;
// namespace to access the serial port
import System.IO.Ports;
// namespace to abort the script by pressing the "Stop" button
import DoasCore.Script;
var signal;
// specify the properties of the port and the data transfer
var serial = new SerialPort();
serial.PortName = "COM5";
serial.BaudRate = 57600;
serial.DataBits = 8;
serial.Handshake = Handshake.None;
serial.Parity = Parity.None;
serial.StopBits = StopBits.One;
// opens a new serial port connection
serial.Open();
// as long as the "Stop" button is not pressed, the loop is executed
while(!Script.StopAllScripts)
{
// read in one line of the serial port output
signal = serial.ReadLine();
// display it
Console.WriteLine(signal);
}
// closes the port connection
serial.Close();
Remarks
• The output of the GPS used here consisted of a sequences of 6, which are continuously
produced:
GPRMC,135257.000,V,4925.0709,N,00840.4109,E,0.00,0.00,120608,,,N*78
GPGGA,135257.000,4925.0709,N,00840.4109,E,0,00,99.9,249.6,M,48.0,M,,0000*62
GPGSA,A,1,,,,,,,,,,,,,99.9,99.9,99.9*09
GPGSV,2,1,08,10,39,197,,27,15,070,,07,06,069,,18,09,324,*7B
GPGSV,2,2,08,15,53,298,,09,03,253,,19,07,027,,08,42,063,*7F
The first line starting with GPRMC provides information about time (13h 52min
57s UTC), latitude 49
◦
25.0709
′
and longitude 8
◦
40.4109
′
. For more information
search the internet for the NMEA (National Marine Electronics Association) standard
protocol.
• To extract specific characters out the lines, the command signal.Substring(x,y) can
be used. It provides part of the string “signal” which starts at a specified character
position x and has a specified length y.
52
Figure 10.1: Scan button (marked red) to record a spectrum manually.
10.2
Measure a spectrum with an Ocean Optics spec-
trograph
Before running the script, make sure that you get connection to the spectrograph manually
via DOASIS by pressing the Scan button (see Fig. 10.1).
This script was tested with an Ocean Optics HR2000 spectrograph but should work with
any other spectrograph of Ocean Optics as well.
import System;
import DoasCore.Spectra;
// the namespace "Device" enables the usage of external devices
import DoasCore.Device;
// open an empty spectrum in the specbar
var MeasSpec = Specbar.GetSpectrum("MeasSpec");
var ScanNumber = 10;
var Inttime = 100;
// create a new ocean optics spectrograph object
var Spectrograph = new OceanOptics();
// assign the serial number of spectrograph
Spectrograph.USBSerial = "HR2B2201";
// sum up 10 spectra, each with an integration time of 100ms
// and display it in the spectrum "MeasSpec"
Spectrograph.Scan(MeasSpec,ScanNumber,Inttime);
53
Remarks
• A new spectrograph object could be created as well like this:
var Spectrograph :
OceanOptics = new OceanOptics();
The only difference to
var Spectrograph = new OceanOptics();
is that the “type” of the object is declared after the colon. However, creating the
object this way sometimes caused problems when trying to access the properties of the
measured spectrum. E.g. the measurement temperature of an Ocean Optics QE65000
spectrograph could not be retrieved.
• Many more objects to control hardware can be created (HMTUSBMultiStepper, Ac-
ton,.....). More detailed information can be found in the Programming Documentation
in the Help menu of DOASIS. Search for “DoasCore.Device” and a list of all types of
available devices will appear.
10.3
Operate two Ocean Optics spectrographs
It has to be said the solution presented here is only a (not very satisfactory) “work around”.
So far, two spectrograhs could not be controlled with a single JScript.
First, please follow the steps described in the chapter “How to operate two Ocean Optics
spectrographs with DOASIS at the same time” of the DOASIS Tutorial. Now, both spec-
trographs can be run with two instances of DOASIS.
The remains are quite easy:
1. Each of the two instances of DOASIS is connected to one of the spectrographs. So,
in each of these instances, choose the proper JScript for controlling the connected
spectrograph.
2. Make sure that these JScripts address the spectrographs by using the ”OceanOptics”
class (see example of section 10.2). In the JScript, create an object of this class and
assign to it the serial number of the connected spectrograph.
3. Now, you should be able to operate both spectrographs with the two JScripts at the
same time.
10.4
Mini-MAX-DOAS (MiniDOAS) control via JScript
Since the author never worked with MiniDOAS devices, the provided script could not be
tested in detail. The JScript controlling a MiniDOAS device is thus presented in section
12.6.
54