Example #1
0
        public void CreateS7Device()
        {
            // prepare
            var dpConfig = new List <DeviceConfig> {
                new DeviceConfig {
                    Name   = "plc01",
                    Driver = "s7",
                    Config = "host=127.0.0.1;rack=0;slot=0",
                    Tags   = null
                },
                new DeviceConfig {
                    Name   = "plc02",
                    Driver = "s7",
                    Config = "host=127.0.0.1;rack=0;slot=0",
                    Tags   = null
                }
            };

            var loggerMock = new Mock <ILogger>();
            var devices    = DeviceFactory.CreateDevices(dpConfig, loggerMock.Object);

            Assert.Equal(2, devices.Count);

            Assert.IsType <S7Device>(devices["plc01"]);

            Assert.IsType <S7Device>(devices["plc02"]);
        }
Example #2
0
 public void Initialize()
 {
     Logger.LogInformation($"OTM {Config.Name} Context Initializing ...");
     try
     {
         DataPoints   = DataPointFactory.CreateDataPoints(Config.DataPoints, Logger);
         Devices      = DeviceFactory.CreateDevices(Config.Devices, Logger);
         Transactions = TransactionFactory.CreateTransactions(Config.Transactions, DataPoints, Devices, Logger);
         Logger.LogInformation($"OTM {Config.Name} Context Initialized!");
     }
     catch (Exception ex)
     {
         Logger.LogError(ex, $"OTM {Config.Name} Context Initialization error!");
     }
 }
Example #3
0
        public void InvalidDriverName()
        {
            // prepare
            var dpConfig = new List <DeviceConfig> {
                new DeviceConfig {
                    Name   = "plc01",
                    Driver = "xxx",
                    Config = "",
                    Tags   = null
                }
            };

            var loggerMock = new Mock <ILogger>();
            var ex         = Record.Exception(() => DeviceFactory.CreateDevices(dpConfig, loggerMock.Object));

            Assert.Equal("Driver", ex?.Data["field"]);
        }