Beispiel #1
0
        static void Main(string[] args)
        {
            token = new CancellationTokenSource();
            System.Console.CancelKeyPress += Console_CancelKeyPress;
            NLog.LogManager.Configuration  = new NLog.Config.XmlLoggingConfiguration("nlog.config");
            AbsMqttBase.SetDefaultLoggerName("nlog.config", true);
            logger = NLog.LogManager.Configuration.LogFactory.GetLogger("");

            AppSetting            setting               = new AppSetting("appsettings.json");
            ModbusConfig          pvmodbusConfig        = setting.GetSection <ModbusConfig>("PVModbus");
            ModbusConfig          essmodbusConfig       = setting.GetSection <ModbusConfig>("ESSModbus");
            var                   redisConfiguration    = setting.GetSection <RedisConfiguration>("redis");
            ConnectionMultiplexer connectionMultiplexer = ConnectionMultiplexer.Connect(redisConfiguration.ConfigurationOptions);
            MysqlDataAccess       access = new MysqlDataAccess(setting.GetConnectionString("etridb"));
            RelayDataInformation  relayDataInformation = setting.GetSection <RelayDataInformation>("Information");

            try
            {
                using (RelayDevicePublisher publisher = new RelayDevicePublisher(relayDataInformation, pvmodbusConfig, essmodbusConfig, access, connectionMultiplexer, logger))
                {
                    publisher.Initialize();
                    Task t = publisher.RunningAsync(token.Token);
                    t.Wait();
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }
        }
Beispiel #2
0
 public RelayDevicePublisher(RelayDataInformation dataInformation, ModbusConfig pvmodbusConfig, ModbusConfig essmodbusConfig, MysqlDataAccess dataAccess, ConnectionMultiplexer connectionMultiplexer, ILogger logger)
 {
     this.relayDataInformation = dataInformation;
     this.pvmodbusConfig       = pvmodbusConfig;
     this.essmodbusConfig      = essmodbusConfig;
     this.logger          = logger;
     this.mysqlDataAccess = dataAccess;
     redisDb = connectionMultiplexer.GetDatabase(1);
 }
Beispiel #3
0
        //protected override void OnInitialize()
        //{
        //    base.OnInitialize();
        //    InitializeModbus();
        //}

        private void InitializeModbus(ref EasyModbus.ModbusClient Client, ModbusConfig modbusConfig)
        {
            if (string.IsNullOrEmpty(modbusConfig.SerialPort))
            {
                Client = new EasyModbus.ModbusClient(modbusConfig.IpAddress, modbusConfig.Port);
            }
            else
            {
                Client          = new EasyModbus.ModbusClient(modbusConfig.SerialPort);
                Client.Baudrate = modbusConfig.BaudRate;
                Client.StopBits = modbusConfig.StopBits;
                Client.Parity   = modbusConfig.Parity;
            }
        }