def message_write(self, inbox, message): """Send a message to a brick mailbox. :param int inbox: Mailbox number (0 to 19). :param bytes message: Message to send (58 bytes maximum). """ if len(message) > 58: raise ValueError("message too long") tgram = Telegram(Opcode.DIRECT_MESSAGE_WRITE) tgram.add_u8(inbox) tgram.add_u8(len(message) + 1) tgram.add_bytes(message) tgram.add_u8(0) self._cmd(tgram)
def file_write(self, handle, data): """Write data to open file. :param int handle: Open file handle. :param bytes data: Data to write. :return: The file handle and the number of bytes written. :rtype: (int, int) .. warning:: This is a low level function, prefer to use :meth:`open_file`. """ tgram = Telegram(Opcode.SYSTEM_WRITE) tgram.add_u8(handle) tgram.add_bytes(data) tgram = self._cmd(tgram) handle = tgram.parse_u8() size = tgram.parse_u16() return handle, size
def ls_write(self, port, tx_data, rx_bytes): """Write data to a brick input port using low speed transaction. :param nxt.sensor.Port port: Input port identifier. :param bytes tx_data: Data to send. :param int rx_bytes: Number of bytes to receive. Function returns immediately. Transaction status can be retrieved using :meth:`ls_get_status` and result must be read using :meth:`ls_read`. .. warning:: This is a low level function, prefer to use a :mod:`nxt.sensor` class. """ tgram = Telegram(Opcode.DIRECT_LS_WRITE) tgram.add_u8(port.value) tgram.add_u8(len(tx_data)) tgram.add_u8(rx_bytes) tgram.add_bytes(tx_data) self._cmd(tgram)
def write_io_map(self, mod_id, offset, data): """Write module IO map on the brick. :param int mod_id: Module identifier. :param int offset: Offset in IO map. :param bytes data: Data to write. :return: Module identifier and written size. :rtype: (int, int) Module identifier can be found using :meth:`find_modules`. You need to know the structure of the module IO map. You can find it by reading the firmware source code. """ tgram = Telegram(Opcode.SYSTEM_IOMAPWRITE) tgram.add_u32(mod_id) tgram.add_u16(offset) tgram.add_u16(len(data)) tgram.add_bytes(data) tgram = self._cmd(tgram) mod_id = tgram.parse_u32() size = tgram.parse_u16() return mod_id, size
def boot(self, *, sure=False): """Erase NXT brick firmware and go to SAM-BA boot mode. :param bool sure: Set to ``True`` if you are really sure. Must be a keyword parameter. :return: Brick response, should be ``"Yes\0"``. :rtype: bytes This only works on USB connection. .. danger:: This **erases the firmware** of the brick, you need to send a new firmware to use it. Sending a firmware is not supported by NXT-Python. You can use the original LEGO software or `libnxt`_ for example. Be sure to know what you are doing. .. _libnxt: https://git.ni.fr.eu.org/libnxt.git/ """ if not sure: raise ValueError("this is dangerous, please read documentation") tgram = Telegram(Opcode.SYSTEM_BOOTCMD) tgram.add_bytes(b"Let's dance: SAMBA\0") tgram = self._cmd(tgram) resp = tgram.parse_bytes() return resp