Mailbox messages maximum size

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
ricardocrl
Posts: 117
Joined: 27 Dec 2010, 19:27

Mailbox messages maximum size

Post by ricardocrl »

Hello all,

I've been working around mailboxes and I got my mind clear, finally. I'd like to share this, in case anyone else gets stuck trying to understand why can't we actually send 59 chars (excluding null-terminator).

Because of the 64 bytes limit, the WRITEMESSAGE direct command allows sending 59 bytes (without null terminator), as it is explained in the documentation that LEGO provides (communication protocol and direct commands).
I was so blind by this fact that I didn't realize that the overhead size of the MESSAGEREAD direct command is compromising the amount of bytes read.
Let's see:

MESSAGEWRITE:
Byte 0 - Command Type
Byte 1 - Command Number
Byte 2 - Inbox Number
Byte 3 - Message Size
Byte 4-N: Message data, where N = Message size +3
"Message size must be capped at 59 for all message packets to be legal on USB!"

MESSAGEREAD
Byte 0 - Command Type
Byte 1 - Command Number
Byte 2 - Status Byte
Byte 3 - Local Inbox number (0-9)
Byte 4 - Message size
Byte 5-63: Message data (padded)

This means that the message data bytes that can be used in the MESSAGEWRITE direct command are: byte 4-62. And so, 58 bytes + 1 (null-terminator) is the real limit.

I've already seen also this 58 limit, but didn't understand why.

I hope this helps. Good luck with the LEGO projects! ;)
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests