![]() |
Communication | Contents | Master Index |
RCX | RCX2 | Scout |
ClearMessage() | Clear the message buffer. | ||||||
SendMessage() | Send an IR message. | ||||||
SetTxPower() | Set the power level for IR transmission. | ||||||
SetSerialComm() | Set the communication settings. | ||||||
SetSerialPacket() | Set the packet settings. | ||||||
SetSerialData() | Set one byte of data in the transmit buffer. | ||||||
SendSerial() | Use the contents of the transmit buffer to build a packet and send it out the IR port. | ||||||
SendVLL() | Sends a Visible Light Link (VLL) command. |
VALUES / QUERIES
Message() | Returns the most recently received message. | ||||||
SerialData() | Returns the value of a byte in the transmit buffer (NOT received data). |
The RCX and Scout can send and receive simple messages using IR. A message can have a value from 0 to 255, but the use of message 0 is discouraged. The most recently received message is remembered and can be accessed as Message(). If no message has been received, Message() will return 0. Note that due to the nature of IR communication, receiving is disabled while a message is being transmitted.
|
The RCX2 can transmit serial data out the IR port. Prior to transmitting any data, the communication and packet settings must be specified. Then, for each transmission, data should be placed in the transmit buffer, then sent using the SendSerial() function.
The communication settings are set with SetSerialComm, and determine how bits are sent over IR. Possible values are shown below.
|
The default is to send data at 2400 baud using a 50% duty cycle on a 38kHz carrier. To specify multiple options (such as 4800 baud with 25% duty cycle), combine the individual options using bitwise or (SERIAL_COMM_4800 | SERIAL_COMM_DUTY25).
|
The packet settings are set with SetSerialPacket and control how bytes are assembled into packets. Possible values are shown below.
|
Note that negated packets always include a checksum, so the SERIAL_PACKET_CHECKSUM option is only meaningful when SERIAL_PACKET_NEGATED is not specified. Likewise the preamble, negated, and checksum settings are implied by SERIAL_PACKET_RCX.
|
The transmit buffer can hold up to 16 data bytes. These bytes may be set using SetSerialData, then transmitted by calling SendSerial. For example, the following code sends two bytes (0x12 and 0x34) out the serial port:
SetSerialComm(SERIAL_COMM_DEFAULT); SetSerialPacket(SERIAL_PACKET_DEFAULT); SetSerialData(0, 0x12); SetSerialData(1, 0x34); SendSerial(0, 2); |
FUNCTIONS / COMMANDS |
|
ClearMessage() | Overview | Top | ||||||
Clear the message buffer. This facilitates detection of the next received message since the program can then wait for Message() to become non-zero: ClearMessage(); // clear out the received message | |||||||
SendMessage(message) | Overview | Top | ||||||
Send an IR message. Message may be any expression, but the RCX can only send messages with a value between 0 and 255, so only the lowest 8 bits of the argument are used. SendMessage(3); // send message 3 | |||||||
SetTxPower(power) | Overview | Top | ||||||
Set the power level for IR transmission. Power should be one of the constants TX_POWER_LO or TX_POWER_HI. SetTxPower(TX_POWER_LO); | |||||||
SetSerialComm(settings) | Overview | Top | ||||||
Set the communication settings, which determine how the bits are sent over IR SetSerialComm(SERIAL_COMM_DEFAULT); | |||||||
SetSerialPacket(settings) | Overview | Top | ||||||
Set the packet settings, which control how bytes are assembled into packets. SetSerialPacket(SERIAL_PACKET_DEFAULT); | |||||||
SetSerialData(n, value) | Overview | Top | ||||||
Set one byte of data in the transmit buffer. N is the index of the byte to set (0-15), and value can be any expression. SetSerialData(3, x); // set byte 3 to x | |||||||
SendSerial(start, count) | Overview | Top | ||||||
Use the contents of the transmit buffer to build a packet and send it out the IR port - according to the current packet and communication settings. Start and count are both constants that specify the first byte and the number of bytes within the buffer to be sent. SendSerial(0,2); // send first two bytes in buffer | |||||||
SendVLL(value) | Overview | Top | ||||||
Sends a Visible Light Link (VLL) command, which can be used to communicate with the MicroScout or Code Pilot. The specific VLL commands are described in the Scout SDK. SendVLL(4); // send VLL command #4 | |||||||
VALUES / QUERIES |
|
Message() | Overview | Top | ||||||
Returns the most recently received message. | |||||||
SerialData(n) | Overview | Top | ||||||
Returns the value of a byte in the transmit buffer (NOT received data). N must be a constant between 0 and 15. x = SerialData(7); // read byte #7 | |||||||