Exemple #1
0
        /// <summary>
        /// 11.下位机
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsmiOpenPLC_Click(object sender, EventArgs e)
        {
            TaskForm taskForm = new FrmPLC();

            if (HaveOpened(taskForm, this))
            {
                taskForm.MdiParent = this;
                taskForm.Show();
            }
        }
Exemple #2
0
        public MainViewModel()
        {
            ConnectCommand              = new RelayCommand <bool>(Connect, CanConnectExcute);
            SwitchOutputCommand         = new RelayCommand <string>(SwitchOutput);
            StopMonitorCommand          = new RelayCommand <bool>(StopMonitor, CanStopMonitorExcute);
            ShowViewCommand             = new RelayCommand <string>(ShowSettingWindowCommandExecute);
            SwitchLangugeCommand        = new RelayCommand <string>(SwitchLanguage);
            WriteDataCommand            = new RelayCommand <object>(WriteData);
            ChangeConnectionTypeCommand = new RelayCommand <string>(ChangeConnectionType);

            OpenSerialPortCommand    = new RelayCommand <bool>(OpenSerialPort, CanConnectSerialExcute);
            CloseSerialPortCommand   = new RelayCommand(CloserSerialPort, CanCloserSerialPortExcute);
            ChangeSerialPortCommand  = new RelayCommand <string>(ChangeSerialPort);
            ClearReceviedDataCommand = new RelayCommand(ClearReceviedData);

            ChangePrinterCommand    = new RelayCommand <string>(ChangePrinter);
            OpenPrintSetupCommand   = new RelayCommand(ShowPrintSetup);
            OpenPrintPreviewCommand = new RelayCommand(ShowPrintPreview);
            PrintCommand            = new RelayCommand(Print);

            ShowSettingWindowCommand = new RelayCommand <string>(ShowSettingWindowCommandExecute);
            ShowIOWindowCommand      = new RelayCommand(ShowIOWindowCommandExecute);

            _frmPLC      = new FrmPLC();
            _layupPLC    = new Fx3GA();
            _serialPorts = SerialPort.GetPortNames();
            _printers    = PrinterSettings.InstalledPrinters;
            ReturnCode   = new ObservableCollection <string>();
            //初始化定时器,定时读取PLC状态
            DispatcherTimer1          = new DispatcherTimer();
            DispatcherTimer1.Interval = new System.TimeSpan(500);
            // DispatcherTimer1.Tick += GetOutputStatus;
            // DispatcherTimer1.Tick += GetInputStatus;
            //DispatcherTimer1.Tick += GetDataStatus;

            //  DispatcherTimer1.Tick +={ () => { _serialPorts = SerialPort.GetPortNames(); } };
            // DispatcherTimer1.Tick += GetMStatus;

            //初始化打印
            DefaultPrinterName  = printDocument1.PrinterSettings.PrinterName;
            SelectedPrinterName = DefaultPrinterName;
            //指定打印机
            printDocument1.PrinterSettings.PrinterName = SelectedPrinterName;
            //设置页边距
            printDocument1.PrinterSettings.DefaultPageSettings.Margins.Left   = 0;
            printDocument1.PrinterSettings.DefaultPageSettings.Margins.Top    = 0;
            printDocument1.PrinterSettings.DefaultPageSettings.Margins.Right  = 0;
            printDocument1.PrinterSettings.DefaultPageSettings.Margins.Bottom = 0;
            //设置尺寸大小,如不设置默认是A4纸
            //A4纸的尺寸是210mm×297mm,
            //当你设定的分辨率是72像素/英寸时,A4纸的尺寸的图像的像素是595×842
            //当你设定的分辨率是150像素/英寸时,A4纸的尺寸的图像的像素是1240×1754
            //当你设定的分辨率是300像素/英寸时,A4纸的尺寸的图像的像素是2479×3508,
            // printDocument1.DefaultPageSettings.PaperSize = new PaperSize("A4", 2479, 3508);
            printDialog1.AllowSelection = true;
            printDocument1.DefaultPageSettings.PaperSize = printDialog1.PrinterSettings.DefaultPageSettings.PaperSize;
            //printDocument1.BeginPrint += new System.Drawing.Printing.PrintEventHandler(this.OnBeginPrint);
            printDocument1.BeginPrint += OnBeginPrint;
            printDocument1.EndPrint   += PrintDocument1_EndPrint;

            this.printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.OnPrintPage);


            pageSetupDialog1.Document = this.printDocument1;
            this.printPreviewDialog1.AutoScrollMargin  = new System.Drawing.Size(0, 0);
            this.printPreviewDialog1.AutoScrollMinSize = new System.Drawing.Size(0, 0);
            this.printPreviewDialog1.ClientSize        = new System.Drawing.Size(400, 300);
            this.printPreviewDialog1.Document          = this.printDocument1;
            this.printPreviewDialog1.Enabled           = true;
            this.printPreviewDialog1.Name    = "printPreviewDialog1";
            this.printPreviewDialog1.Visible = false;


            //将配置文件反序列化为对象,如果反序列化失败就使用默认值初始化SettingModel
            try
            {
                SettingModel = JsonConvert.DeserializeObject <SettingModel>(File.ReadAllText(Environment.CurrentDirectory + "\\config" + ".json"));
            }
            catch (Exception e)
            {
                //System.Windows.MessageBox.Show(e.Message);
                SettingModel = new SettingModel {
                    Subdivision = 1600, Pitch = 5
                };
            }

            //初始化串口设置


            //初始化序列化
            JsonSerializer serializer = new JsonSerializer();

            //注册消息接收设置窗口传来的对象,接收到后进行序列化操作保存成配置文件
            Messenger.Default.Register <SettingModel>(this, msg =>
            {
                SettingModel.Pitch       = msg.Pitch;
                SettingModel.Subdivision = msg.Subdivision;
                //Debug.Print(SettingModel.Pitch.ToString());
                Debug.Print(SettingModel.Subdivision.ToString());
                string Json = JsonConvert.SerializeObject(SettingModel, Formatting.Indented);
                File.WriteAllText(Environment.CurrentDirectory + "\\config" + ".json", Json);
            });
        }