# iseg Terminal

iseg Terminal is a small GUI program to control all kind of
ASCII based iseg devices. This includes devices with RS-232,
USB, GPIB (IEEE-488) and Ethernet interface.

## Scripts

iseg Terminal can run scripts, which are pure text files containing
one or multiple commands. These commands are sent to the connected
device and optionally written to the log window. The answer is read
back from the device and written to the log window.

Optionally the answer can be checked against a regular expression.
The script is stopped when the check fails. The regular expression
must be separated from the command by at least one tab character.

Example to check that the connected device is an iseg device.
The answer starts with "iseg Spezialelektronik GmbH" followed by
device information like type, serial number, firmware release).
So the regex checks for "iseg" followed by more characters:
```
*IDN?		iseg.*
```
The following commands have special meanings:

* Lines starting with `//` are interpreted as comments and ignored.
  `// This is a comment`

* This command pauses the script execution for `time` milliseconds.
  `SLEEP <time>`

* This command prints the `message` to the log window.
  `ECHO <message>`

* This commands stops the script execution
  `STOP`

Advanced scripts can have three sections named `INIT:`, `LOOP:`
and `EXIT:`. Their meaning is explained below:
```
INIT:
// Commands run one time at startup
LOOP:
// Commands run in a loop
EXIT:
// Commands run one time at cleanup
```

# Windows

## Building

The development takes place with:
* Qt Creator 3.6.0
* Qt 4.8.2 and MSVC 2010 32-Bit
* Qt 5.5.1 and MinGW 4.9.2 32-Bit

As Qt 4 does not contain QSerialPort, this library has to be
installed seperately when using iseg Terminal with Qt 4
(see section "Building QSerialPort for Qt 4".

# Linux

The development takes place with:
* Qt Creator 3.6.0
* Qt 5.5.1 and gcc 4.8.4 64-Bit

## Building

To build iseg Terminal, the following packages are needed:

* C++ Compiler and related tools ("build-essential")
* Qt-dev-tools (qmake), Qt-Creator is recommended

## Ubuntu Linux
```
sudo apt-get install g++
sudo apt-get install qtbase5-dev-tools qtbase5-dev
```
In case of linker errors like: "/usr/bin/ld: cannot find -lGL"
sudo apt-get install libglu1-mesa-dev

## Building with Qt Creator

Open the project file isegTerminal.pro in Creator.
Creator asks to setup a shadow-build directory, which should be accepted.
Then the project can be build with build all (Ctrl+Shift+B).

## Building by hand

Shadow-building (i.e. the build is done outside the source directory) is
recommended. Qmake needs the build directory to be in parallel to the
source directory (i.e. on the same directory depth), e.g.:
```
/home/user/src/isegTerminal       <-- the sources
/home/user/src/isegTerminal-build <-- the build directory

[/home/user/src]
mkdir isegTerminal-build
cd isegTerminal-build
qmake ../isegTerminal/isegTerminal.pro
make
```

# Other requirements

## Building QSerialPort for Qt 4

Taken from: https://wiki.qt.io/Qt_Serial_Port

```
git clone git://code.qt.io/qt/qtserialport.git
cd qtserialport
git checkout qt4-dev
cd ..
mkdir qtserialport-build
cd qtserialport-build
qmake ../qtserialport/qtserialport.pro
```
* Linux-GCC
```
make
sudo make install
```
* Windows-MSVC
```
nmake
nmake install
```

# Linux-GPIB

* Download linux-gpib and extract it
* Compile and install:
```
cd linux-gpib-4.1.0
./configure
make
sudo make install
```

* Edit the gpib.conf, change the board_type if needed:
```
sudo gedit /etc/gpib.conf
# board_type = "ni_usb_b"
```
* Add yourself to the group gpib:
```
sudo gedit /etc/group
# gpib:x:1001:<your-user-name>
```

## FTDI USB-Serial-Adapter read timeout

By default, the FTDI adapters uses 16 milliseconds read timeouts,
i.e. the received characters arrive in blocks every 16 milliseconds.

To improve the performance, this timeout can be reduced to 1 milli-
second as described below.

### Windows
Go to Device Manager > Ports (COM & LPT) > USB Serial Port (COMxx) >
Right click for context menu > Properties > Tab Port settings >
Advanced > Wait Time (ms) > Select 1 > Ok.

### Linux
```
cat /sys/bus/usb-serial/devices/ttyUSB0/latency_timer
16
setserial /dev/ttyUSB0 low_latency
cat /sys/bus/usb-serial/devices/ttyUSB0/latency_timer
1
```

# History

## 2.1.0
* Linux:
  * Added XPort ARP (MAC address) resolving
* Added serial communication without echo
* Added option to visualize line endings
* Added dialog factory settings like in iseg Terminal 1
* Added support for National Instruments VISA
* Improved the formatting of IPv6 encapsulated IPv4 address
  (display 192.168.16.221 instead ::ffff:192.168.16.221)
* Script:
  * Fixed that partial answers were considered as correct
  * Fixed that the SLEEP command did not work
  * Improved the script syntax to allow running parts of the
    script at startup, in a loop and whenever the script is
    stopped. See section Scripts for more information.
  * Allow direct editing with the system editor
* GPIB:
  * Use the modern NI4882 instead GPIB32 library and load it
    at runtime. Errors are printed to the log window.
  * Only scan for instruments when the combo box is visible

## 2.0.6
* The command is now immediately added to the log when sending
* Added setting to add timestamp to log
* Added shortcut Ctrl+L to clear log
* When GPIB writing fails try a second time
* Script:
  * Removed duplicated timestamps
  * Evaluate expected answer as regular expression like iseg Terminal 1
  * Made start/stop output more colorful
  * Enable run button again when script stops
* Firmware Update: Remember recently used update files

## 2.0.5
* Added fast serial communication
* Added GPIB support for Linux
* Firmware Update
  * Fixed file name verification in history combo box
  * Fixed flashing over internal CAN bus
* Script:
  * Restored script compatibility to isegTerminal 1.xx
  * Improved script error handling

## 2.0.4
* Use program name without space for ini file
* Add debug mode for serial connection
* Serial Port combo box:
  * Refresh tooltip on changes
  * Automatically update port list as long as combo box is empty
* Firmware Update:
  * Added a history box and restore last hex file path at startup
  * Allow flashing standalone and internal filament (FPS) devices
  * Disabled Ok button if invalid hex file is selected

## 2.0.3
* Disabled the overeager auto-completion for the input field,
  behave now like iseg Terminal 1.x did
* Better distinction between communication errors and commands without answer
* Fix enabling serial ports under Linux
* Actualize GPIB combo box when opening the box

## 2.0.2
* The dialog Firmware Update now keeps its settings if opened again
* Updated build instructions
* Added example script
* Query button and Firmware Update menu entry are disabled when
  wrong interface is selected

## 2.0.1
* Serial sending is now character-wise with echo to support NHQ, SHQ and THQ
* Script commands are also added to the log if "Add command to Log" is checked
* Show an error message if the flash program could not be started
* The XPort search now runs periodically when the scan dialog is open, i.e.
  XPorts that were connected to network while the dialog is open are found now

## 2.0.0
* Initial release
