Ruida

The educational technology and digital learning wiki
Jump to navigation Jump to search

Introduction

Ruida controllers are laser cutter controller boards with several beefier features. They are built for lasering, and run a download and execute scheme. They are natively supported by RDWorks (which is free) and supported by Lightburn (Proprietary, $80). They have a control panel that can often display the program to be run and perform jogging operations. There have been a number of reverse engineering and supporting operations.

Ruida controllers can control 4 axises. These are X, Y, Z, and U.

Protocol

The laser can be controlled through a few different means. It accepts USB files in an .rd format, it can be set to listen for UDP packets on port 50200, and can directly transfer files via USB to the device.

UDP

UDP packets requires an extra 16 bit checksum for each packet. Since UDP can lose packets it requires an ACK reply after every packet. The checksum doesn't require any special operations it's literally just the lower 16 bits sum of the value of each byte in the packet. Beyond those differences the remaining elements are Ruida commands which follow a fairly well understood structure.

The first two bytes of any UDP packet are LSB checksum. This response to this is either 0xCC Checksum match or 0xCF checksum fail. On fail the packet must be resent. Too long of a time will cause a time out.

In UDP the packet size is limited to 1474 bytes. However most modern versions simply cut at around 1000 bytes. These cuts are permitted to occur mid-command but modernly do not do that. They cut at command boundaries.

USB

There are two methods of USB transfer, direct transfer with a USB device between the machine and computer, and through the use of a thumb drive.


Swizzling

All packet data is lightly swizzled at the byte level. The checksum is calculated preswizzle.

Swizzling:

       b ^= (b >> 7) & 0xFF
       b ^= (b << 7) & 0xFF
       b ^= (b >> 7) & 0xFF
       b ^= 0xB0
       b ^= 0x38
       b = (b + 1) & 0xFF

Unswizzling:

       b = (b - 1) & 0xFF
       b ^= 0xB0
       b ^= 0x38
       b ^= (b >> 7) & 0xFF
       b ^= (b << 7) & 0xFF
       b ^= (b >> 7) & 0xFF
       return b

The general algorithm swaps the first and last digit, xors the data and adds 1. The reverse unswizzling requires subtracting one, xor, and swapping the first and last digit. In the presented code the swap is done there with an xor swap.

Ruida Encoding

Each command in Ruida starts with a a high bit meaning all bytes sent that are 0x80 or above are commands. All other bytes consequently cannot use that bit. This leads to the two other main unit types.

  • One byte integer.
  • 14 bit signed integer.
  • 14 bit unsigned integer.
  • 32 bit signed number
  • 32 bit unsigned number.

The 32 bit numbers require 5 bytes (5 * 7 bits) which gives 35 bits. The top three are simply ignored.

Values

Absolute Coordinate. This is stored as a signed 32 bit integer 5 byte integer. The distance is in micrometers.

Relative Coordinate. This is stored as a signed 14 bit integer 2 byte integer. The distance is in micrometers.

0x88 Move To Absolute

0x88 is 2 absolute coordinate for X and Y. The command is:

  • 88 XX XX XX XX XX YY YY YY YY YY -- 11 bytes.

0x89 Move To Relative

0x89 is 2 relative coordinates for x and Y. The command is:

  • 89 XX XX YY YY - 5 bytes.

0xA8 Cut To Absolute

0xA8 is 2 absolute coordinates for X and Y. The command is:

0xA8 XX XX XX XX XX YY YY YY YY YY -- 11 bytes.

0xA9 Cut To Relative

0xA9 is 2 relative coordinates for x and Y. The command is:

  • A9 XX XX YY YY - 5 bytes.

0xAA Horizontal Cut To Relative

0xAA is 1 relative coordinate for X. The command is:

AA XX XX - 3 bytes

0xAB Vertical Cut To Relative

0xAB is 1 relative coordinate for Y. The command is:

AB YY YY - 3 bytes

0xC6 Set Property

0xC6 sets a particular properties some are known, some are not.

  • 0x01 <Power> -- Sets Power1 Minimum.
  • 0x02 <Power> -- Sets Power1 Maximum.
  • 0x05 <2 bytes> -- Unknown.
  • 0x07 <2 bytes> -- Unknown.
  • 0x08 <2 bytes> -- Unknown.
  • 0x15 -- Unknown
  • 0x16 -- Unknown
  • 0x21 <Power> -- Sets Power2 Minimum.
  • 0x22 <Power> -- Sets Power2 Maximum.
  • 0x31 <3 bytes> - Unknown. #1 in sequence
  • 0x32 <3 bytes> - Unknown. #2 in sequence
  • 0x35 <3 bytes> - Unknown. #5 in sequence
  • 0x36 <3 bytes> - Unknown. #6 in sequence
  • 0x37 <3 bytes> - Unknown. #7 in sequence
  • 0x38 <3 bytes> - Unknown. #8 in sequence
  • 0x41 <3 bytes> - Unknown. #4 in sequence
  • 0x42 <3 bytes> - Unknown. #5 in sequence

0xC9 Set Speed

0xC9 set the speed. Speeds are in micrometers / sec.

  • 0x02 <Speed> - 7 bytes
  • 0x04 0x00 <Speed> - 8 bytes

0xCA Unknown Set Coords?

  • 0x01 <1 byte>
  • 0x02 <1 byte>
  • 0x03 <1 byte>
  • 0x06 <5 bytes> -- 7 bytes
  • 0x10 <1 byte>
  • 0x22 <1 byte>
  • 0x41 <2 bytes> -- 4 bytes.

0xCC ACK

