-
Notifications
You must be signed in to change notification settings - Fork 6
The functions substructure
aortega255 edited this page Jul 22, 2020
·
1 revision
The fields of this substructure basically specify the path for hardware-specific scripts as anonymous functions. The scripts for each device should be in a subfolder of the ‘device_functions’ folder dedicated to scripts for that specific hardware device. Only four function scripts are required right now, and all four need to be defined in order for the GUI to work:
- [data,packlen,rbytes]=ReadBytesAvailable(app). This function calls a script that reads bytes present in the input buffer. The implementation for each hardware device can be different, but they should always return three outputs in the following order. The first output (data) should be the data read, with rows being fNIRS channels and columns being time in samples. The second parameter is packlen, which specifies how many samples were read for each channel. If the number of samples read is the same for all channels, this needs to be a constant. If channels had an unequal number of samples read, then it needs to return a column vector with the same number of rows as channels. Each row indicates the number of samples read for each channel. Finally, the third parameter (rbytes) needs to return any bytes that were read but were unused by the function. While ideally all packages are the same length and we should be able to just read bytes in multiples of that length, we observed that occasionally the port returns more or less packets that intended. This means that some data packets are incomplete and cannot be processed by the function properly, losing the information on that package. Furthermore, this caused future calls of the ReadBytesAvailable function to return “out of frame” packages; that is, the first byte read by the function call would not be the start of a package. To handle this, the ReadBytesAvailable function needs to return any “extra” or unused bytes at the end of the read operation, and these can be appended at the beginning of the data generated by the next read operation. This ensures that the data is always in-frame.
- FlushBuffer(app). This function needs to discard all data present in the input buffer. It is used to prevent “garbage data” to be kept in the buffer from previous runs of the device.
- MapFrequencies(app,statemap). This function is used to set the frequencies of the light sources. The function can be a dummy function (just return a value of 1) for devices in which the frequencies are not configurable. Right now, this function is only being used for ninjaNIRS.
- Ask4Status(app). This function is meant to request the status of the serial device. If the device firmware does not have a serial command for that, this function should just return a 1. The main purpose of the function would be to identify if the hardware device is offline. Currently, NIRS1k (but not ninjaNIRS) has a command to request status. If it fails to respond, ninjaGUI returns an error (as this is likely to happen if the device is not plugged in to the power outlet, which is somewhat common).