예제 #1
0
        private void RichTextBoxTxData_KeyPress(object sender, KeyPressEventArgs e)
        {
            try
            {
                if (_appConfig.SendOnKeyPress)
                {
                    var keyval = (byte)e.KeyChar;
                    _serialCom.Write(new byte[] { keyval });

                    var txstr = "";
                    if (keyval > 32 && keyval < 127)
                    {
                        txstr = e.KeyChar.ToString();
                    }
                    else
                    {
                        txstr = "0x" + keyval.ToString("X2");
                    }
                    AppendEventLog(txstr, Color.DarkGreen);
                }
                else if (e.KeyChar == '\n') //CTRL+ENTER
                {
                    e.Handled = true;
                    buttonSend.PerformClick();
                }
            }
            catch (Exception ex)
            {
                PopupException(ex.Message);
            }
        }
예제 #2
0
 public void Move(int x, int y, int moveTime)
 {
     if (x < 0 || x > 180)
     {
         throw new Exception($"X not between 0 and 180, value: {x}");
     }
     if (y < 0 || y > 180)
     {
         throw new Exception($"Y not between 0 and 180, value: {y}");
     }
     if (IsActive == false)
     {
         throw new Exception("Turret not active");
     }
     _com.Write(new PriorityMessage($"m:{x},{y}", 2, moveTime));
 }
예제 #3
0
        /// <summary>
        /// Send a SIP (Slave Interrupt Packet) to a master computer.
        /// </summary>
        /// <param name="deviceId">Id of the slave device who answered.</param>
        /// <param name="InterrupCode">The code of the interruption (0 to 255).</param>
        /// <returns>The error check data.</returns>
        public int SendInterruption(int deviceId, int InterrupCode)
        {
            byte[] hex;
            byte[] pkt = new byte[14];
            int    ecd;

            //Packet Type
            pkt[0] = (byte)'!';
            pkt[1] = (byte)'!';
            //ECA
            hex    = Encoding.Default.GetBytes(((int)ErrorCheckType).ToString("X1"));
            pkt[2] = hex[0];
            //Device ID
            hex    = Encoding.Default.GetBytes(deviceId.ToString("X3"));
            pkt[3] = hex[0];
            pkt[4] = hex[1];
            pkt[5] = hex[2];
            //Interruption Code
            hex    = Encoding.Default.GetBytes(InterrupCode.ToString("X2"));
            pkt[6] = hex[0];
            pkt[7] = hex[1];
            //CRC
            ecd     = ErrorCheck(pkt, 8, ErrorCheckType);
            hex     = Encoding.Default.GetBytes(ecd.ToString("X4"));
            pkt[8]  = hex[0];
            pkt[9]  = hex[1];
            pkt[10] = hex[2];
            pkt[11] = hex[3];
            //Packet End
            pkt[12] = (byte)'\r';
            pkt[13] = (byte)'\n';

            SerialCom.Write(pkt, 0, 14);
            return(ecd);
        }
        /// <summary>
        /// Send a MRP packet to a slave computer.
        /// </summary>
        /// <param name="deviceId">Id of the requested device in slave.</param>
        /// <param name="message">The message in bytes to be send.</param>
        /// <param name="msgLength">The message length.</param>
        /// <returns>The error check data.</returns>
        public int SendRequest(int deviceId, byte[] message, int msgLength)
        {
            byte[] hex;
            int    ecd;

            if (message.Length < msgLength)
            {
                msgLength = message.Length; //saturating
            }

            //mounting the packet
            byte[] pkt = new byte[msgLength + 15];
            //Packet Type
            pkt[0] = (byte)'!';
            pkt[1] = (byte)'?';
            //ECA

            hex = Encoding.Default.GetBytes(((int)ErrorCheckType).ToString("X1"));
            //hex = Encoding.Default.GetBytes(String.Format("{0:X1}", ErrorCheckType));
            pkt[2] = hex[0];
            //device Id
            hex    = Encoding.Default.GetBytes(deviceId.ToString("X3"));
            pkt[3] = hex[0];
            pkt[4] = hex[1];
            pkt[5] = hex[2];
            //Message length
            hex    = Encoding.Default.GetBytes(msgLength.ToString("X3"));
            pkt[6] = hex[0];
            pkt[7] = hex[1];
            pkt[8] = hex[2];
            //Message (payload)
            for (int i = 0; i < msgLength; i++)
            {
                pkt[9 + i] = message[i];
            }
            //Error checking
            ecd = ErrorCheck(pkt, msgLength + 9, ErrorCheckType);
            hex = Encoding.Default.GetBytes(ecd.ToString("X4"));
            pkt[9 + msgLength]     = hex[0];
            pkt[9 + msgLength + 1] = hex[1];
            pkt[9 + msgLength + 2] = hex[2];
            pkt[9 + msgLength + 3] = hex[3];
            //Packet End
            pkt[9 + msgLength + 4] = (byte)'\r';
            pkt[9 + msgLength + 5] = (byte)'\n';

            //Sending request
            SerialCom.Write(pkt, 0, 15 + msgLength);
            return(ecd);
        }