http://bricxcc.sourceforge.net/nbc/doc/NBC_Guide.pdf3.12. NBC/NXC Comm ModuleThe NBC/NXC comm module encompasses support for all forms of Bluetooth, USB, and HiSpeed
communication.Table 57. Comm Module Constants
You can use the Bluetooth communication methods to send information to other devices
connected to the NXT brick. The NXT firmware also implements a message queuing or mailbox
system which you can access using these methods.
Communication via Bluetooth uses a master/slave connection system. One device must be
designated as the master device before you run a program using Bluetooth. If the NXT is the
master device then you can configure up to three slave devices using connection 1, 2, and 3 on
the NXT brick. If your NXT is a slave device then connection 0 on the brick must be reserved for
the master device.
Programs running on the master NXT brick can send packets of data to any connected slave
devices using the BluetoothWrite method. Slave devices write response packets to the message
queuing system where they wait for the master device to poll for the response.
Using the direct command protocol, a master device can send messages to slave NXT bricks in
the form of text strings addressed to a particular mailbox. Each mailbox on the slave NXT brick
is a circular message queue holding up to five messages. Each message can be up to 58 bytes
long.
To send messages from a master NXT brick to a slave brick, use BluetoothWrite on the master
brick to send a MessageWrite direct command packet to the slave. Then, you can use
ReceiveMessage on the slave brick to read the message. The slave NXT brick must be running a
program when an incoming message packet is received. Otherwise, the slave NXT brick ignores
the message and the message is dropped.
3.12.1. High-level functionsSendRemoteBool (connection, queue, bvalue, out result) Function
This method sends a boolean value to the device on the specified connection. The message
containing the boolean value will be written to the specified queue on the remote brick.
SendRemoteBool (1, queue, false, result)
SendRemoteNumber (connection, queue, value, out result) Function
This method sends a numeric value to the device on the specified connection. The message
containing the numeric value will be written to the specified queue on the remote brick.
SendRemoteNumber (1, queue, 123, result)
SendRemoteString(connection, queue, strval, out result) Function
This method sends a string value to the device on the specified connection. The message
containing the string value will be written to the specified queue on the remote brick.
SendRemoteString (1, queue, 'hello world', result)
SendResponseBool(queue, bvalue, out result) Function
This method sends a boolean value as a response to a received message. The message
containing the boolean value will be written to the specified queue (+10) on the slave brick
so that it can be retrieved by the master brick via automatic polling.
SendResponseBool (queue, false, result)
SendResponseNumber (queue, value, out result) Function
This method sends a numeric value as a response to a received message. The message
containing the numeric value will be written to the specified queue (+10) on the slave brick
so that it can be retrieved by the master brick via automatic polling.
SendResponseNumber (queue, 123, result)
SendResponseString (queue, strval, out result) Function
This method sends a string value as a response to a received message. The message
containing the string value will be written to the specified queue (+10) on the slave brick so
that it can be retrieved by the master brick via automatic polling.
SendResponseString (queue, 'hello world', result)
ReceiveRemoteBool (queue, remove, out bvalue, out result) Function
This method is used on a master brick to receive a boolean value from a slave device
communicating via a specific mailbox or message queue. Optionally remove the last read
message from the message queue depending on the value of the boolean remove parameter.
ReceiveRemoteBool (queue, true, bvalue, result)
ReceiveRemoteNumber(queue, remove, out value, out result) Function
This method is used on a master brick to receive a numeric value from a slave device
communicating via a specific mailbox or message queue. Optionally remove the last read
message from the message queue depending on the value of the boolean remove parameter.
ReceiveRemoteBool (queue, true, value, result)
ReceiveRemoteString (queue, remove, out strval, out result) Function
This method is used on a master brick to receive a string value from a slave device
communicating via a specific mailbox or message queue. Optionally remove the last read
message from the message queue depending on the value of the boolean remove parameter.
ReceiveRemoteString (queue, true, strval, result)
ReceiveRemoteMessageEx(queue, remove, out strval, out val, out bval, out result) Function
This method is used on a master brick to receive a string, boolean, or numeric value from a
slave device communicating via a specific mailbox or message queue. Optionally remove the
last read message from the message queue depending on the value of the boolean remove
parameter.
ReceiveRemoteMessageEx (queue, true, strval, val, bval, result)
SendMessage (queue, msg, out result) Function
This method writes the message buffer contents to the specified mailbox or message queue.
The maximum message length is 58 bytes.
SendMessage (mbox, data, result)
NBC Programmer's Guide
ReceiveMessage (queue, remove, out buffer, out result) Function
This method retrieves a message from the specified queue and writes it to the buffer
provided. Optionally removes the last read message from the message queue depending on
the value of the boolean remove parameter.
RecieveMessage (mbox, true, buffer, result)
BluetoothStatus(connection, out result) Function
This method returns the status of the specified Bluetooth connection. Avoid calling
BluetoothWrite or any other API function that writes data over a Bluetooth connection while
BluetoothStatus returns STAT_COMM_PENDING.
BluetoothStatus (1, result)
BluetoothWrite (connection, buffer, out result) Function
This method tells the NXT firmware to write the data in the buffer to the device on the
specified Bluetooth connection. Use BluetoothStatus to determine when this write request is
completed.
BluetoothWrite (1, data, result)
RemoteMessageRead (connection, queue, out result) Function
This method sends a MessageRead direct command to the device on the specified
connection. Use BluetoothStatus to determine when this write request is completed.
RemoteMessageRead(1, 5, result)
RemoteMessageWrite (connection, queue, msg, out result) Function
This method sends a MessageWrite direct command to the device on the specified
connection. Use BluetoothStatus to determine when this write request is completed.
RemoteMessageWrite (1, 5, 'test', result)
RemoteStartProgram (connection, filename, out result) Function
This method sends a StartProgram direct command to the device on the specified connection.
Use BluetoothStatus to determine when this write request is completed.
RemoteStartProgram (1, 'myprog.rxe', result)
RemoteStopProgram (connection, out result) Function
This method sends a StopProgram direct command to the device on the specified connection.
Use BluetoothStatus to determine when this write request is completed.
RemoteStopProgram(1, result)
RemotePlaySoundFile (connection, filename, bLoop, out result) Function
This method sends a PlaySoundFile direct command to the device on the specified
connection. Use BluetoothStatus to determine when this write request is completed.
RemotePlaySoundFile(1, 'click.rso', false, result)
RemotePlayTone (connection, frequency, duration, out result) Function
This method sends a PlayTone direct command to the device on the specified connection.
Use BluetoothStatus to determine when this write request is completed.
RemotePlayTone (1, 440, 1000, result)
RemoteStopSound (connection, out result) Function
This method sends a StopSound direct command to the device on the specified connection.
Use BluetoothStatus to determine when this write request is completed.
RemoteStopSound (1, result)
RemoteKeepAlive (connection, out result) Function
This method sends a KeepAlive direct command to the device on the specified connection.
Use BluetoothStatus to determine when this write request is completed.
RemoteKeepAlive (1, result)
RemoteResetScaledValue (connection, port, out result) Function
This method sends a ResetScaledValue direct command to the device on the specified
connection. Use BluetoothStatus to determine when this write request is completed.
RemoteResetScaledValue (1, IN_1, result)
RemoteResetMotorPosition (connection, port, bRelative, out result)Function
This method sends a ResetMotorPosition direct command to the device on the specified
connection. Use BluetoothStatus to determine when this write request is completed.
RemoteResetMotorPosition (1, OUT_A, true, result)
RemoteSetInputMode (connection, port, type, mode, out result) Function
This method sends a SetInputMode direct command to the device on the specified
connection. Use BluetoothStatus to determine when this write request is completed.
RemoteSetInputMode (1, IN_1, IN_TYPE_LOWSPEED, IN_MODE_RAW, result)
RemoteSetOutputState(connection, port, speed, mode, regmode, turnpct, runstate, tacholimit, out result) Function
This method sends a SetOutputState direct command to the device on the specified
connection. Use BluetoothStatus to determine when this write request is completed.
RemoteSetOutputState (1, OUT_A, 75, OUT_MODE_MOTORON,OUT_REGMODE_IDLE, 0, OUT_RUNSTATE_RUNNING, 0, result)