Exemple #1
0
        private void ReadClick()
        {
            s                     = ConState.read;
            dataerrer             = true;
            issessce              = false;
            Common.Common.massage = "";
            if (PortCommunication.ComName == null)
            {
                mondelName.Text = "Select Port ...";
                GetComList(); //获取端口
                if (PortCommunication.ComName == null)
                {
                    MsgBox.Show("Please Select Port ...");
                    SetEnable(true);
                    return;
                }
            }

            //lg = new Loading();
            //lg.Location = new Point(this.Width / 2 - lg.Width / 2,  this.Height / 2 - lg.Height / 2);
            //lg.TopLevel = false;
            //try
            //{
            //    lg.Parent = this;
            //}
            //catch (Exception)
            //{

            //    ;
            //}

            try
            {
                PortCommunication.NewSerialPort();

                PortCommunication.openPort();
            }
            catch (Exception)
            {
                MsgBox.Show("The port failed to open, please check the port!");
                SetEnable(true);
                return;
            }

            conn = new Thread(br3.readMessage);


            conn.IsBackground = true;
            //timerSend.Interval = timeout;

            PortCommunication.timerSend.Interval = PortCommunication.timeout;
            PortCommunication.timerSend.Enabled  = true;
            PortCommunication.timerSend.Start();

            //timerSend.Start();
            //timer1.Start();
            SetEnable(false);
            conn.Start();
        }
Exemple #2
0
        private void WriteClick()
        {
            s                     = ConState.write;
            dataerrer             = true;
            issessce              = false;
            Common.Common.massage = "";
            //writeP();
            if (PortCommunication.ComName == null)
            {
                mondelName.Text = "Select Port ...";
                GetComList(); //获取端口
                if (PortCommunication.ComName == null)
                {
                    MessageBox.Show("Please Select Port ...");
                    foreach (Control item in this.Controls)
                    {
                        item.Enabled = true;
                    }
                    return;
                }
            }
            //lg = new Loading();

            //lg.Location = new Point(this.Width / 2 - lg.Width / 2, this.Height / 2 - lg.Height / 2);
            //lg.TopLevel = false;
            //lg.Parent = this;
            try
            {
                PortCommunication.NewSerialPort();

                PortCommunication.openPort();
            }
            catch (Exception)
            {
                MessageBox.Show("The port failed to open, please check the port!");
                foreach (Control item in this.Controls)
                {
                    item.Enabled = true;
                }
                return;
            }

            conn = new Thread(br3.writeMessage);



            conn.IsBackground = true;
            PortCommunication.timerSend.Interval = PortCommunication.timeout;
            PortCommunication.timerSend.Enabled  = true;
            PortCommunication.timerSend.Start();
            //timer1.Start();
            foreach (Control item in this.Controls)
            {
                item.Enabled = false;
            }
            conn.Start();
            //lg.BringToFront();
            //lg.Show();
        }
Exemple #3
0
        /// <summary>
        /// Handles the Click event of the BtnClose control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs" /> instance containing the event data.</param>
        private void BtnClose_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            PortCommunication.ClosePort(serialPort);

            dynamic parentWindow = Window.GetWindow(this) as MainWindow;

            parentWindow.LoadIndex(sender, e);
        }
Exemple #4
0
        private void OpenPort()
        {
            if (serialPort == null)
            {
                throw new NullReferenceException(Properties.Resources.DeviceNotFoundError);
            }

            PortCommunication.OpenPort(serialPort);
        }
Exemple #5
0
 internal static bool BR3Read()
 {
     for (int i = 0; i < 32 * 8; i++)
     {
         recive[i] = PortCommunication.reciveMsg(BR3SendCode.readSendCode + " " + Common.Common.decToHex(BR3SendCode.readStartAdress + i * 8, 8) + " " + Common.Common.decToHex(BR3SendCode.readAdressLenth), BR3SendCode.readAdressLenth + 4);
         MainForm.barEditItem3.Value = (4 + i / 3) / 1;
     }
     PortCommunication.sendMassge("62");
     return(true);
 }
        /// <summary>
        /// Renders the result.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        public void RenderResult(object sender, RoutedEventArgs e)
        {
            PortCommunication.ClosePort(serialPort);

            var dataContext = this.DataContext as MessuresViewModel;

            dynamic parentWindow = Window.GetWindow(this) as MainWindow;

            parentWindow.contentControl.Content = new Result(dataContext);
        }
