Exemple #1
0
 /// <summary>
 /// Initializes a new connection to the interface
 /// </summary>
 /// <remarks>Uses the credentials Port, StopBites, aso.</remarks>
 private void InitConnection(string port = "COM2", int baudRate = 57600, ComPortParity parityBits = ComPortParity.None, int dataBits = 8, ComPortStopBits stopBits = ComPortStopBits.One)
 {
     SerialPortConnection = new ComPortConnection(port, baudRate, parityBits, dataBits, stopBits);
     try
     {
         SerialPortConnection.Open();
     }
     catch (System.UnauthorizedAccessException notavail)
     {
         // COM Port in use
         logme.Log(i18n.FlakeLIErrors.ComPortNotAvailable, logme.LogLevel.error);
         notavail.ToString(); // foo
         return;
     }
     catch (IOException ioex)
     {
         logme.Log(ioex);
         return;
     }
     catch (Exception ex)
     {
         logme.Log(ex);
         return;
     }
 }
Exemple #2
0
        private void btnTestCom_Click(object sender, EventArgs e)
        {
            bool check = false;

            if (com == null)
            {
                com = new ComPort(1);
                //   com.OnComReaderReceived += new ComReaderReceived(this._port_DataReceived);
                check = com.Init();
            }
            if (check)
            {
                check = com.Connect();
                if (check)
                {
                    MessageBox.Show("OK");
                }
                else
                {
                    MessageBox.Show("Fail");
                }
            }
            else
            {
                MessageBox.Show("Fail");
            }
        }
Exemple #3
0
 /// <summary>
 /// Initializes a new connection to the interface
 /// </summary>
 /// <remarks>Uses the credentials Port, StopBites, aso.</remarks>
 private void InitConnection(string port = "COM2", int baudRate = 57600, ComPortParity parityBits = ComPortParity.None, int dataBits = 8, ComPortStopBits stopBits = ComPortStopBits.One)
 {
     SerialPortConnection = new ComPortConnection(port, baudRate, parityBits, dataBits, stopBits);
     try
     {
         SerialPortConnection.Open();
     }
     catch (System.UnauthorizedAccessException notavail)
     {
         // COM Port in use
         logme.Log(i18n.FlakeLIErrors.ComPortNotAvailable, logme.LogLevel.error);
         notavail.ToString(); // foo
         return;
     }
     catch (IOException ioex)
     {
         logme.Log(ioex);
         return;
     }
     catch (Exception ex)
     {
         logme.Log(ex);
         return;
     }
 }
Exemple #4
0
 public int GetHashCode(IComPort obj)
 {
     unchecked
     {
         return(obj.PortName.GetHashCode() * 12377 ^ (obj.Name.GetHashCode() * 397));
     }
 }
Exemple #5
0
 public Shell(IConsole console,
              IComPort port,
              IEnumerable <ICommand> commands)
 {
     _commands = commands;
     _console  = console;
     _port     = port;
 }
Exemple #6
0
        public PlcKeyenceUpperLink(IComPort comPort, int readTimeoutSeconds = 3)
        {
            this.comPort            = comPort;
            this.readTimeoutSeconds = readTimeoutSeconds;
            this.connectionStateChangedEventManager = new ConnectionStateChangedEventManager(string.Empty);

            this.comPort.ConnectionStateChanged += (s, e) =>
            {
                connectionStateChangedEventManager.OnConnectionStateChanged(ConnectionStateChanged, this, e);
            };
        }
        public PlcOmronFins(IComPort comPort, int readTimeoutSeconds = 3)
        {
            this.comPort            = comPort;
            this.readTimeoutSeconds = readTimeoutSeconds;
            this.pcNode             = 0x00;
            this.plcNode            = 0x00;
            this.connectionStateChangedEventManager = new ConnectionStateChangedEventManager(string.Empty);

            this.comPort.ConnectionStateChanged += (s, e) =>
            {
                connectionStateChangedEventManager.OnConnectionStateChanged(ConnectionStateChanged, this, e);
            };
        }
        public CommandBarcodeReader(string name, IComPort comPort, CommandBarcodeReaderConfigInfo commandBarcodeReaderConfigInfo, string regex = null, ILoggerFactory loggerFactory = null)
            : base(name)
        {
            this.comPort = comPort;
            this.CommandBarcodeReaderConfigInfo = commandBarcodeReaderConfigInfo ?? new CommandBarcodeReaderConfigInfo();
            this.loggerFactory = loggerFactory;
            this.regex         = new Regex(regex ?? string.Empty);
            this.connectionStateChangedEventManager = new ConnectionStateChangedEventManager(name);

            this.comPort.ConnectionStateChanged += (s, e) =>
            {
                connectionStateChangedEventManager.OnConnectionStateChanged(ConnectionStateChanged, s, e);
            };
        }
Exemple #9
0
        public void Connect(IComPort serialPort)
        {
            if (isConnected)
                Disconnect();

            this.serialPort = serialPort;
            this.serialPort.OnDataReceivedEvent += RecieveMessage;
            this.serialPort.OnDisconnectedEvent += OnSerialPortDisconnectedEvent;
            isConnected = true;

            DebugGatewayState("Gateway connected.");

            if (OnConnectedEvent != null)
                OnConnectedEvent();
        }
