Ejemplo n.º 1
0
 private void ClosePort()
 {
     if (_access != null)
     {
         _access.Close();
         _access = null;
     }
     SerialPortOperate.ClosePort();
 }
        private void StatusMonitorControlForm_Load(object sender, EventArgs e)
        {
            _serialPort = new SerialPortOperate(Para.SerialPortPara.PortName, Para.SerialPortPara.BaudRate, Para.SerialPortPara.DataBits, Para.SerialPortPara.StopBits, "NONE");
            try
            {
                _serialPort.OpenPort();
            }
            catch (Exception exception)
            {
                CommonLogHelper.GetInstance("LogError").Error($"打开串口{Para.SerialPortPara.PortName}出错", exception);
                MessageBox.Show($"打开串口{Para.SerialPortPara.PortName}出错");
            }

            try
            {
                _powerAlarmPara.GetXmlNodeInfo();
            }
            catch (Exception ex)
            {
                CommonLogHelper.GetInstance("LogError").Error(@"读取电源报警参数出错", ex);
            }

            try
            {
                Text  = StationId + @":雷达状态监控和控制";
                _conn =
                    $"Data Source={Para.SqlServerPara.SqlIp};Initial Catalog={Para.SqlServerPara.SqlDb};User ID={Para.SqlServerPara.SqlUser};Password={Para.SqlServerPara.SqlPwd};";

                powerIndicationUI.StationId     = StationId;
                powerIndicationUI.SqlConnection = _conn;

                if (Para.StationGrade.Contains("台站"))
                {
                    启用控制ToolStripMenuItem.Visible       = true;
                    _serialPort.ReturnCollectorRecData += RecDataProcessing;
                    radarControlUI.SendCmd             += SendControlCmd;
                }
                DateTime dt = DateTime.Now;
                int      s  = dt.Second;
                dt = dt.AddSeconds(-s);
                if (Para.StationGrade.Contains("台站"))
                {
                    dt = s < 30 ? dt.AddSeconds(30) : dt.AddSeconds(30).AddMinutes(Para.UpdateDataIntl);
                }
                else
                {
                    dt = dt.Second < 30 ? dt.AddSeconds(45) : dt.AddSeconds(45).AddMinutes(Para.UpdateDataIntl);
                }
                toolSslNextUpdateTime.Text = $"下次采集时间:{dt.ToString("yyyy-MM-dd HH:mm:ss")}";
                _tmr.Start();
            }
            catch (Exception ex)
            {
                CommonLogHelper.GetInstance("LogError").Error(@"加载窗体过程出错", ex);
            }
        }
Ejemplo n.º 3
0
        private void SendToSelector(int floor)
        {
            byte bx         = 0x00;
            var  b41        = (byte)(bx | floor);
            var  handBuffer = Funs.InitArray(8, 0x00);
            var  total      = Package.CardDataSendToLiftPackage(0, handBuffer, b41);

            this.Dispatcher.BeginInvoke(new Action(() =>
            {
                BarcodeFloor  = "楼层:" + floor;
                var animation = OpacityAnimation();
                tbBarcode.BeginAnimation(Label.OpacityProperty, animation);
            }));
            var bsend = SerialPortOperate.SendData(total);

            if (bsend)
            {
                //Log("自动权限层:{0} {1}", b41.ToHex(), floor);
                //Log("长度:{0}", total.Length);
                Log("发送数据:{0}", total.ToHex());
            }
        }
        private void 实时采集ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DateTime dt   = DateTime.Now;
            DateTime obdt = dt.AddSeconds(-dt.Second).AddMilliseconds(-dt.Millisecond);

            #region 台站级别发送指令

            if (Para.StationGrade.Contains("台站"))
            {
                Thread collectThread = new Thread((ThreadStart) delegate
                {
                    try
                    {
                        SerialPortOperate tempSerialPortOperate = _serialPort;
                        //_tempSerialPortOperate.ReturnCollectorRecData += ManualRecDataProcessing;
                        byte[] cmd = SerialPortCmdCombine.SetBaseCommand("FF", "03");
                        CommonLogHelper.GetInstance("LogInfo")
                        .Info($@"实时采集:发送采集命令:{string.Join(" ", cmd.Select(x => x.ToString("X2")).ToArray())}");
                        tempSerialPortOperate.SendCommand(cmd);
                    }
                    catch (Exception ex)
                    {
                        CommonLogHelper.GetInstance("LogInfo").Info(@"实时采集:发送串口命令获取数据过程出错");
                        CommonLogHelper.GetInstance("LogError").Error(@"实时采集:发送串口命令获取数据过程出错", ex);
                        _synchContext.Post(a =>
                                           MessageBox.Show(this, @"实时采集:发送串口命令获取数据过程出错," + ex.Message, @"错误", MessageBoxButtons.OK, MessageBoxIcon.Error)
                                           , null);
                    }
                })
                {
                    IsBackground = true
                };
                collectThread.Start();
            }

            #endregion 台站级别发送指令

            #region 省级级别操作数据库

            try
            {
                if (Para.StationGrade.Contains("省级"))
                {
                    Thread collectProThread = new Thread((ThreadStart) delegate
                    {
                        tSSLSystemStatus.Text = @"获取最新数据";
                        RadarDataClassesDataContext radarDataContext = new RadarDataClassesDataContext(_conn);
                        DataAdapter dataadp = new DataAdapter(StationId, obdt);
                        dataadp.DataResolve(radarDataContext);
                        _synchContext.Post(a =>
                        {
                            try
                            {
                                if (dataadp.AlarmStatusData != null)
                                {
                                    radarStatusUI.SetAlarmStatus(dataadp.AlarmStatusData);
                                }
                                if (dataadp.ControlStatusData != null)
                                {
                                    radarControlUI.SetControlStatus(dataadp.ControlStatusData);
                                }
                                if (dataadp.RadarPowerData != null)
                                {
                                    powerIndicationUI.SetPowerDataValue(dataadp.RadarPowerData);
                                }
                                if (dataadp.AlarmStatusData != null || dataadp.ControlStatusData != null ||
                                    dataadp.RadarPowerData != null)
                                {
                                    tSSLDataUpdateTime.Text = $"数据更新时间:{obdt.ToString("yyyy-MM-dd HH:mm")}";
                                }
                                else
                                {
                                    MessageBox.Show(@"无当前实时数据");
                                }
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(@"数据显示到界面上出错" + ex);
                            }
                        }, null);
                        CommonLogHelper.GetInstance("LogInfo").Info(@"获取数据库数据成功");

                        try
                        {
                            RadarFailureAlarm(dataadp.AlarmStatusData);
                        }
                        catch (Exception ex)
                        {
                            CommonLogHelper.GetInstance("LogError").Error(@"雷达故障报警过程出错", ex);
                        }
                    })
                    {
                        IsBackground = true
                    };
                    collectProThread.Start();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, @"提取数据库数据处理过程出错" + ex, @"错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            #endregion 省级级别操作数据库
        }