The following callbacks are available:
onTCPIPData(IOnDataCallbackFunctionArguments)
-
ICallbackFunctionResult
available when TCP control is enabled in the device settings, accepts data on the same port. It uses the end-line terminator from the device settings to assemble the entire message.
onSerialPortData(OnSerialPortDataFunctionArguments)
-
ICallbackFunctionResult
is available when control over USB CDC or RS232 is enabled. This callback is invoked for data arriving on these channels. It has a special argument that allows it to distinguish the data's origin. It uses the end-line terminator from the device settings to assemble the entire message.
onGPIOSignal(IGPIOSignalArguments)
-
ICallbackFunctionResult
is called when the GPIO signal changes. The argument indicates which GPIO port has changed. GPIO ports must be set as inputs, and the callback respects the edge setting. If the port is only for rising edges, the callback is called only then.
Declare a function with the above name and the export keyword (for example,
onResults
) to have it work as part of the device configuration. It's recommended to use snippets to create the body of these functions.
Callbacks and the
onResults
function are executed within a single thread using a FIFO queue. No event should be static, and there is no need to synchronize global variables between callbacks. All concurrent callbacks are executed one after the other. This also applies to
onResults
, frequent input changes can block
onResults
until earlier events are processed.
Callbacks can control camera outputs similarly to what
onResults
does by returning a structure:
interface ICallbackFunctionResult {
tcp_ip ? : ((string | (number[] | Uint8ClampedArray | Uint8Array)) | null);
serial ? : ((string | (number[] | Uint8ClampedArray | Uint8Array)) | null);
cdc ? : ((string | (number[] | Uint8ClampedArray | Uint8Array)) | null);
hid ? : ((string | (IHIDCombinationResult | IHIDPauseResult | HIDKey | string)[]) | null);
gpio ? : (IGpioPortControlResult[] | null);
beeper ? : (IBeepBeeperResult | null);
}
Refer to previous sections in Operation Mode to understand supported output types.
The callback input data follows this structure:
enum SerialPortSourceArguments {
RS232 = "RS232",
USB_CDC = "USB_CDC",
}
interface IOnSerialPortDataFunctionArguments {
data: number[];
source: SerialPortSourceArguments;
}
interface IOnDataCallbackFunctionArguments {
data: number[];
}
enum GpioEdgeArguments {
RISING_EDGE = "RISING_EDGE",
FALLING_EDGE = "FALLING_EDGE",
}
interface IOnGPIOSignalFunctionArguments {
port_number: number;
edge: GpioEdgeArguments;
}
The data field is a list of numbers. These are numbers in the range 0-255, representing the incoming bytes, as these are binary protocols. To treat them as strings, you must use the UTF-8, UTS-32, or other decoding used in the data. For debugging purposes, the following function is available within snippets:
function decodeBinaryArray(array){
let result = "";
array.forEach(element => result += String.fromCharCode(element));
return result;
}