コード例 #1
0
 public void Disconnect()
 {
     if (SerialPortAdapterRef != null)
     {
         _serialPortAdapter.Disconnect(SerialPortAdapterRef);
         SerialPortAdapterRef = null;
         Printer = null;
     }
 }
コード例 #2
0
 public void Connect(PrinterConfigurationModel printer)
 {
     if (SerialPortAdapterRef == null)
     {
         SerialPortAdapterRef = _serialPortAdapter.Connect(
             printer,
             new Action <SerialPortAdapterRef, string>(DataReceivedCallback));
         Printer = printer;
     }
 }
コード例 #3
0
 public ISerialPort GetSerialPort(SerialPortAdapterRef portRef)
 {
     if (_portsByRef.TryGetValue(portRef, out var serialPort))
     {
         return(serialPort);
     }
     else
     {
         return(null);
     }
 }
コード例 #4
0
        public bool Disconnect(SerialPortAdapterRef portRef)
        {
            if (_portsByRef.ContainsKey(portRef))
            {
                var serialPort = _portsByRef[portRef];
                serialPort.Close();
                _portsByRef.TryRemove(portRef, out _);
                _refsByPort.TryRemove(serialPort, out _);

                serialPort.Dispose();
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #5
0
        public SerialPortAdapterRef Connect(
            PrinterConfigurationModel config,
            Action <SerialPortAdapterRef, string> dataReceivedCallback)
        {
            var portRef = new SerialPortAdapterRef(
                config,
                dataReceivedCallback);

            var serialPort = (SerialPortType)Activator.CreateInstance(typeof(SerialPortType),
                                                                      config.Port,
                                                                      config.BaudRate);

            serialPort.DataReceived += SerialPort_DataReceived;
            serialPort.Open();

            _portsByRef.TryAdd(portRef, serialPort);
            _refsByPort.TryAdd(serialPort, portRef);
            return(portRef);
        }
コード例 #6
0
 public bool Write(
     SerialPortAdapterRef portRef,
     byte[] data,
     int offset,
     int count)
 {
     if (_portsByRef.ContainsKey(portRef))
     {
         var serialPort = _portsByRef[portRef];
         serialPort.Write(
             data,
             offset,
             count);
         return(true);
     }
     else
     {
         return(false);
     }
 }
コード例 #7
0
 private void DataReceivedCallback(
     SerialPortAdapterRef portRef,
     string data)
 {
     _printerPacketParser.ReceiveData(data);
 }