Acknowledgment from Machine.

0xCD ERROR

Error from the machine

0xD7 Finishing

A few bytes sequences are finishing bytes. D7 is seen at the end. It's not clear what it does. It doesn't have any payload.

0xD8 Unknown Program

These elements are only seen when planning on starting some programmed cuts.

  • 0x00 -- #5 seen in sequence.
  • 0x12 -- #1 seen in sequence.
  • 0x2C -- Home the Z axis.
  • 0x2D -- Home the U axis.
  • 0x2E -- Focus.

0xD9 Jog Move.

  • PARAM 1 Byte:
   * 0x00 (Origin) Move with Origin.
   * 0x01 (Light/Origin) Move with Light and Origin.
   * 0x02 () Move
   * 0x03 (Light) Move with Light On
  • 0x00 <PARAM> <ABSCOORD> -- Move X
  • 0x01 <PARAM> <ABSCOORD> -- Move Y
  • 0x02 <PARAM> <ABSCOORD> -- Move Z
  • 0x03 <PARAM> <ABSCOORD> -- Move U
  • 0x10 <PARAM> Home XY

0xDA Data Exchange

Requests data from the machine. To work successfully the reply to 05 7E is 0x65006500.

  • IO 1 Byte
   * 0x00 Requesting Data.
   * 0x01 Sending Data.
  • 0xDA <IO=0x00> <2 Byte>
  • 0xDA <IO=0x01>

The data between the two flows both ways between program and controller.

Data Byte 0x00

  • 0x04: Item 1 and 6 in the preamble for most commands.
  • 0x05: Unknown
  • 0x10: Startup 1. First request on starting of RDWorks.
  • 0x1E: Startup 2. Second request on starting of RDWorks.
  • 0x20: X Position Request.
  • 0x21: Item 4 in the preamble for most commands.
  • 0x30: Y Position Request.
  • 0x31: Item 5 in the preamble for most commands.
  • 0x36: Item 3 in the preamble for most commands.
  • 0x40: Z Position Request.
  • 0x50: U Position Request.

Data Byte 0x04

  • 0x00: Reply 0x22. Unknown but replying 0x22 is known.
  • 0x05: Previous Work Time. Work time in seconds.
  • 0x08: Previous Work Time2. Work time in seconds.
  • 0x21: Position X.
  • 0x31: Position Y.
  • 0x41: Position Z.
  • 0x51: Position U.

Data Byte 0x05

  • 0x7E: Reply must be 0x65006500 or things go poorly.
  • 0x12: Item 5B in the preamble for most commands. (Sometimes this is 5th item).


0xE7 Program Items

  • filename is a c-string some number of characters followed with a 0x00
  • 0xE7 0x00 - Is only seen at Finishing.
  • 0xE7 0x01 <* bytes> 0x00 - <c_string: filename for transfer>
  • 0xE7 0x03 <10 bytes> - Program Item 7
  • 0xE7 0x04 <15 bytes> - Program Item 11
  • 0xE7 0x05 <1 byte> - Program Item 12
  • 0xE7 0x06 <10 bytes> - Program Item 6
  • 0xE7 0x07 <12 bytes> - Program Item 8 (This value is the same as F2 05 value.)
  • 0xE7 0x13 <10 bytes> - Unknown
  • 0xE7 0x17 <10 bytes> - Unknown
  • 0xE7 0x23 <10 bytes> - Unknown
  • 0xE7 0x24 <1 byte> - Unknown
  • 0xE7 0x50 <10 bytes> - Program Item 9
  • 0xE7 0x51 <10 bytes> - Program Item 10
  • 0xE7 0x52 <10 bytes> - Coord 52
  • 0xE7 0x53 <10 bytes> - Coord 53
  • 0xE7 0x54 <1 byte: 0x00 or 0x01> <5 bytes> - Coord 54
  • 0xE7 0x55 <1 byte: 0x00 or 0x01> <5 bytes> - Coord 55
  • 0xE7 0x60 <1 byte> - Unknown
  • 0xE7 0x61 <10 bytes> - Coord 61
  • 0xE7 0x62 <10 bytes> - Coord 62

0xE8 File Transfer

  • File Number is a 14 bit integer
  • filename is a c-string some number of characters followed with a 0x00
  • 0xE8 0x01 <filenumber> <c_string filename>
  • 0xE8 0x02 This is followed by the 0xE7 0x01

0xEA Unknown

  • 0xEA <1 byte> Unknown.

0xEB End Cut

  • 0xEB - Ends Cutting commands.

0xF0 Program Item 2

  • 0xF0 - Program Item 2

0xF1 Unknown

  • 0xF1 0x00 <1 Byte> - Unknown.
  • 0xF1 0x01 <1 Byte> - Unknown.
  • 0xF1 0x02 <1 byte> - Program Item 3
  • 0xF1 0x03 <10 bytes> - Unknown
  • 0xF1 0x04 <1 byte> - Program Item 4
  • 0xF1 0x20 <2 bytes> - Unknown.

0xF2 Unknown

  • 0xF2 0x00 <1 Byte> - Unknown.
  • 0xF2 0x01 <1 Byte> - Unknown.
  • 0xF2 0x02 <10 bytes> - Unknown.
  • 0xF2 0x03 <10 bytes> - Unknown.
  • 0xF2 0x04 <10 bytes> - Unknown.
  • 0xF2 0x05 <12 bytes> - Unknown. (This value is the same as E7 07 value.)
  • 0xF2 0x06 <12 bytes> - Unknown
  • 0xF2 0x07 <1 byte> - Unknown.