Exemple #10
0
        public void Disconnect()
        {
            isConnected = false;
            if (serialPort != null)
            {
                serialPort.OnDataReceivedEvent -= RecieveMessage;
                serialPort.OnDisconnectedEvent -= OnSerialPortDisconnectedEvent;
                serialPort = null;
            }

            DebugGatewayState("Gateway disconnected.");


            if (OnDisconnectedEvent != null)
                OnDisconnectedEvent();
        }
        public AutoReconnectComPort(IComPort comPort, ILoggerFactory loggerFactory = null)
        {
            this.comPort       = comPort;
            this.loggerFactory = loggerFactory;
            this.connectionStateChangedEventManager = new ConnectionStateChangedEventManager(comPort.Name, loggerFactory);
            this.syncObj = new object();

            this.ConnectionStateChanged += (s, e) =>
            {
                if (!e.IsConnected)
                {
                    Reconnect();
                }
                ;
            };
        }
Exemple #12
0
 public bool Equals(IComPort x, IComPort y)
 {
     if (x == null)
     {
         return(y == null);
     }
     if (y == null)
     {
         return(false);
     }
     if (x.PortName != y.PortName)
     {
         return(false);
     }
     return(x.Name == y.Name);
 }
Exemple #13
0
        /// <summary>
        /// Creates a new XpressNet LI central
        /// </summary>
        /// <param name="serialPortConnection">an existing serialport connection</param>
        public Central(IComPort serialPortConnection)
        {
            Config = new FlakeLIConfiguration();

            _RigisteredEntities = new List <ILIEntity>();
            _ErrorInARow        = 0;

            // Open connection to interface
            SerialPortConnection = serialPortConnection;
            SerialPortConnection.Open();

            // start command queue worker process
            //System.Threading.ThreadPool.QueueUserWorkItem(delegate { _AnswerListener = new LIListener(this); }, null);
            logme.Log(string.Format(i18n.FlakeLIMsgs.StartLIListener, Port), logme.LogLevel.info);
            SerialPortConnection.ComDataReceived += new ComPortEventHandler(DataReceivedHandler);

            GetInterfaceAndCentralInfo();
        }
        public void Initialize(IComPort comPort)
        {
            InternalSupportsDisconnect = false;
            InternalSupportsReconnect  = false;
            ConnectionTransport        = new CommonSerialComport(comPort)
            {
                EnableLogging = InternalEnableLogging,
                CustomLogger  = InternalCustomLogger,
                EnableRxDebug = InternalEnableRxDebug,
                EnableTxDebug = InternalEnableTxDebug
            };

            DisplayProtocol = new SspCompanyVideoDisplayProtocol(ConnectionTransport, Id);
            DisplayProtocol.EnableLogging = InternalEnableLogging;
            DisplayProtocol.CustomLogger  = InternalCustomLogger;
            DisplayProtocol.StateChange  += StateChange;
            DisplayProtocol.RxOut        += SendRxOut;
            DisplayProtocol.LoadDriver(DataFile);
        }
        public void OneTimeSetUp()
        {
            this.connectionState  = false;
            this.tcpListener      = new TcpListener(IPAddress.Any, 8080);
            this.tcpClientComPort = new AutoReconnectComPort(
                new TcpClientComPort(
                    new TcpClientComPortConfigInfo()
            {
                RemoteIPAddress = "127.0.0.1",
                RemotePort      = 8080,
                ReceiveTimeout  = 500,
                SendTimeout     = 500
            },
                    Substitute.For <ILoggerFactory>()));
            this.tcpClientComPort.ConnectionStateChanged += (sender, e) =>
            {
                connectionState = e.IsConnected;
            };

            tcpListener.Start();
            AcceptTcpClientAsync(tcpListener);
        }
Exemple #16
0
 /// <summary>
 /// 启动监视
 /// </summary>
 /// <param name="connectionStateChanged">连接状态改变事件事件委托</param>
 /// <param name="comPort">通讯端口</param>
 public void StartMonitor(EventHandler <ConnectionStateChangedEventArgs> connectionStateChanged, IComPort comPort)
 {
     StartMonitor(() => comPort?.Write(new byte[] { }, 0, 0), comPort, connectionStateChanged);
 }
Exemple #17
0
 public int Compare(IComPort a, IComPort b) => ComPortExtensions.ComNameComparer.Compare(a?.PortName, b?.PortName);
Exemple #18
0
 public int CompareTo(IComPort other) => this.ComparedTo(other);
Exemple #19
0
 public static int ComparedTo(this IComPort portA, IComPort portB)
 => ComNameComparer.Compare(portA.PortName, portB.PortName);
Exemple #20
0
        /// <summary>
        /// Creates a new XpressNet LI central
        /// </summary>
        /// <param name="serialPortConnection">an existing serialport connection</param>
        public Central(IComPort serialPortConnection)
        {
            Config = new FlakeLIConfiguration();

            _RigisteredEntities = new List<ILIEntity>();
            _ErrorInARow = 0;

            // Open connection to interface
            SerialPortConnection = serialPortConnection;
            SerialPortConnection.Open();

            // start command queue worker process
            //System.Threading.ThreadPool.QueueUserWorkItem(delegate { _AnswerListener = new LIListener(this); }, null);
            logme.Log(string.Format(i18n.FlakeLIMsgs.StartLIListener, Port), logme.LogLevel.info);
            SerialPortConnection.ComDataReceived += new ComPortEventHandler(DataReceivedHandler);

            GetInterfaceAndCentralInfo();
        }
Exemple #21
0
 public PegasusCore(IComPort com)
 {
     this.com = com;
 }