Skip to content
Chris Petersen edited this page Oct 16, 2014 · 1 revision

serial-try attempts to open the serial port with given settings and execute testproc if valid.

Parameter Description
devname Device name, e.g. "/dev/ttyUSB0"
baudrate Baud rate (110-230400)
databits Number of data bits (5-8)
parity The parity, 0: no parity, 1: odd parity, 2: even parity
stopbits Number of stop bits (1-2)
testproc Function to be executed to test connectivity. Most often #f

Example

Example 1: Connect to a binary file if fromfile flag is set, otherwise make a normal serial connection. This example derives from a plugin, in which a handshake is done over a serial connection.

((fx= runlevel 1)
  (if fromfile
      ;; From a file, so connect to file
      (let* ((filepath (instance-refvar group instance "Port" #f))
             (dev (serial-tryfile filepath)))
        (if dev (begin (instance-setvar! group instance "Device" dev) 2) 0))
      ;; Not from a file, so connect normally
      (let* ((devname (instance-refvar group instance "Port" #f))
             (baudrate 9600) (databits 8) (parity 0) (stopbits 1)
             (dev (serial-try devname baudrate databits parity stopbits #f)))
        (if dev (begin (instance-setvar! group instance "Device" dev) 2) 0))
  ))
Clone this wiki locally