Skip to content

Serial device access

Lieven Hollevoet edited this page Sep 22, 2014 · 1 revision

Serial Device Access.

One of the things Misterhouse is good at doing is accessing devices connected to a serial port on the Misterhouse server. This is due to the module **Device::SerialPort** (Linux) or **Win32::SerialPort** (Windows)functions.

Simple Serial_Item example

Most of the serial communicaton in Misterhouse is built upon Serial_Item. Here is how to set up a very basic Serial_Item (provided on the Misterhouse list by Steve Switzer)

  1. 1: Create a serial port. Add to mh.private.ini:
serialname_port=COMX serialname_baudrate=9600
  1. 2: Create a Serial_Item in user code:
$myitem = new Serial_Item('aaaa', 'state1', 'serialname'); $myitem -> add('bbbb', 'state2'); $myitem -> add('cccc', 'state3'); $myitem -> add('dddd', 'state4');

NOTE: In this example, when 'bbbb' is received on the serial port, $myitem is set to 'state2'. Additionally, if you set $myitem to 'state2', it'll send 'bbbb' to the serial port.

  1. 3: Either set states or trigger on item set:
if($New_Minute) {
  1. Every minute, send 'dddd' to the serial port
$myitem->set('state4'); }

if($state = state_now $myitem) {

  1. This triggers on any state change, with the state in $state variable
print_log('myitem is now: '.$state); } if('state3' = state_now $myitem) {
  1. This triggers only when the state is 'state3'
print_log('myitem was noticed at state3'); }

You can also use state_changed instead of state_now, then if the item is set to state3 twice in a row, it'll only trigger once.


code format="perl"

  1. user code
code
Clone this wiki locally