Ejemplo n.º 1
0
        /// <summary>
        /// 启用连接外部设备
        /// </summary>
        /// <param name="_cfg"></param>
        private void SubDeviceInitial()
        {
            try
            {
                AE2DeviceFactory fac = new AE2DeviceFactory();
                //IO模块
                adam = fac.CreateAdamDevice(appConfig.Adam.PortNumber);
                adam.NetChangedAction = (d, n) =>
                {
                    ShowToAllForms(m => m.ADAMNet = n);
                };
                adam.OnSensorTrigger += Adam_OnSensorTrigger;

                //RFID
                rfid = fac.CreateRFIDDevice(appConfig.Rfid);
                //相当于连接变化时的事件
                rfid.NetChangedAction = (d, n) =>
                {
                    ShowToAllForms(m =>
                    {
                        m.RFIDNet = n;
                        m.PrintlnInfo("RFID已连接。");
                    });
                };
                rfid.OnTagDataReaded = TagReaded;//相当于RFID读到标签后的事件

                //串口条码枪
                scan              = fac.CreateScanDevice(appConfig.Scanner);
                scan.OnScanCoded += Scan_OnScanCoded;

                //OPC
                opc = fac.CreateOpcDevice(appConfig.Opc);
                opc.LineStopChangedAction = (s) =>
                {
                    ShowToAllForms(v => v.StopLine = s);
                };
                opc.NetChangedAction = (d, s) =>
                {
                    ShowToAllForms(m =>
                    {
                        m.PLCNet = s;
                    });
                };
                opc.ShieldChangedAction = s =>
                {
                    ShowToAllForms(m =>
                    {
                        m.ShieldStatus = !s;
                        m.PrintlnInfo(s ? "PLC屏蔽PC信号" : "PLC启动接收PC信号");
                    });
                };

                mwCard = fac.CreateCardDevice(appConfig.MwCard);
                Log.Information("设备初始化完成");
            }
            catch (Exception ex)
            {
                Log.Error("外设模块初始化出错," + ex.Message, ex);
            }
        }
Ejemplo n.º 2
0
        public MainForm(ScreenConfig config, MainViewModels viewModel, IAdamController iAdam, IOpcController iopc, ICardController iCard)
        {
            try
            {
                _screenConfig = config;
                ViewModel     = viewModel ?? new MainViewModels();
                adam          = iAdam;
                opc           = iopc;
                mwCard        = iCard;
                InitializeComponent();
                Load += FormForm_Load;
                adam.OnSensorTrigger += Adam_OnSensorTrigger;//开关\按钮信息
                mwCard.SwipedEvent   += MwCard_SwipedEvent;
                if (_screenConfig != null)
                {
                    lblAppName.Text = _screenConfig.Title;
                    if (_screenConfig.Part.Available)
                    {
                        panelPart.Visible = true;
                    }
                    if (config.Id != 0)
                    {
                        btClose.Visible = false;
                    }
                    theTitle = config.Title;
                }

                {
                    var dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
                    dataGridViewCellStyle1.Alignment          = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
                    dataGridViewCellStyle1.BackColor          = System.Drawing.SystemColors.Window;
                    dataGridViewCellStyle1.Font               = new System.Drawing.Font("宋体", 36F);
                    dataGridViewCellStyle1.ForeColor          = System.Drawing.SystemColors.ControlText;
                    dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
                    dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
                    dataGridViewCellStyle1.WrapMode           = System.Windows.Forms.DataGridViewTriState.False;
                    this.dataViewTd.DefaultCellStyle          = dataGridViewCellStyle1;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Form:" + ex.Message);
            }
        }