コード例 #1
0
        protected override void OnSourceInitialized(EventArgs e)
        {
            base.OnSourceInitialized(e);

            // Install window hook for USB device add/removal notification.
            SerialportWatcher.InstallWindowHook(this);
            SerialportWatcher.RegisterUsbDeviceNotification();

            // restore windows position and size
            if (Properties.Settings.Default.WinWidth > 0)
            {
                this.Width = Properties.Settings.Default.WinWidth;
            }
            if (Properties.Settings.Default.WinHeight > 0)
            {
                this.Height = Properties.Settings.Default.WinHeight;
            }
            if (Properties.Settings.Default.WinTop >= 0)
            {
                this.Top = Properties.Settings.Default.WinTop;
            }
            if (Properties.Settings.Default.WinLeft >= 0)
            {
                this.Left = Properties.Settings.Default.WinLeft;
            }
        }
コード例 #2
0
        private static IntPtr WndProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            if (msg == WmDevicechange)
            {
                var dbt = wParam.ToInt32();
                if (dbt == DBT_DEVICEREMOVECOMPLETE || dbt == DBT_DEVICEARRIVAL)
                {
                    int devType = Marshal.ReadInt32(lParam, 4);
                    if (devType == DBT_DEVTYP_PORT)
                    {
                        var name = Marshal.PtrToStringAuto((IntPtr)((long)lParam + 12));
                        if (dbt == DBT_DEVICEARRIVAL)
                        {
                            Task.Factory.StartNew(
                                new Action <object>((state) =>
                            {
                                SerialportWatcher.UsbPortChanged((string)state, true);
                            }), name);
                        }
                        else
                        {
                            SerialportWatcher.UsbPortChanged(name, false);
                        }
                    }
                }
                handled = true;
            }
            else
            {
                handled = false;
            }

            return(IntPtr.Zero);
        }
コード例 #3
0
        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            SerialportWatcher.UnregisterUsbDeviceNotification();

            DeleteLogFiles(); // Delete Log files

            // save windows position and size
            if (this.WindowState == WindowState.Normal)
            {
                Properties.Settings.Default.WinWidth  = this.Width;
                Properties.Settings.Default.WinHeight = this.Height;
                Properties.Settings.Default.WinTop    = this.Top;
                Properties.Settings.Default.WinLeft   = this.Left;
            }

            Properties.Settings.Default.Save();
        }
コード例 #4
0
        public MainModel()
        {
            ModelName = "MainModel";

            SerialportWatcher.UsbPortChanged(null);

            EModel = new EmergencyModel(this);
            MModel = new MultiModel(this);
            DModel = new DumpModel(this);
            NModel = new NormalModel(this); // jwoh add Micom Download only

            this._currentTabIndex = Properties.Settings.Default.TabIndex;
            this.AllErase         = Properties.Settings.Default.AllErase;
            this.LogLevel         = Properties.Settings.Default.LogLevel;
            this.SelBoard         = Properties.Settings.Default.SelBoard;    // jwoh add User/Factory mode
            this.SelFirehose      = Properties.Settings.Default.SelFirehose; // jwoh add GM Signing
            this.SelBaudrate      = Properties.Settings.Default.SelBaudrate; // jwoh add baudrate
            this.SelModel         = Properties.Settings.Default.SelModel;    // jwoh add model
            this.MCP2K            = (Properties.Settings.Default.MCP2K_4K == "2K") ? true : false;
            this.MCP4K            = (Properties.Settings.Default.MCP2K_4K == "4K") ? true : false;
            ModelActivateChange(-1, this.CurrentTabIndex);
        }
コード例 #5
0
        private void SerialportWatcher_SerialPortsChangedEvent(bool aInserted, SerialportWatcher.PortInfo aChangedPort)
        {
            this.UIThread(() =>
            {
                var qport = SerialportWatcher.GetPorts(SerialportWatcher.PortKind.QDLoader);
                if (qport.Count > 0)
                {
                    this.CurrentPort = qport[0];
                    Log.i("QDLoader port is presented ({0})", this.CurrentPort.Name);
                }
                else
                {
                    var dport = SerialportWatcher.GetPorts(SerialportWatcher.PortKind.Serial);
                    if (dport.Count > 0)
                    {
                        if (this.CurrentPort.Kind != SerialportWatcher.PortKind.Serial)
                        {
                            this.CurrentPort = dport[0];
                        }
                        else if (aInserted == false && this.CurrentPort.Equals(aChangedPort)) // 제거 시 갱신
                        {
                            this.CurrentPort = dport[0];
                        }

                        Log.i("Debug port is presented ({0})", this.CurrentPort.Name);
                    }
                    else
                    {
                        if (this.CurrentPort.Kind != SerialportWatcher.PortKind.None)
                        {
                            this.CurrentPort = new SerialportWatcher.PortInfo();
                        }
                        Log.i("Port is none");
                    }
                }
                InvokePropertyChanged("PortListVisible");
            });
        }