Example #1
0
        /// <summary>
        /// Transfers message data to a byte array for transfer.
        /// </summary>
        /// <returns>
        /// Command Structure:
        /// [Type XYZ P] [SpeedUpper7 P] [SpeedLower7 P] [0000 0 SU1 SL1 P] [Parity]
        /// -  Type: 5
        /// -   XYZ: 110 would set the speed for X and Y, but not Z
        /// - Speed: 16 bit unsigned int, a range of about 64k
        /// </returns>
        public override byte[] toSerial()
        {
            // Build first byte [Type 0 XYZ] --> [0101 0XYZ]
            byte TypeAndAxis = getMsgTypeByte();

            if (_X)
            {
                TypeAndAxis |= 0x08;
            }                                // Set X bit [0000 1000]
            if (_Y)
            {
                TypeAndAxis |= 0x04;
            }                                // Set Y bit [0000 0100]
            if (_Z)
            {
                TypeAndAxis |= 0x02;
            }                                // Set Z bit [0000 0010]

            byte[] speedBytes = CNCRTools.generateThreeBytesFromUInt16(_speed);

            byte[] result = { TypeAndAxis,   speedBytes[0],
                              speedBytes[1], speedBytes[2], 0 };
            CNCRTools.generateParity(ref result);
            return(result);
        }
Example #2
0
        /// <summary>
        /// Transfers CNCRMsgEStop to a byte array for transfer.
        /// </summary>
        /// <returns>
        /// Command Structure:
        ///     [Type 000 P] [Parity]
        /// </returns>
        public override byte[] toSerial()
        {
            // [0010 000 P] [Parity]
            byte Type = getMsgTypeByte();

            byte[] result = { Type, 0 };
            CNCRTools.generateParity(ref result);
            return(result);
        }
Example #3
0
        /// <summary>
        /// Converts message data to a byte array for transfer over serial.
        /// </summary>
        /// <returns>
        /// Command Structure:
        /// [Type 000 P] [#Cmds P] [255]
        /// -     Type: 3
        /// -    #Cmds: 7 bits, gives a range of 1 to 128.
        /// </returns>
        public override byte[] toSerial()
        {
            byte Type     = getMsgTypeByte();
            byte CmdCount = Convert.ToByte(_cmdCnt << 1);

            byte[] result = { Type, CmdCount, 0 };   // Build the result array.
            // generate parity
            CNCRTools.generateParity(ref result);
            return(result);
        }
Example #4
0
        /// <summary>
        /// Transfers the message data to a byte array for transfer.
        /// </summary>
        /// <returns>
        /// Command Structure:
        /// [Type 00 isEndQueue P] [Parity]
        /// -        Type: 4
        /// - isStopQueue: Set to 1 to indicate an end of the build process.
        /// </returns>
        public override byte[] toSerial()
        {
            byte typeEndQueue = getMsgTypeByte();

            if (_isEndQueue)
            {
                typeEndQueue |= 0x02; // Set the EndQueue bit.
            }
            byte[] result = { typeEndQueue, 0 };
            CNCRTools.generateParity(ref result);
            return(result);
        }
Example #5
0
        /// <summary>
        /// Transfers the message data to a byte array for transfer.
        /// </summary>
        /// <returns>
        /// [Type 00 OnOff P][Parity]
        /// -  Type: 7
        /// - OnOff: 0 for off, 1 for on
        /// </returns>
        public override byte[] toSerial()
        {
            byte TypeOnOff = getMsgTypeByte();

            if (_toolOn)
            {
                TypeOnOff |= 0x02;
            }                                   // If tool on, set the bit.

            byte[] result = { TypeOnOff, 0 };
            CNCRTools.generateParity(ref result);
            return(result);
        }
Example #6
0
        /// <summary>
        /// Outputs the message in a format that can be sent over the
        /// serial connection.
        /// </summary>
        /// <returns>
        /// Command Structure:
        /// [Type 000] [UpperX] [LowerX] [EndsX]
        ///            [UpperY] [LowerY] [EndsY]
        ///            [UpperZ] [LowerZ] [EndsZ]
        ///            [Parity]
        /// </returns>
        public override byte[] toSerial()
        {
            byte Type = getMsgTypeByte();

            byte[] xBits  = CNCRTools.generateThreeBytesFromInt16(getX());
            byte[] yBits  = CNCRTools.generateThreeBytesFromInt16(getY());
            byte[] zBits  = CNCRTools.generateThreeBytesFromInt16(getZ());
            byte[] result = { Type,
                              xBits[0],xBits[1],  xBits[2],
                              yBits[0],yBits[1],  yBits[2],
                              zBits[0],zBits[1],  zBits[2],
                              0 };
            CNCRTools.generateParity(ref result);
            return(result);
        }
Example #7
0
        /// <summary>
        /// Transfers CNCRMsgCmdAck data to a byte array for transfer.
        /// </summary>
        /// <returns>
        /// Structure of result:
        ///     0001 001 0 | 0000 000 0 | Parity
        ///     type err P | firmware P | Parity
        /// </returns>
        public override byte[] toSerial()
        {
            // Set top 4 bits to "0001"
            byte TypeAndErr = getMsgTypeByte();

            // Set the error flag.
            if (_isError)
            {
                TypeAndErr |= 0x02;
            }

            byte[] result = { TypeAndErr, Convert.ToByte(_firmware << 1), 0 };

            // Set the parity bits and byte.
            CNCRTools.generateParity(ref result);
            return(result);
        }