Пример #1
0
        private void connectToHostAndBeginPlayback(bool reconnect = false)
        {
            for (int retries = 0; retries < 5; retries++)
            {
                networkConnection = new NetworkConnection(tbServerHost.Text.Trim(), Convert.ToInt32(tbServerPort.Text.Trim()));
                networkConnection.connectDone.WaitOne();

                if (networkConnection.connectionStatus != NetworkConnection.ConnectionStatus.Connected)
                {
                    Thread.Sleep(1000);
                }
                else
                {
                    break;
                }
            }

            if (networkConnection.connectionStatus == NetworkConnection.ConnectionStatus.Connected)
            {
                Encryption enc = new Encryption();

                string password = enc.Encrypt(tbPassword.Text);
                networkConnection.Login(string.Format("STARTDAT 00048 PS17,VERSION=6.6,PASSWORD={0} ENDDAT",
                    string.IsNullOrEmpty(password) ? string.Empty : password));
                networkConnection.loginDone.WaitOne();

                if (networkConnection.loginStatus == NetworkConnection.LoginStatus.LoggedIn)
                {
                   _scannerScreen = new ScannerScreen();
                   _scannerLog = new ScannerLog();

                    _startTime = DateTime.Now;
                    _timerCounter = DateTime.Now;
                    _timer.Start();
                    _timerSys.Start();

                }
                else
                {
                    Console.WriteLine(networkConnection._loginStatusMessage);

                    networkConnection.LogOut("STARTDAT 00026 PS05 ENDDAT");
                    networkConnection.logoutDone.WaitOne();

                    networkConnection.Close();
                    networkConnection.closeDone.WaitOne();
                }
            }
            else
            {
                listBox1.Items.Add(string.Format("{0} (SCANNER) {1}", DateTime.Now, networkConnection._connectionStatusMessage));
                listBox1.TopIndex = listBox1.Items.Count - 1;
            }
        }
Пример #2
0
        private void StopScanner()
        {
            _timer.Stop();
            _timerSys.Stop();

            if (_scannerScreen != null)
                _scannerScreen.Dispose();

            if (_scannerLog != null)
                _scannerLog.Dispose();

            if (networkConnection != null && networkConnection.connectionStatus == NetworkConnection.ConnectionStatus.Connected)
            {
                networkConnection.LogOut("STARTDAT 00026 PS05 ENDDAT");
                networkConnection.logoutDone.WaitOne();

                networkConnection.Close();
                networkConnection.closeDone.WaitOne();

                networkConnection = null;
            }

            btConnect.Text = "Connect";
        }
Пример #3
0
 private void btConnect_Click(object sender, EventArgs e)
 {
     if (networkConnection == null)
     {
         listBox1.Items.Add(string.Format("{0} (SCANNER) Connecting to ProScan server...", DateTime.Now));
         listBox1.TopIndex = listBox1.Items.Count - 1;
         Application.DoEvents();
         connectToHostAndBeginPlayback();
         if (networkConnection.connectionStatus == NetworkConnection.ConnectionStatus.Error)
         {
             listBox1.Items.Add(string.Format("{0} (SCANNER) Cannot connect to ProScan server", DateTime.Now));
             listBox1.TopIndex = listBox1.Items.Count - 1;
             networkConnection = null;
         }
         else
         {
             listBox1.Items.Add(string.Format("{0} (SCANNER) Starting scanner playback", DateTime.Now));
             listBox1.TopIndex = listBox1.Items.Count - 1;
             btConnect.Text = "Close";
         }
     }
     else
     {
         listBox1.Items.Add(string.Format("{0} (SCANNER) Stopping scanner playback", DateTime.Now));
         listBox1.TopIndex = listBox1.Items.Count - 1;
         StopScanner();
         saveListSystems();
         saveSettings();
     }
 }