NXT_LSRead
Reads data from a digital low speed sensor port (I2C)
Contents
Syntax
[data BytesRead] = NXT_LSRead(port)
[data BytesRead] = NXT_LSRead(port, handle)
[data BytesRead optionalStatusByte] = NXT_LSRead(port)
[data BytesRead optionalStatusByte] = NXT_LSRead(port, handle)
Description
[data BytesRead] = NXT_LSRead(port)) gets the data of the low speed (digital) sensor value of the given sensor port. The value port can be addressed by the symbolic constants SENSOR_1, SENSOR_2, SENSOR_3 and SENSOR_4 analog to the labeling on the NXT Brick. The return value BytesRead contains the number of bytes available to read.
[data BytesRead] = NXT_LSRead(port, handle) uses the given Bluetooth connection handle. This should be a serial handle on a PC system and a file handle on a Linux system.
[data BytesRead optionalStatusByte] = NXT_LSRead(port, [handle]) will ignore the automatic statusbyte check and instead return it as output argument. This causes the function to ignore erronous I2C calls or crashes if the sensor is not yet ready. You can effectively save a call to NXT_LSGetStatus with this, if you interpret the statusbytes correctly. This may vary, depending on your I2C sensor. The handle argument is still optional, like above.
If no NXT handle is specified the default one (COM_GetDefaultNXT) is used.
For more details see the official LEGO Mindstorms communication protocol.
Note:
For LS communication on the NXT, data lengths are limited to 16 bytes per command. Furthermore, this protocol does not support variable-length return packages, so the response will always contain 16 data bytes, with invalid data bytes padded with zeros.
Before using LS commands, the sensor mode has to be set to LOWSPEED_9V using the NXT_SetInputMode command.
Examples
handle = COM_OpenNXT('bluetooth.ini'); NXT_SetInputMode(SENSOR_1, 'LOWSPEED_9V', 'RAWMODE', 'dontreply'); % usually we would use NXT_LSWrite before, to request some sort of reply [data BytesRead] = NXT_LSRead(SENSOR_1, handle);
See also
NXT_SetInputMode, NXT_LSWrite, NXT_LSGetStatus, COM_ReadI2C,
Signature
- Author: Linus Atorf (see AUTHORS)
- Date: 2007/10/15
- Copyright: 2007-2010, RWTH Aachen University