/// <summary> /// Initializes a new instance of the <see cref="FrmMain"/> class. /// </summary> public FrmMain() { this.InitializeComponent(); Logger.Info("App started."); this.WriteSessionCount = 0; // Init scanner. var comPortName = Properties.Settings.Default.ScannerPort; this.scanner = MatrixCodeScanner.Init(comPortName); this.lblScannerPortName.Text = string.Format("Scanner Port: {0}", comPortName); // register scanner event handler only once this.scanner.ScannerDataReceived += OnScannerDataReceived; // start scanner receive loop this.scanner.Run(); // run whenever this form is shown. this.VisibleChanged += (sender, args) => { if (this.Visible) { this.Init(); } }; }
public static MatrixCodeScanner Init(string portName) { if (instance != null) { if (instance.Sp != null) { try { if (instance.Sp.IsOpen) { instance.Sp.Close(); } } catch (Exception ex) { } } } instance = new MatrixCodeScanner(portName); return instance; }