Welcome | spec | C-PLOT | Support | Users | Contact
 
Contents -> REFERENCE MANUAL -> Built-In Functions and Commands -> Hardware Functions and Commands -> RS-232 Serial Interfaces
spec Manual


2.4.5.4. - RS-232 Serial Interfaces

Serial functions are available on all the systems spec supports. The device nodes are selected in the config file, where they are assigned spec device numbers starting from zero that are used in the functions below.


ser_get(dev_num)
Reads a string of characters, up to and including a newline, from serial device dev_num and returns the string so read. The routine will not return until the read is satisfied. Use ser_get(dev_num, 0) to read up to a newline with a timeout.

ser_get(dev_num, n)
If n is greater than 0, this routine reads n bytes from the serial device dev_num and returns the string so obtained. If n is zero, the routine reads characters up to and including a newline. If the read is not satisfied within two seconds, the routine returns the null string.

ser_get(dev_num, mode)
If mode is the string "byte", reads and returns one unsigned binary byte. The following modes read short or long integers and work the same on both big-endian and little-endian platforms. If mode is the string "int2" reads two binary bytes and returns the short integer so formed. If mode is the string "int4" reads four binary bytes and returns the long integer so formed. By default, the incoming data is treated as big endian. If the incoming data is little endian, use "int2_swap" or "int4_swap". If the device returns less than the required number of bytes, the characters so read are discarded, and ser_get() returns the null string. The tty mode for the device needs to be selected as raw in the config file for this command to work properly.

ser_put(dev_num, string)
Writes the string string to the serial device having device number dev_num, as set in the config file . Returns the number of bytes written.


spec uses the standard tty(4) driver interface on the UNIX systems. Serial line characteristics are set according to the device modes set in the config file. Available modes are either raw or cooked, with cooked mode also having noflow, igncr (no-op on non-System V) and evenp or oddp options. The baud rate for the serial line is also taken from the config file.

ser_par(dev_num, par [, val ])
Sets parameters for the serial device dev_num. Values for par include:


"timeout"
Sets or returns the current value for the timeout for reads from cooked serial lines. The units are seconds. If val is zero, timeouts are disabled. If val is less than zero, the default timeout of two seconds is set.



  Top
  Prev | Next