This is an old revision of the document!


Device Driver Concepts

A device driver is a specialized piece of programming code, allowing Blocks to manage a device over a network or serial connection in a reliable and easy to understand manner. The device driver handles the intricate details of the control protocol required by the device being controlled. Rather than exposing "raw" command strings sent to the device, it exposes high-level functions of the device, such as input selection, power on/off, etc.

Furthermore, by exposing such high-level functions, a driver also allows those functions to be directly bound to buttons, sliders and other UI controls that can be exposed through Blocks.

Since the driver can not only send commands to the device, but also receive data from the device, it can make sure the device is performing properly. It can also query the device for its state, or handle data sent spontaneously from the device. Such feedback data often needs to be parsed and decoded according to the device's protocol – a function the device driver can handle.

Using a Device Driver

If an adequate driver for your device already exists, using it is quite straightforward.

  1. Obtain the driver code. Drivers provided by PIXILAB may come as part of your Blocks installation, or can be downloaded from official locations on the web, such as PIXILAB's github page.
  2. Install the driver file(s) into your Blocks server by copying all relevant files to the PIXILAN-root/script/driver folder under your home directory.
  3. Restart the Block server.

The driver(s) will now appear on the "Driver" menu for TCP/UDP Devices added on the manage page in Blocks. Once selected for a device, any functions exposed by the driver become available for use from panel controls, such as buttons and sliders, as well as Tasks.

Driver Development Prerequisites

If a driver doesn't exist for your device, and you have sufficient programming knowledge and experience, you may be able to create a driver by following the instructions outlined below.

:!: In some cases, a driver for a similar type of device may already exist. If so, it may be easier to use that driver as a starting point for your own efforts, rather than starting from scratch.

Things You Must Know

You must have sufficient programming experience to feel comfortable with all the concepts described below. Device drivers are written using the TypeScript programming language, which can be considered a superset of JavaScript. Thus, if you have experience with modern JavaScript, you should feel right at home.

While the execution environment for drivers is specific to Blocks, it has some similarities with node.js. In particular, it shares the following properties:

  • All code must be written in a non-blocking way. In particular, this means you can't use any long-running loops or similar code constructs.
  • Potentially time-consuming operations typically return a promise, to be resolved or rejected once the operation finishes, thereby allowing subsequent operations to proceed.

Things You Must Have

  • A Mac, Window or Linux computer you can use for development purposes, with its own Blocks license.
  • Development tools and code, as described here.
  • Access to the device to be controlled, as well as all relevant documentation.
  • If the device is controlled by serial data rather than a direct network connection, you'll need a network-to-serial interface.