Пример #1
0
        private void SerialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            var rx = new List <byte>();

            try
            {
                while (serialPort1.BytesToRead > 0)
                {
                    rx.Add((byte)serialPort1.ReadByte());
                }
            }
            catch (Exception ex)
            {
                _logger.AddText("Error reading port " + serialPort1.PortName + ": " + ex.Message, (byte)DataDirection.Error, DateTime.Now, TextLogger.TextLogger.TextFormat.PlainText);
            }
            var outStr1 = Encoding.GetEncoding(ComPrnControl.Properties.Settings.Default.CodePage).GetString(rx.ToArray(), 0, rx.Count);

            _logger.AddText(outStr1, (byte)DataDirection.Received, DateTime.Now);
        }
Пример #2
0
        private void Button_OPEN_Click(object sender, EventArgs e)
        {
            for (var i = 0; i < CONNECTED_PRINTER_LIST.Count; i++)
            {
                if (CONNECTED_PRINTER_LIST[i].USB_SYMBOLIC_NAME.Equals(comboBox_Printer.Text))
                {
                    Selected_Printer = CONNECTED_PRINTER_LIST[i];
                    Selected_Printer.READ_TIMEOUT  = 50;
                    Selected_Printer.WRITE_TIMEOUT = 1000;
                    if (Selected_Printer.OpenDevice())
                    {
                        timer1.Enabled           = true;
                        button_Refresh.Enabled   = false;
                        button_Open.Enabled      = false;
                        comboBox_Printer.Enabled = false;
                        button_closeport.Enabled = true;
                        button_Send.Enabled      = true;
                        checkBox_printer.Enabled = false;
                        checkBox_scanner.Enabled = false;
                        //button_sendFile.Enabled = true;
                        TextBox_fileName_TextChanged(this, EventArgs.Empty);
                    }
                    else
                    {
                        _logger.AddText("Port open failure", (byte)DataDirection.Error, DateTime.Now, TextLogger.TextLogger.TextFormat.PlainText);
                    }

                    return;
                }
            }
        }
Пример #3
0
 private void Button_OPEN_Click(object sender, EventArgs e)
 {
     if (!_clientSocket.Connected)
     {
         try
         {
             _clientSocket = new TcpClient();
             _clientSocket.Connect(textBox_ipAddress.Text, int.Parse(textBox_port.Text));
             _clientSocket.ReceiveTimeout        = 500;
             _clientSocket.SendTimeout           = 500;
             _clientSocket.Client.ReceiveTimeout = 500;
             _clientSocket.Client.SendTimeout    = 500;
             serverStream = _clientSocket.GetStream();
             _logger.AddText("Port opened: " + textBox_ipAddress.Text + ":" + textBox_port.Text,
                             (byte)DataDirection.Info, DateTime.Now, TextLogger.TextLogger.TextFormat.PlainText);
             button_Open.Enabled       = false;
             textBox_ipAddress.Enabled = false;
             textBox_port.Enabled      = false;
             button_closeport.Enabled  = true;
             button_Send.Enabled       = true;
             button_sendFile.Enabled   = true;
             timer1.Enabled            = true;
             TextBox_fileName_TextChanged(this, EventArgs.Empty);
         }
         catch (Exception ex)
         {
             _logger.AddText("Port open failure: " + ex.Message, (byte)DataDirection.Error, DateTime.Now,
                             TextLogger.TextLogger.TextFormat.PlainText);
         }
     }
     else
     {
         _logger.AddText("Port already connected", (byte)DataDirection.Info, DateTime.Now,
                         TextLogger.TextLogger.TextFormat.PlainText);
     }
 }