//Get connection, reader, writer, autoReader and so on.
        private OperationResult SetProtocolEntity()
        {
            try
            {
                this.conn = ConfigProtocol.GetConnection();
                this.conn.Connect();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                //return new OperationResult(1, ex.Message);
            }
            finally
            {
                if (this.conn == null)
                {
                    throw new NullReferenceException("EtherCAT初始化失败");
                }
            }
            /*reader and writer*/
            reader = (IReader)conn;
            writer = (IWriter)conn;
            if (ConnectionContext.isAutoRead)
            {
                autoReader = (IAutoReader)conn;

                if (autoReader != null)
                {
                    autoReader.InitAutoReadConfig();
                    autoReader.AutoDataChanged += ReadDataToDatapool;
                }
                else
                {
                    throw new Exception("获取AutoReader失败");
                }
            }

            return(new OperationResult());
        }
 public DashboardViewModel(IAutoReader reader, IVehicleInfoService vehicleInfoService)
 {
     AutoReader          = reader;
     _vehicleInfoService = vehicleInfoService;
 }