Exemple #7
0
        internal static bool connect()
        {
            PortCommunication.senderMsg(BR3SendCode.connSendCode, BR3SendCode.connReciveCode, 1);
            MainForm.barEditItem3.Value = 1;

            PortCommunication.senderMsg(BR3SendCode.connSendSure, BR3SendCode.connReciveSure, 8);
            MainForm.barEditItem3.Value = 2;
            PortCommunication.senderMsg(BR3SendCode.connReSureCode, BR3SendCode.connReciveCode, 1);
            MainForm.barEditItem3.Value = 3;
            //lblConnect.Text = "握手完成";
            //progressBar1.Value = 4;
            //MsgBox.Show("握手成功");
            return(true);
        }
Exemple #8
0
        /// <summary>
        /// 连接超时
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void timerSend_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            PortCommunication.timerSend.Enabled = false;
            if (conn.IsAlive)
            {
                conn.Abort();
            }

            PortCommunication.closePort();
            barEditItem3.Value = 0;
            if (dataerrer == true)
            {
                if (!issessce)
                {
                    if (conCount < 1)
                    {
                        conCount++;
                        Thread.Sleep(100);
                        if (s == ConState.read)
                        {
                            ReadClick();
                        }
                        else if (s == ConState.write)
                        {
                            WriteClick();
                        }
                    }
                    else
                    {
                        Common.Common.massage = "Connect Time Out";
                        SetEnable(true);
                        MsgBox.Show(Common.Common.massage);
                    }
                }
                else
                {
                    SetEnable(true);

                    MsgBox.Show(Common.Common.massage);
                }
            }
            else
            {
                SetEnable(true);
            }
        }
        /// <summary>
        /// Handles the Click event of the btnTakeSample control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        private void TakeSamples(object sender, RoutedEventArgs e)
        {
            if (serialPort == null)
            {
                throw new NullReferenceException(HaenggiModel.Presentation.Properties.Resources.DeviceNotFoundError);
            }

            if (serialPort.IsOpen)
            {
                PortCommunication.ClosePort(serialPort);
                ToogleButtons(true);
            }
            else
            {
                PortCommunication.OpenPort(serialPort);
                txt17.Focus();
                ToogleButtons(false);
            }
        }
