public void WriteHexData(string strHex)
        {
            byte[] buf = ShujuChuli.HexStringToBytes(strParam.ToUpper());
            try
            {
                if (comm.IsOpen)
                {
                    comm.Write(buf, 0, buf.Length);

                    Console.WriteLine(strParam);
                    Log.Debug("CmdHex-->" + strParam);//问题调查时可用
                }
                else
                {
                    ConnectPort();
                    try
                    {
                        if (comm.IsOpen)
                        {
                            //  recEvent.WaitOne();
                            comm.Write(buf, 0, buf.Length);
                        }
                    }
                    catch (Exception)
                    {
                        comm = new SerialPort();
                        //   MessageBox.Show(ex.Message);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// 当前位置获取
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button13_Click(object sender, EventArgs e)
        {
            Button button = (Button)sender;

            EquipmentCmd.Instance.SendCommand(button.Text, "", out res);
            string resHexs = ByteToHexString(EquipmentCmd.Instance.resPort);

            if (resHexs.IndexOf("34 0A 16 06 05 ") != -1)
            {
                dangQianWeiZhi_X = ShujuChuli.DiGaoBaWei(ShujuChuli.HexStringToBytes((ShujuChuli.GetIndexString(resHexs, 5)))[0], ShujuChuli.HexStringToBytes((ShujuChuli.GetIndexString(resHexs, 6)))[0]);
                dangQianWeiZhi_Y = ShujuChuli.DiGaoBaWei(ShujuChuli.HexStringToBytes((ShujuChuli.GetIndexString(resHexs, 7)))[0], ShujuChuli.HexStringToBytes((ShujuChuli.GetIndexString(resHexs, 8)))[0]);
            }


            txtXianShi.AppendText(DateTime.Now.ToString("hh时mm分ss秒") + "  " + button.Text + "-->" + res + "    " + resHexs + "\r\n");
        }
        public bool ConnectPort()
        {
            //握手状态指示
            bool connectOK = false;

            #region 握手

            while (ws)
            {
                if (comm.IsOpen)
                {
                    comm.Close();
                    comm.Dispose();
                }
                else
                {
                    int a = 0;
                    for (int i = 0; i < 5; i++)
                    {
                        string[] ports = SerialPort.GetPortNames();
                        foreach (string port in ports)
                        {
                            comm.PortName = port;
                            comm          = new SerialPort(port);

                            comm.BaudRate = 19200;
                            comm.Parity   = Parity.None;
                            comm.StopBits = StopBits.One;
                            comm.DataBits = 8;


                            // comm.DataReceived += new SerialDataReceivedEventHandler(comm_DataReceived);//串口数据回调函数

                            //comm.DataReceived +=comm_DataReceived;
                            try
                            {
                                comm.Open();

                                //开启一个线程读取串口数据
                                //把读取线程设置为后台线程

                                _readThread.Start();


                                byte[] sbuf = ShujuChuli.HexStringToBytes(str_woshou);
                                comm.Write(sbuf, 0, sbuf.Length);

                                ChaZhaoChuanKouCiShu = woShouEvent.WaitOne(2000);//等待返回函数将mEvent置为mEvent.Set();
                                if (ChaZhaoChuanKouCiShu == true)
                                {
                                    //将串口名称加载在指定的控件上
                                    // strPort = port;
                                    connectOK = true;
                                    ws        = false;
                                    break;
                                }
                                else
                                {
                                    _readThread.Abort();
                                    comm.Close();
                                    comm.Dispose();
                                }
                            }
                            catch (Exception)
                            {
                                _readThread.Abort();
                                comm.Close();
                                comm.Dispose();
                                //现实异常信息给客户。
                                //  MessageBox.Show(ex.Message);
                            }
                        }
                        a += 1;
                        if (ChaZhaoChuanKouCiShu == true)
                        {
                            //  MessageBox.Show("无法找到串口!请确认硬件问题.");
                            ws = false;
                            break;
                        }
                        if (a == 5)
                        {
                            ws = false;
                            comm.Close();
                            connectOK = false;
                            break;
                        }
                    }
                }
            }
            #endregion
            return(connectOK);
        }