Exemplo n.º 1
0
        public void L2Start()
        {
            try
            {
                L2TxThread      = new Thread(new ThreadStart(TxThreadProcess));
                L2TxThread.Name = "L2 - TX Thread" + cfg.GetName();

                L1Handler.Open();

                AddPkg2TxQueue.Reset();
                TxQueue.Clear();
                ThMan.AddThread(L2TxThread.Name, L2TxThread);
                L2TxThread.Start();
            }
            catch (System.Exception ex)
            {
                if (L1Handler.IsConnected())
                {
                    L1Handler.Close();
                }
                Thread t = ThMan.RemoveThread(L2TxThread.Name);

                if (t != null)
                {
                    t.Abort();
                    t = null;
                }

                throw ex;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// open connection with given config
        /// </summary>
        public virtual void Open()
        {
            try
            {
                if (seialPort != null)
                {
                    seialPort.Close();
                }
                seialPort          = new SerialPort();
                seialPort.PortName = config.PortName;
                seialPort.BaudRate = config.BaudRate;
                seialPort.DataBits = config.DataBit;
                seialPort.Parity   = config.parity;
                seialPort.StopBits = config.stopbit;

                // Set the read/write timeouts
                //TODO: get grom config, do not hardcode
                seialPort.ReadBufferSize  = 4096;
                seialPort.WriteBufferSize = 4096;
                seialPort.ReadTimeout     = 1000;
                seialPort.WriteTimeout    = 1500;

                // set handler
                seialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
                seialPort.Open();
                seialPort.DiscardInBuffer();
                isConnected = true;

                ThreadCom      = new Thread(new ThreadStart(NotifyReceiveMessage));
                ThreadCom.Name = "Communications - Receive message. L1 " + config.GetName();

                ThMan.AddThread(ThreadCom.Name, ThreadCom);

                ThreadCom.Start();
            }
            catch (System.Exception ex)
            {
                isConnected = false;
                throw ex;
            }
        }