Home Contents | # Mubus | Gpio | Core4 Lua Event System

## DESCRIPTION

External IO Devices can be connected either through the local 10-pin Mubus Header or remotely via RS485.

The device can provide additional GPIO ports and extra serial ports.

gpio.register() must be called to make the existence of an add-on device known. Once registered, the system automatically polls for the device. Events are generated when the device is detected and also when a device goes offline.

## HOTPLUG EVENTS

The application can get notified if a device is detected or goes offline.

The reporting arrives through the callback function that can be registered with gpio.new().

The event structure for device detection has the same outline as all other gpio events:

{ type = GPIO_ACTIVE, -- When device goes offline: GPIO_INACTIVE value = «registered group», -- Group number that the device was registered through gpio.register() group = GPGRP_MUPP, -- Constant value GPGRP_MUPP pin = «address», -- Bus address that the device was registered through gpio.register() }

When a device was reported GPIO_ACTIVE, more information about it is available with gpio.info() using the group number it was registered with.

## REMOTE GPIO

Remote devices typically provide extra GPIO.

The remote GPIO is controlled with the same mechanism as any other GPIO of the controller. The group number that a device was registered with gpio.register() must be used for all gpio calls concerning that device.

## REMOTE TTY

Remote devices may provide extra serial ports.

Data is tunneled through the device's bus connection. Due to the peculiar nature of this "tunneling", please note:

- The remote serial ports are available as /dev/ttyMUPP«group»s«index». «group» is taken from the lower 8 bits of the group number that the device was registered through gpio.register(). «index» numbers the serial port on the device, starting at 0. Example: /dev/ttyMUPP6s0
- The entries in /dev will appear once the device is detected.
- When a device goes offline after one or more serial ports have been registered, the device file for the remote serial port stays available. Attempting to read or write data results in the error ENODEV (No such device).
- If you want to get notified when a serial port is plugged back in, watch for POLLOUT events on the device handle. (Don't forget to stop watching once the serial port is back.)
- The data of the serial ports is tunneled through a polled bus at 19200bps. While it is possible to configure a remote serial port to e.g. 115200bps, this can only work if the total bandwidth used over time does no exhaust the bus capabilities.

## HOTPLUG EVENTS

app = event.new() function gpio_event(ev) print("GPIO", table.tostring(ev)) end gpio_evh = gpio.new(app, gpio_event) -- Register a remote device at address 6 on a RS485 Bus connected to /dev/ttyS15 gpio.register(0x0106, GPGRP_MUPP, "/dev/ttyS15", 6) -- Register a remote device at address 1 on the local 10-pin mubus port gpio.register(0x0101, GPGRP_MUPP, "/dev/mbus", 1)