Page
Library
Module
Module type
Parameter
Class
Class type
Source
Mindstorm_lwt.NXTSourceUSB connection type.
Bluetooth connection type.
Abstract type representing a connection to a LEGO® mindstorm brick. The type parameter indicates whether this connection is a USB or a Bluetooth one.
connect_bluetooth bdaddr connects through bluetooth to the brick with bluetooth address bdaddr. See the section "connectBluetooth" for more information.
Functions to choose and connect to NXT bricks connected through USB. So far, it works on Linux (users of other platforms, your help is welcome).
type error = Mindstorm.NXT.error = | No_more_handlesAll 16 handles are in use.
*)| No_space| No_more_files| EOF_expected| Not_a_linear_file| No_linear_space| Undefined_error| File_is_busy| No_write_buffers| Append_not_possible| File_is_full| File_exists| Module_not_found| Out_of_boundary| Illegal_file_name| PendingPending communication transaction in progress
*)| Empty_mailboxSpecified mailbox queue is empty
*)| FailedRequest failed (i.e. specified file not found)
*)| UnknownUnknown command opcode
*)| InsaneInsane packet
*)| Out_of_rangeData contains out-of-range values
*)| Bus_errorCommunication bus error, can indicate a device failure.
*)| Buffer_fullNo free memory in communication buffer
*)| Invalid_connSpecified channel/connection is not valid
*)| Busy_connSpecified channel/connection not configured or busy
*)| No_programNo active program
*)| Bad_sizeIllegal size specified
*)| Bad_mailboxIllegal mailbox queue ID specified
*)| Bad_fieldAttempted to access invalid field of a structure
*)| Bad_ioBad input or output specified
*)| Out_of_memoryInsufficient memory available
*)| Bad_argBad arguments
*)Error codes. The codes starting with Pending are command error.
This exception can be raised by any of the functions below except when the optional argument ~check_status is set to false. Note that checking for errors leads to up to approximately a 60ms latency between two commands.
Raised to indicate that a file is not present on the brick.
Read and write messages from the 10 message queues. This can be thought as advanced direct commands.
Handle for reading from the brick.
open_in conn fname opens the file named fname on the brick for reading. The channel must be closed with Mindstorm_lwt.NXT.close_in. Close it as soon as possible as channels are a scarce resource.
in_channel_length ch returns the length of the channel ch.
close_in ch closes the channel ch. Closing an already closed channel does nothing.
input ch buf ofs len reads a block of data of length len from the channel ch and write it to buf starting at position ofs.
Handle for writing data to the brick.
The standard NXT firmware requires that executable files and icons are linear but all other types of files (including sound files) can be non-contiguous (i.e., fragmented).
`File length: Default file, the parameter is its length.`Linear length: Write a linear file, the parameter is its length.open_out conn flag fname opens the file fname for writing. The channel must be closed with Mindstorm_lwt.NXT.close_in. Close it as soon as possible as channels are a scarce resource.
If the the file exists, Error File_exists is raised. If the brick does not like the extension you use, Error File_is_full may be raised.
close_out ch closes the channel ch. Closing an already closed channel does nothing.
output ch buf ofs len ouputs the substring buf.[ofs .. ofs+len-1] to the channel fd. Returns the number of bytes actually written. If you try to write more bytes than declared when opening the file, Error File_is_full is raised.
remove conn fname remove the file fname from the brick.
firmware_version conn returns a tuple (p1, p0, f1, f0) where p1 is the major version of the protocol, p0 is the minor version of the protocol, f1 is the major version of the firmware, f0 is the minor version of the firmware,
set_brick_name conn name change the name to which one is connected through conn to name.
type brick_info = Mindstorm.NXT.brick_info = {brick_name : string;bluetooth_addr : string;Bluetooth address
*)signal_strength : int;Bluetooth signal strength (for some reason is always 0)
*)free_user_flash : int;Free user FLASH
*)}get_device_info conn returns some informations about the brick connected through conn.
keep_alive conn returns the current sleep time limit in milliseconds.
battery_level conn return the voltages in millivolts of the battery on the brick.
bluetooth_reset conn performs a factory reset of the brick. (The type system does will a allow this command to be transmitted via bluetooth because all bluetooth functionality is reset by this command.)
Returns the number of bytes for a command in the low-speed buffer or the high-speed buffer (0 = no command is ready).