コード例 #1
0
ファイル: CNCRMessage.cs プロジェクト: pvince/AnalogMeter
 public override string ToString()
 {
     return("[ " + _msgType.ToString() +
            " - " + _priority.ToString() +
            " - ID: " + _msgID +
            " (" + CNCRTools.BytesToHex(this.toSerial()) + ") ]");
 }
コード例 #2
0
 private void DisplayDataQueue()
 {
     _displayLabel.Invoke(new EventHandler(delegate
     {
         _displayLabel.Text = string.Empty;
         byte[] bytesInQ    = _commBufferQueue.ToArray();
         _displayLabel.Text = CNCRTools.BytesToHex(bytesInQ);
     }));
 }
コード例 #3
0
 public void SendBytes(byte[] bytes)
 {
     if (!(comPort.IsOpen == true))
     {
         OpenPort();
     }
     if (comPort.IsOpen && (bytes.Length > 0))
     {
         comPort.Write(bytes, 0, bytes.Length);
     }
     else
     {
         DisplayData("Error: Failed to send bytes - [" +
                     CNCRTools.BytesToHex(bytes) + "]\n");
     }
     //comPort.Close();
 }
コード例 #4
0
        /// <summary>
        /// method that will be called when there is data waiting in the buffer
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void comPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            int bytes = comPort.BytesToRead;

            byte[] comBuffer = new byte[bytes];
            comPort.Read(comBuffer, 0, bytes);

            if (getDiscardingData())
            {
                DisplayData("Discarded: " + CNCRTools.BytesToHex(comBuffer) + "\n");
            }
            else
            {
                DisplayData("Received: " + CNCRTools.BytesToHex(comBuffer) + "\n");
                handleData(comBuffer);
                DisplayDataQueue();
            }
        }
コード例 #5
0
        public void SendMsg(CNCRMessage msg)
        {
            //TODO: SendMsg: Should this function really be doing this check?  Shouldnt the function errorhandler do this?
            if (getDiscardingData() &&                   // If we are discarding data.
                msg.getMessageType() == CNCRMSG_TYPE.CMD_ACKNOWLEDGE && // and sending an acknowledge
                ((CNCRMsgCmdAck)msg).getError() == true) // and that acknowledge is saying we have an error.
            {
                setDiscardingData(false);                // Then clear the discard data bit so we can see the response.
                byte[] serialStuff = msg.toSerial();
                string toDisplay   = "Ack Sent: " + CNCRTools.BytesToHex(msg.toSerial());
                toDisplay += "\n";

                DisplayData(toDisplay);
            }
            if (msg.getMessageType() != CNCRMSG_TYPE.CMD_ACKNOWLEDGE)
            {
                setWaitingOnAck(true);
            }
            setLastMessage(msg);
            DisplayData("Sending: " + msg.ToString() + "\n");
            SendBytes(msg.toSerial());
        }
コード例 #6
0
        private void btnSndMsg_Click(object sender, EventArgs e)
        {
            /*
             * int discarded = 0;
             * byte[] bytes = CNCRTools.GetBytes(txtHex.Text, out discarded);
             * lblDbgOut.Text = "";
             * for (int i = 0; i < bytes.Length; i++)
             * {
             *  lblDbgOut.Text += bytes[i].ToString() + " ";
             * }//*/

            byte[]      sendBytes = { 0 };
            CNCRMessage sendMsg   = null;

            switch (cmbMsgs.SelectedIndex)
            {
            case 0:
                int discarded = 0;
                sendBytes = CNCRTools.GetBytes(txtHex.Text, out discarded);
                break;

            case 1:
                sendMsg   = new CNCRMsgPing();
                sendBytes = sendMsg.toSerial();
                break;

            case 2:
                sendMsg   = new CNCRMsgCmdAck(false, 127);
                sendBytes = sendMsg.toSerial();
                break;

            case 3:
                sendMsg   = new CNCRMsgEStop();
                sendBytes = sendMsg.toSerial();
                break;

            case 4:
                sendMsg   = new CNCRMsgRequestCommands(128);
                sendBytes = sendMsg.toSerial();
                break;

            case 5:
                sendMsg   = new CNCRMsgStartQueue(false);
                sendBytes = sendMsg.toSerial();
                break;

            case 6:
                sendMsg   = new CNCRMsgSetSpeed(true, true, false, 40000);
                sendBytes = sendMsg.toSerial();
                break;

            case 7:
                sendMsg   = new CNCRMsgMove(Int16.MinValue, Int16.MaxValue, 0);
                sendBytes = sendMsg.toSerial();
                break;

            case 8:
                sendMsg   = new CNCRMsgToolCmd(true);
                sendBytes = sendMsg.toSerial();
                break;
            }
            rtbTraffic.AppendText(CNCRTools.BytesToHex(sendBytes) + "\n");
            if (sendMsg == null)
            {
                commCmd.SendBytes(sendBytes);
            }
            else
            {
                commCmd.SendMsg(sendMsg);
            }
        }