Example #1
0
        public void SendCommand(MTRFXXMode mode, MTRFXXAction action, byte channel, MTRFXXCommand command,
                                MTRFXXRepeatCount repeatCount = MTRFXXRepeatCount.NoRepeat, MTRFXXDataFormat format = MTRFXXDataFormat.NoData,
                                byte[] data = null, UInt32 target = 0)
        {
            var cmd = BuildCommand(mode, action, repeatCount, channel, command, format, data, target);

            device.Write(cmd, 0, cmd.Length);
        }
Example #2
0
        public static byte[] BuildCommand(MTRFXXMode mode, MTRFXXAction action, MTRFXXRepeatCount repeatCount, byte channel,
                                          MTRFXXCommand command, MTRFXXDataFormat format, byte[] data, UInt32 target = 0)
        {
            byte actionAndRepeatCount = (byte)((byte)action | ((byte)repeatCount << 6));
            byte id1 = (byte)(target >> 24);
            byte id2 = (byte)(target >> 16);
            byte id3 = (byte)(target >> 8);
            byte id4 = (byte)target;

            byte[] d = data ?? new byte[0];

            byte d1 = d.Length > 0 ? d[0] : (byte)0;
            byte d2 = d.Length > 1 ? d[1] : (byte)0;
            byte d3 = d.Length > 2 ? d[2] : (byte)0;
            byte d4 = d.Length > 3 ? d[3] : (byte)0;

            var res = new byte[]
            {
                START_MARKER,         // 0: start marker
                (byte)mode,           // 1: device mode
                actionAndRepeatCount, // 2: action & repeat count
                0,                    // 3: reserved
                channel,              // 4: channel
                (byte)command,        // 5: command
                (byte)format,         // 6: data format
                d1, d2, d3, d4,       // 7..10: data
                id1, id2, id3, id4,   // 11..14: target device id
                0,                    // 15: checksum
                STOP_MARKER           // 16: stop marker
            };

            for (int i = 0; i < 15; i++)
            {
                res[15] += res[i];
            }

            return(res);
        }