Exemplo n.º 1
0
 /// <summary>
 /// Update format of message sent and message recieved if radiobuttons changes
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void rdb_comm_status_CheckedChanged(object sender, EventArgs e)
 {
     if (rdb_comm_status_dec.Checked)
     {
         txt_con_messageSendt.Text    = CommHandler.PacketToString(CommHandler.messageSendt);
         txt_con_messageRecieved.Text = CommHandler.PacketToString(CommHandler.messageRecieved);
     }
     else if (rdb_comm_status_hex.Checked)
     {
         txt_con_messageSendt.Text    = CommHandler.PacketToHEXString(CommHandler.messageSendt);
         txt_con_messageRecieved.Text = CommHandler.PacketToHEXString(CommHandler.messageRecieved);
     }
     else if (rdb_comm_status_bytes.Checked)
     {
         txt_con_messageSendt.Text    = CommHandler.PacketToByteString(CommHandler.messageSendt);
         txt_con_messageRecieved.Text = CommHandler.PacketToByteString(CommHandler.messageRecieved);
     }
 }
Exemplo n.º 2
0
    private void tim_100ms_update_Tick(object sender, EventArgs e)
    {
        //serial connection
        if (CommHandler.initialized)
        {
            //the button to update
            Button btn;
            switch (CommHandler.connectionType)
            {
            case CommHandler.ConnectionType.Serial:
                btn = btn_comm_serialConnect;
                break;

            case CommHandler.ConnectionType.Ethernet:
                btn = btn_comm_ethernetConnect;
                break;

            case CommHandler.ConnectionType.CANbus:
                btn = btn_comm_CANconnect;
                break;

            default:
                btn = null;
                break;
            }

            //update connection button color
            if (CommHandler.GetConnectionStatus() == CommHandler.ConnectionStatus.Connected)
            {
                btn.BackColor = System.Drawing.Color.SpringGreen;                 //Darg green?, ForrestGreen? LimeGreen? SpringGreen?
                //btn_connect_serial.ForeColor = System.Drawing.Color.White;
            }

            else if (CommHandler.GetConnectionStatus() == CommHandler.ConnectionStatus.NotConnected)
            {
                btn.UseVisualStyleBackColor = true;
                btn.ForeColor = System.Drawing.SystemColors.MenuHighlight;
            }

            else if (CommHandler.GetConnectionStatus() == CommHandler.ConnectionStatus.Disconnected)
            {
                btn.BackColor = System.Drawing.Color.Red;                 //Firebrick?
                btn.ForeColor = System.Drawing.Color.White;
            }


            if (CommHandler.newMessage)
            {
                if (rdb_comm_status_dec.Checked)
                {
                    txt_con_messageSendt.Text    = CommHandler.PacketToString(CommHandler.messageSendt);
                    txt_con_messageRecieved.Text = CommHandler.PacketToString(CommHandler.messageRecieved);
                }
                else if (rdb_comm_status_hex.Checked)
                {
                    txt_con_messageSendt.Text    = CommHandler.PacketToHEXString(CommHandler.messageSendt);
                    txt_con_messageRecieved.Text = CommHandler.PacketToHEXString(CommHandler.messageRecieved);
                }
                else if (rdb_comm_status_bytes.Checked)
                {
                    txt_con_messageSendt.Text    = CommHandler.PacketToByteString(CommHandler.messageSendt);
                    txt_con_messageRecieved.Text = CommHandler.PacketToByteString(CommHandler.messageRecieved);
                }

                CommHandler.newMessage = false;
            }


            //TEMP reset zero depth click
            //ST_Register.commands[801] = 0;
        }



        //temp

        /*
         * byte[] b = new byte[9] { 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
         * KeyValuePair<int, int>[] a;
         * a = CommHandler.AegirConvertData(13, b);
         * ST_Register.status[4] = a[0].Value;
         */



        if (sendHeartbeat)
        {
            if (st.status[0] == 0)
            {
                //try { CommHandler.Send(0, 1); } catch { Program.errors.Add("No serial connection for heartbeat"); }
            }
            else if (st.status[0] > 0)
            {
                //try { CommHandler.Send(0, 0); } catch { Program.errors.Add("No serial connection for heartbeat"); }
            }

            sendHeartbeat = false;
        }


        //display error messages if they are updated
        if (Program.errors.HaveUpdated())
        {
            txt_error.Text = Program.errors.ToString();
        }
    }