示例#1
0
 public void Disconnect()
 {
     try
     {
         m_Adapter.Close();
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         throw;
     }
 }
示例#2
0
        internal DeviceConnectionState Initialize(int Timeout)
        {
            m_ConnectionState = DeviceConnectionState.ConnectionInProcess;

            FireConnectionEvent(m_ConnectionState, "Adapter initializing");

            if (m_IsAdapterEmulation)
            {
                m_ConnectionState = DeviceConnectionState.ConnectionSuccess;

                FireConnectionEvent(m_ConnectionState, "Adapter initialized");

                return(m_ConnectionState);
            }

            try
            {
                if (m_Adapter != null)
                {
                    if (m_Adapter.Connected)
                    {
                        m_Adapter.Close();
                    }
                }

                m_Adapter = new SCCIMasterAdapter(true);
                m_Adapter.Initialize(new SerialPortConfigurationMaster
                {
                    PortNumber                  = Settings.Default.AdapterPort,
                    BaudRate                    = 115200,
                    DataBits                    = 8,
                    StopBits                    = StopBits.One,
                    ParityMode                  = Parity.None,
                    TimeoutForSyncReceive       = Timeout,
                    TimeoutForSyncStreamReceive = Timeout,
                    UseRetransmitsForArrays     = true,
                    RetransmitsCountOnError     = 5
                });

                m_ConnectionState = DeviceConnectionState.ConnectionSuccess;

                FireConnectionEvent(m_ConnectionState, "Adapter initialized");
            }
            catch (SerialConnectionException ex)
            {
                m_ConnectionState = DeviceConnectionState.ConnectionFailed;

                FireConnectionEvent(m_ConnectionState, String.Format("Adapter initialization error: {0}", ex.Message));
            }

            return(m_ConnectionState);
        }