Exemple #10
0
        internal static bool BR3Write(Class.BR3Class br3)
        {
            string str;

            PortCommunication.senderMsg(BR3SendCode.writeSendCode + " " + Common.Common.decToHex(BR3SendCode.writeStartAdress + 0 * 8, 8) + " " + Common.Common.decToHex(BR3SendCode.writeAdressLenth) + " " + BR3SendCode.writeNull, BR3SendCode.connReciveCode, 1);
            PortCommunication.senderMsg(BR3SendCode.writeSendCode + " " + Common.Common.decToHex(BR3SendCode.writeStartAdress + 1 * 8, 8) + " " + Common.Common.decToHex(BR3SendCode.writeAdressLenth) + " " + BR3SendCode.writeNull, BR3SendCode.connReciveCode, 1);
            for (int i = 0; i < 99; i++)
            {
                if (i < br3.DtRowCount)
                {
                    if (br3.Channel.Rows[i][Class.ChannelBR3.TXFrequency] != null && br3.Channel.Rows[i][ChannelBR3.TXFrequency].ToString() != "")
                    {
                        PortCommunication.senderMsg(BR3SendCode.writeSendCode + " " + Common.Common.decToHex(BR3SendCode.writeStartAdress + (i + 1) * 16, 8) + " " + Common.Common.decToHex(BR3SendCode.writeAdressLenth)
                                                    + " " + decFrequencyToHex(Convert.ToDouble(br3.Channel.Rows[i][ChannelBR3.TXFrequency])) + " " + decFrequencyToHex(Convert.ToDouble(br3.Channel.Rows[i][ChannelBR3.RXFrequency]))
                                                    , BR3SendCode.connReciveCode, 1);
                        str = br3.Channel.Rows[i][ChannelBR3.Clone].ToString() == "Yes" ? "ff" : "fe";
                        PortCommunication.senderMsg(BR3SendCode.writeSendCode + " " + Common.Common.decToHex(BR3SendCode.writeStartAdress + (i + 1) * 16 + 8, 8) + " " + Common.Common.decToHex(BR3SendCode.writeAdressLenth)
                                                    + " " + CTCSToHex(br3.Channel.Rows[i][ChannelBR3.CTCSDec].ToString()) + " " + CTCSToHex(br3.Channel.Rows[i][ChannelBR3.CTCSEnc].ToString())
                                                    + " " + ChannelParam(br3.Channel.Rows[i]) + " " + str + " ff ff"
                                                    , BR3SendCode.connReciveCode, 1);
                    }
                    else
                    {
                        PortCommunication.senderMsg(BR3SendCode.writeSendCode + " " + Common.Common.decToHex(BR3SendCode.writeStartAdress + (i + 1) * 16, 8) + " " + Common.Common.decToHex(BR3SendCode.writeAdressLenth)
                                                    + " ff ff ff ff ff ff ff ff"
                                                    , BR3SendCode.connReciveCode, 1);

                        PortCommunication.senderMsg(BR3SendCode.writeSendCode + " " + Common.Common.decToHex(BR3SendCode.writeStartAdress + (i + 1) * 16 + 8, 8) + " " + Common.Common.decToHex(BR3SendCode.writeAdressLenth)
                                                    + " ff ff ff ff ff ff ff ff"
                                                    , BR3SendCode.connReciveCode, 1);
                    }
                }
                else
                {
                    PortCommunication.senderMsg(BR3SendCode.writeSendCode + " " + Common.Common.decToHex(BR3SendCode.writeStartAdress + (i + 1) * 16, 8) + " " + Common.Common.decToHex(BR3SendCode.writeAdressLenth)
                                                + " ff ff ff ff ff ff ff ff"
                                                , BR3SendCode.connReciveCode, 1);

                    PortCommunication.senderMsg(BR3SendCode.writeSendCode + " " + Common.Common.decToHex(BR3SendCode.writeStartAdress + (i + 1) * 16 + 8, 8) + " " + Common.Common.decToHex(BR3SendCode.writeAdressLenth)
                                                + " ff ff ff ff ff ff ff ff"
                                                , BR3SendCode.connReciveCode, 1);
                }

                MainForm.barEditItem3.Value = Convert.ToInt32(i / 1.2 + 4);//82.5+4
            }
            string[] dis = CodeToHex(br3.Display);
            //57 07 90 08
            PortCommunication.senderMsg(BR3SendCode.writeSendCode + " " + Common.Common.decToHex(BR3SendCode.dispalyAdress1, 8) + " " + Common.Common.decToHex(BR3SendCode.writeAdressLenth)
                                        + " " + dis[0] + " " + dis[1] + " " + dis[2] + " " + dis[3] + " " + dis[4] + " " + dis[5] + " " + dis[6] + " " + dis[7]
                                        , BR3SendCode.connReciveCode, 1);
            MainForm.barEditItem3.Value = 88;
            //57 07 98 08

            //PortCommunication.senderMsg(BR3SendCode.writeSendCode + " " + Common.Common.decToHex(BR3SendCode.dispalyAdress2, 8) + " " + Common.Common.decToHex(BR3SendCode.writeAdressLenth)
            //    + " " + dis[8] + " " + dis[9] + " ff ff ff ff ff "/*+Common.Common.decToHex(br3.RogerTone==true? 1:0 ) +" "*/+ Common.Common.decToHex((br3.StartupCh))
            //    , BR3SendCode.connReciveCode, 1);
            PortCommunication.senderMsg(BR3SendCode.writeSendCode + " " + Common.Common.decToHex(BR3SendCode.dispalyAdress2, 8) + " " + Common.Common.decToHex(BR3SendCode.writeAdressLenth)
                                        + " " + dis[8] + " " + dis[9] + " ff ff ff " + Common.Common.decToHex(br3.Brightness) + " " + Common.Common.decToHex(br3.RogerTone == true? 1:0) + " " + Common.Common.decToHex((br3.StartupCh))
                                        , BR3SendCode.connReciveCode, 1);
            MainForm.barEditItem3.Value = 90;
            //57 07 a0 08
            PortCommunication.senderMsg(BR3SendCode.writeSendCode + " " + Common.Common.decToHex(BR3SendCode.TxStartAdress, 8) + " " + Common.Common.decToHex(BR3SendCode.writeAdressLenth)
                                        + " " + TxCodeToHex(br3.TxStart)
                                        , BR3SendCode.connReciveCode, 1);
            MainForm.barEditItem3.Value = 92;
            //57 07 c0 08
            PortCommunication.senderMsg(BR3SendCode.writeSendCode + " " + Common.Common.decToHex(BR3SendCode.pragramAdress, 8) + " " + Common.Common.decToHex(BR3SendCode.writeAdressLenth)
                                        + " " + Common.Common.decToHex((br3.Ppt + br3.ScanMode * 4) * 16 + (br3.BeepSound?1:0) + (br3.PowerSaving?1:0) * 2 + br3.VoiceAnnouncements * 4)
                                        + " " + Common.Common.decToHex(br3.SquelchLevel) + " " + pressToHex(br3.ShotPress1) + " " + Common.Common.decToHex(br3.TxLimit) + " " + Common.Common.decToHex(br3.VoiceLevel) + " " + pressToHex(br3.ShotPress2) + " ff " + Common.Common.decToHex(br3.VoiceDelay)
                                        , BR3SendCode.connReciveCode, 1);
            MainForm.barEditItem3.Value = 94;
            //57 07 c8 08
            if (br3.Fto == 0)
            {
                //PortCommunication.senderMsg(BR3SendCode.writeSendCode + " " + Common.Common.decToHex(BR3SendCode.pragramAdress1, 8) + " " + Common.Common.decToHex(BR3SendCode.writeAdressLenth)
                //+ " " + pressToHex(br3.LongPress1) + " 0a " + Common.Common.decToHex(br3.DisplayMode) + " ff ff ff ff ff"
                //, BR3SendCode.connReciveCode, 1);
                PortCommunication.senderMsg(BR3SendCode.writeSendCode + " " + Common.Common.decToHex(BR3SendCode.pragramAdress1, 8) + " " + Common.Common.decToHex(BR3SendCode.writeAdressLenth)
                                            + " " + pressToHex(br3.LongPress1) + " " + pressToHex(br3.LongPress2) + " " + Common.Common.decToHex(br3.DisplayMode) + " ff ff ff ff ff"
                                            , BR3SendCode.connReciveCode, 1);
            }
            else if (br3.Fto == 1)
            {
                PortCommunication.senderMsg(BR3SendCode.writeSendCode + " " + Common.Common.decToHex(BR3SendCode.pragramAdress1, 8) + " " + Common.Common.decToHex(BR3SendCode.writeAdressLenth)
                                            + " " + pressToHex(br3.LongPress1) + " " + pressToHex(br3.LongPress2) + " " + Common.Common.decToHex(br3.DisplayMode) + " ff ff ff ff ff"
                                            , BR3SendCode.connReciveCode, 1);
            }
            MainForm.barEditItem3.Value = 96;
            //57 07 d8 08

            if (br3.Fto == 0)
            {
                PortCommunication.senderMsg(BR3SendCode.writeSendCode + " " + Common.Common.decToHex(BR3SendCode.Fto, 8) + " " + Common.Common.decToHex(BR3SendCode.writeAdressLenth)
                                            + " 60 44 80 44 ff ff ff ff"
                                            , BR3SendCode.connReciveCode, 1);
            }
            else if (br3.Fto == 1)
            {
                PortCommunication.senderMsg(BR3SendCode.writeSendCode + " " + Common.Common.decToHex(BR3SendCode.Fto, 8) + " " + Common.Common.decToHex(BR3SendCode.writeAdressLenth)
                                            + " 00 45 00 52 ff ff ff ff"
                                            , BR3SendCode.connReciveCode, 1);
            }
            MainForm.barEditItem3.Value = 98;


            //57 07 e0 08
            PortCommunication.senderMsg(BR3SendCode.writeSendCode + " " + Common.Common.decToHex(BR3SendCode.TxStopAdress, 8) + " " + Common.Common.decToHex(BR3SendCode.writeAdressLenth)
                                        + " " + TxCodeToHex(br3.TxStop)
                                        , BR3SendCode.connReciveCode, 1);
            MainForm.barEditItem3.Value = 100;
            PortCommunication.sendMassge("62");
            return(true);
        }
 public static void SetDataEventhandler(Action <byte[]> handler)
 {
     PortCommunication.SetCurrentDataEventHanlder(handler);
 }
