Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
blocks:drivers:concepts [2018-01-12 19:51]
admin
blocks:drivers:concepts [2024-04-18 11:24] (current)
admin [Using a Device Driver]
Line 11: Line 11:
 If an adequate driver for your device already exists, using it is quite straightforward. If an adequate driver for your device already exists, using it is quite straightforward.
  
-  - 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 [[https://github.com/pixilab/blocks-script|github page]]. +  - Obtain the drivers. Drivers provided by PIXILAB may come as part of your Blocks installation, or can be downloaded from PIXILAB's [[https://github.com/pixilab/blocks-script|github page]]. Find the green "Code" dropdown button and select download ZIP
-  - 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.+  - Install the file(s) into your Blocks server by extracting the ZIP and then copying all relevant files to the PIXILAB-Blocks-root/script directory, typically located in the home directory for the user under which Blocks runs. Do this file copying while logged in as that user to avoid any access permission problems.  
 +  - Some rarely used device drivers are located in the driver-archive directory. If you need any of those, move those over from the archive to the acive driver directory. While blocks ignore the source code (.ts) file and use the .js it still makes sense to move/copy both the .ts and .js file to keep them in the same place. 
 +  - Make sure to also copy the latest version of all files in //system// and //system_lib//, as well as the files //package.json, package-lock.json// and //tsconfig.json//, into corresponding directories on your server
   - Restart the Block server.   - 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 deviceany functions exposed by the driver become available for use from panel controlssuch as buttons and slidersas well as Tasks.+:!: When installing the files downloaded above, take care when copying the files into an existing PIXILAB-Blocks-root/script directoryas some operating systems will replace the entire directory with the new onerather than adding only the individual files. You may want to copy files into directories one by onerather than replacing your entire script directory with the downloaded one.
  
 +The driver(s) will now appear on the "Driver" menu for Network Devices added to the Manage page. 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 from Tasks.
  
 ===== Driver Development Prerequisites ===== ===== Driver Development Prerequisites =====
Line 38: Line 41:
   * Development tools and code, as described [[blocks:drivers:tools|here]].   * Development tools and code, as described [[blocks:drivers:tools|here]].
   * Access to the device to be controlled, as well as all relevant documentation.   * 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 [[blocks:drivers:serial|network-to-serial interface]].+  * If the device is controlled by serial data rather than a direct network connection, you'll need either a USB-to-serial interface if you're connecting through a PIXILAB Player or a [[blocks:drivers:serial|network-to-serial interface]].
  
  
 ===== Anatomy of a Driver ===== ===== Anatomy of a Driver =====
  
-This section provides a brief overview of what's inside a driver. You may want to install the required tools, download the code and open the WOCustomDrvr.ts sample driver to follow along.+This section provides a brief overview of what's inside a driver. You may want to install the required tools, download the code and open the WOCustomDrvr.ts sample driver to follow along. After reading the brief overview below, you may also want to read the more [[blocks:drivers:example|detailed walk-through]] of the sample driver.
  
 ==== Driver Class ==== ==== Driver Class ====
Line 54: Line 57:
 </code> </code>
  
-This class (here named //WOCustomDrvr//) must be stored in a file named WOCustomDrvr.ts, which compiles to a file named WOCustomDrvr.js. Both these files must be located in the PIXILAN-root/script/driver folder, under your home directory.+This class (here named //WOCustomDrvr//) must be stored in a file named WOCustomDrvr.ts, which compiles to a file named WOCustomDrvr.js. Both these files must be located in the PIXILAB-Blocks-root/script/driver folder, under your home directory.
  
 :!: While only the .js file is required to use the driver, you typically keep the .ts "source code" file in the same directory to simplify future changes. :!: While only the .js file is required to use the driver, you typically keep the .ts "source code" file in the same directory to simplify future changes.
Line 60: Line 63:
 === Constructor Function === === Constructor Function ===
  
-A new instance of the driver will be created for each device that uses the driver. This is done by calling the constructor function, passing it an object of the driven class (here NetworkTCP). The constructor takes takes a parameter of the type defined for the //Driver// base class (in the example above, that type is //NetworkTCP//). The only applicable types here at this point are //NetworkTCP// and //NetworkUDP//, both of which are declared in Network.ts file, located in the system directory. That directory contains various definitions of types implemented by the Blocks runtime system.+A new instance of the driver will be created for each device that uses the driver. This is done by calling the constructor function, passing it an object of the driven class (here NetworkTCP). The constructor takes a parameter of the type defined for the //Driver// base class (in the example above, that type is //NetworkTCP//). The only applicable types here at this point are //NetworkTCP// and //NetworkUDP//, both of which are declared in Network.ts file, located in the system directory. That directory contains various definitions of types implemented by the Blocks runtime system.
  
 The constructor stores the driven instance in the private //socket// variable, allowing it to use the socket to communicate with the device via the network. See the NetworkTCP class definition for available functions used to communicate with the device. The constructor stores the driven instance in the private //socket// variable, allowing it to use the socket to communicate with the device via the network. See the NetworkTCP class definition for available functions used to communicate with the device.
Line 107: Line 110:
 Decorator that can be applied to parameters to //callable// functions, providing a textual description of the parameter. Decorator that can be applied to parameters to //callable// functions, providing a textual description of the parameter.
  
 +==== Learn More ====
  
 +Learn more in the [[blocks:drivers:example|detailed walk-through]] of the sample driver. You may also want to take a look at some other drivers available on [[https://github.com/pixilab/blocks-script|github]].