public void when_zip_files_on_day() { Experiment exp = new Experiment(); exp.Name = "Exp1"; IDriver driver = new DriverInt() { ValueStorage = new ValueStorage() }; IntegerVariable integerVariable = new IntegerVariable(0, "var1") { Driver = driver, MinValue = 0, MaxValue = 16, LogValues = true }; exp.AddVariable(integerVariable); // 5 bits IntegerVariable integerVariable1 = new IntegerVariable(1, "var2") { Driver = driver, MinValue = 0, MaxValue = 1015 }; exp.AddVariable(integerVariable1); // 10 bits BoolVariable boolVariable = new BoolVariable(2, "var3") { Driver = driver, LogValues = true }; exp.AddVariable(boolVariable); // 1 bits driver.AddVariable(integerVariable); driver.AddVariable(integerVariable1); driver.AddVariable(boolVariable); logger = new VariableLogger(new List <Experiment>() { exp }); exp.Start(20); Mock <IDateTimeProvider> mock = new Mock <IDateTimeProvider>(MockBehavior.Strict); logger.TimeProvider = mock.Object; mock.Setup(x => x.Now).Returns(DateTime.Now); Dictionary <int, double> varValues = new Dictionary <int, double> { { 0, 23 }, { 1, 12 }, }; logger.ReceiveVariableValues(varValues); mock.Setup(x => x.Now).Returns(new DateTime(2012, 5, 12)); logger.ReceiveVariableValues(varValues); }
public void Cuando_recive_valores_son_salvados_solo_los_que_tienen_que_ser_salvados() { Experiment exp = new Experiment(); IDriver driver = new DriverInt() { ValueStorage = new ValueStorage() }; IntegerVariable integerVariable = new IntegerVariable(0, "var1") { Driver = driver, MinValue = 0, MaxValue = 16, LogValues = true }; exp.AddVariable(integerVariable); // 5 bits IntegerVariable integerVariable1 = new IntegerVariable(1, "var2") { Driver = driver, MinValue = 0, MaxValue = 1015 }; exp.AddVariable(integerVariable1); // 10 bits BoolVariable boolVariable = new BoolVariable(2, "var3") { Driver = driver, LogValues = true }; exp.AddVariable(boolVariable); // 1 bits driver.AddVariable(integerVariable); driver.AddVariable(integerVariable1); driver.AddVariable(boolVariable); logger = new VariableLogger(new List <Experiment>() { exp }); Dictionary <int, double> varValues = new Dictionary <int, double> { { 0, 23 }, { 1, 12 }, }; logger.ExperimentsLogger.Count.ShouldEqual(1); ExperimentLoggerStub stub = new ExperimentLoggerStub(exp); logger.ExperimentsLogger.RemoveAt(0); logger.ExperimentsLogger.Add(stub); logger.ReceiveVariableValues(varValues); stub.ValuesReceive[0].ShouldEqual(23); stub.ValuesReceive[1].ShouldEqual(12); }
public void then_can_save_variables() { Experiment exp = new Experiment(); IDriver driver = new DriverInt() { ValueStorage = new ValueStorage() }; IntegerVariable integerVariable = new IntegerVariable(0, "var1") { Driver = driver, MinValue = 0, MaxValue = 16, LogValues = true }; exp.AddVariable(integerVariable); // 5 bits IntegerVariable integerVariable1 = new IntegerVariable(1, "var2") { Driver = driver, MinValue = 0, MaxValue = 1015 }; exp.AddVariable(integerVariable1); // 10 bits BoolVariable boolVariable = new BoolVariable(2, "var3") { Driver = driver, LogValues = true }; exp.AddVariable(boolVariable); // 1 bits driver.AddVariable(integerVariable); driver.AddVariable(integerVariable1); driver.AddVariable(boolVariable); ExperimentLoggerStub logger = new ExperimentLoggerStub(exp); Dictionary <int, double> varValues = new Dictionary <int, double> { { 0, 23 }, { 1, 12 }, }; logger.ReceiveNewVariableValues(varValues); exp.Start(0); Thread.Sleep(50); logger.ExperimentSerializer.Serializers.Count.ShouldEqual(2); logger.ExperimentSerializer.Serializers.ElementAt(0).Value.ShouldBeInstanceOfType(typeof(IntegerVariableSerializer)); logger.ExperimentSerializer.Serializers.ElementAt(1).Value.ShouldBeInstanceOfType(typeof(BoolVariableSerializer)); }
static void Main(string[] args) { //var service = InitializeDatabase(); Server server = new Server { Timer = new RealtimeFixedIntervalTimer { Interval = 250 } }; Uri uri1 = new Uri(ConfigurationManager.AppSettings["addr"]); ServiceHost host = new ServiceHost(typeof(ServerService), uri1); host.Open(); Console.WriteLine("SCADA SecuritySvc listen {0}", uri1.ToString()); ValueStorage storage = new ValueStorage(); server.ValueStorage = storage; AlarmManager manager = new AlarmManager { TimeProvider = new DateTimeProvider() }; manager.Alarms.Add(new Alarm { AlarmID = 1, Sensor = new RangeAlarmSensor() { MaxBound = 190, MinBound = 160 }, VariableID = 1 }); server.OnVariablesChange += manager.ReceiveVariableValues; /*IDriver driver = new DriverModbusRTU * { * ValueStorage = storage, * Timer = new RealtimeFixedIntervalTimer { Interval = 250 } * }; * ModbusStationRTU stationRtu = new ModbusStationRTU("Station1", 1, * new SerialComm("COM1", 9600, 8, Parity.None, StopBits.One), true); * * Variable var1, var2, var3, var4, var5, var6, var7, var8; * driver.AddVariable(var1 = new Variable(1, "Out40") { TicksToSample = 2, Driver = driver, DriverConfiguration = new ModbusConfiguration(stationRtu, 64, ModbusTypeData.Coils), VariableSerialize = new BoolVariableSerializer() { PositionAllData = 0, PositionInByte = 0 } }); * driver.AddVariable(var2 = new Variable(2, "In00") { TicksToSample = 2, Driver = driver, DriverConfiguration = new ModbusConfiguration(stationRtu, 0, ModbusTypeData.Coils) }); * driver.AddVariable(var3 = new Variable(3, "In02") { TicksToSample = 2, Driver = driver, DriverConfiguration = new ModbusConfiguration(stationRtu, 2, ModbusTypeData.Coils) }); * driver.AddVariable(var4 = new Variable(4, "In04") { TicksToSample = 2, Driver = driver, DriverConfiguration = new ModbusConfiguration(stationRtu, 4, ModbusTypeData.Coils) }); * driver.AddVariable(var5 = new Variable(5, "Timer1") { TicksToSample = 2, Driver = driver, DriverConfiguration = new ModbusConfiguration(stationRtu, 20483, ModbusTypeData.Inputs_Registers) }); * driver.AddVariable(var6 = new Variable(6, "Timer2") { TicksToSample = 2, Driver = driver, DriverConfiguration = new ModbusConfiguration(stationRtu, 20484, ModbusTypeData.Inputs_Registers) }); * driver.AddVariable(var7 = new Variable(7, "Timer3") { TicksToSample = 2, Driver = driver, DriverConfiguration = new ModbusConfiguration(stationRtu, 20485, ModbusTypeData.Inputs_Registers) }); * driver.AddVariable(var8 = new Variable(8, "Out46") { TicksToSample = 2, Driver = driver, DriverConfiguration = new ModbusConfiguration(stationRtu, 70, ModbusTypeData.Coils) }); */IDriver driver = new DriverInt { ValueStorage = storage, Timer = new RealtimeFixedIntervalTimer { Interval = 250 } }; Variable var1, var2, var3, var4, var5, var6, var7; driver.AddVariable(var1 = new IntegerVariable(1, "Out40") { TicksToSample = 2, Driver = driver, }); driver.AddVariable(var2 = new IntegerVariable(2, "In00") { TicksToSample = 1, Driver = driver, LogValues = true, MinValue = 0, MaxValue = 230 }); driver.AddVariable(var3 = new IntegerVariable(3, "In02") { TicksToSample = 1, Driver = driver, LogValues = true, MinValue = 0, MaxValue = 230 }); driver.AddVariable(var4 = new IntegerVariable(4, "In04") { TicksToSample = 1, Driver = driver, LogValues = true, MinValue = 0, MaxValue = 230 }); driver.AddVariable(var5 = new IntegerVariable(5, "Timer1") { TicksToSample = 2, Driver = driver }); driver.AddVariable(var6 = new IntegerVariable(6, "Timer2") { TicksToSample = 2, Driver = driver }); driver.AddVariable(var7 = new IntegerVariable(7, "Timer3") { TicksToSample = 2, Driver = driver }); server.AddDriver(driver); Experiment experiment = new Experiment { Name = "Exp1" }; experiment.AddVariable(var1); experiment.AddVariable(var2); experiment.AddVariable(var3); experiment.AddVariable(var4); experiment.AddVariable(var5); experiment.AddVariable(var6); experiment.AddVariable(var7); //experiment.AddVariable(var8); server.AddExperiment(experiment); //VariableLogger logger = new VariableLogger(new List<Experiment>() { experiment }); //server.OnVariablesChange += logger.ReceiveVariableValues; server.Start(0); experiment.Start(0); ThreadPool.QueueUserWorkItem(myThead, server); Console.Read(); server.Stop(0); Console.Read(); host.Abort(); host.Close(); }