Exemple #12
0
        /// <summary>
        /// 连接超时
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void timerSend_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            PortCommunication.timerSend.Enabled = false;
            // PortCommunication.timerSend.Interval = 0;

            //if (lg.IsHandleCreated)
            //{
            //    lg.Invoke(new Action(() =>
            //    {
            //        lg.Close();
            //    }));
            // }
            if (conn.IsAlive)
            {
                conn.Abort();
            }

            PortCommunication.closePort();
            barEditItem3.Value = 0;
            if (dataerrer == true)
            {
                if (!issessce)
                {
                    if (conCount <= 1)
                    {
                        conCount++;
                        Thread.Sleep(200);
                        if (s == ConState.read)
                        {
                            ReadClick();
                        }
                        else if (s == ConState.write)
                        {
                            WriteClick();
                        }
                    }
                    else
                    {
                        Common.Common.massage = "Connect Time Out";
                        foreach (Control item in this.Controls)
                        {
                            item.Enabled = true;
                        }
                        MessageBox.Show(Common.Common.massage);
                    }
                }
                else
                {
                    foreach (Control item in this.Controls)
                    {
                        item.Enabled = true;
                    }
                    MessageBox.Show(Common.Common.massage);
                }
            }
            else
            {
                foreach (Control item in this.Controls)
                {
                    item.Enabled = true;
                }
            }
        }
 /// <summary>
 /// Removes the received value.
 /// </summary>
 public void HandleFormUnload()
 {
     PortCommunication.ClosePort(serialPort);
 }
 /// <summary>
 /// Closes the form.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
 private void CloseForm(object sender, EventArgs e)
 {
     PortCommunication.ClosePort(serialPort);
 }