public async Task MixedAccessWithDataChangeTest2() { var mapping = "DB_Safety2"; var t = new Stopwatch(); t.Start(); short value = -1; await _papper.WriteAsync(PlcWriteReference.FromAddress($"{mapping}.SafeMotion.Header.NumberOfActiveSlots", (short)0)); var result2 = await _papper.ReadBytesAsync(new List <PlcReadReference> { PlcReadReference.FromAddress($"{mapping}.SafeMotion") }); var sub = _papper.SubscribeDataChanges((s, e) => { value = (short)e[$"{mapping}.SafeMotion.Header.NumberOfActiveSlots"]; }, PlcWatchReference.FromAddress($"{mapping}.SafeMotion.Header.NumberOfActiveSlots", 10), PlcWatchReference.FromAddress($"{mapping}.SafeMotion.Header.States.ChecksumInvalid", 10)); await _papper.WriteAsync(PlcWriteReference.FromAddress($"{mapping}.SafeMotion.Header.NumberOfActiveSlots", (short)1)); await Task.Delay(2000); Assert.Equal((short)1, value); sub.Dispose(); t.Stop(); }
public void TestGetAddressOfWString() { var mapping = "DB_MotionHMI"; var result = _papper.GetAddressOf(PlcReadReference.FromAddress($"{mapping}.HMI.MotionLine[8].Txt.Position[1]")); Assert.Equal(9442, result.Offset.Bytes); Assert.Equal(54, result.Size.Bytes); }
public void TestGetAddressOf() { var mapping = "DB_Safety2"; var result = _papper.GetAddressOf(PlcReadReference.FromAddress($"{mapping}.SafeMotion.Slots")); Assert.Equal(14, result.Offset.Bytes); Assert.Equal(8670, result.Size.Bytes); }
public void TestStructuralAllAccess() { var mapping = "DB_Safety2"; var t = new Stopwatch(); t.Start(); var result = _papper.ReadAsync(PlcReadReference.FromAddress($"{mapping}")).GetAwaiter().GetResult(); t.Stop(); }
private static void PerformReadFull(PlcDataMapper papper) { Console.WriteLine(); Console.ForegroundColor = ConsoleColor.DarkGreen; var result = papper.ReadAsync(PlcReadReference.FromAddress("DB_Safety.SafeMotion")).GetAwaiter().GetResult(); foreach (var item in result) { Console.WriteLine($"Red:{item.Address} = {item.Value}"); } Console.ResetColor(); }
public void ReadNonExistingValue() { var mapping = "STRING_ARRAY_TEST_MAPPING"; var accessDict = new Dictionary <string, object> { { "XXX", "TEST1" } }; Assert.Throws <InvalidVariableException>(() => { var result = _papper.ReadAsync(PlcReadReference.FromRoot(mapping, accessDict.Keys.ToArray()).ToArray()).GetAwaiter().GetResult(); Assert.Empty(result); }); }
public void TestStructuralAllWithSerializerAccess() { var mapping = "DB_Safety2"; var t = new Stopwatch(); var ser = new PlcDataMapperSerializer(); t.Start(); var address = _papper.GetAddressOf(PlcReadReference.FromAddress($"{mapping}")).RawAddress <byte>(); var result = _papper.ReadAsync(PlcReadReference.FromAddress(address)).GetAwaiter().GetResult().FirstOrDefault(); var x = ser.Deserialize <DB_Safety>((byte[])result.Value); t.Stop(); }
private static void PerformRead(PlcDataMapper papper) { Console.WriteLine(); Console.ForegroundColor = ConsoleColor.DarkGreen; var result = papper.ReadAsync(PlcReadReference.FromRoot("DB_Safety", "SafeMotion.Header.NumberOfActiveSlots", "SafeMotion.Header.Generated", "SafeMotion.Slots[42].SlotId", "SafeMotion.Slots[42].HmiId", "SafeMotion.Slots[42].Commands.TakeoverPermitted").ToArray()).GetAwaiter().GetResult();; foreach (var item in result) { Console.WriteLine($"Red:{item.Address} = {item.Value}"); } Console.ResetColor(); }
public async void TestDuplicateDetection() { var writeData = new Dictionary <string, object> { { "W88", (UInt16)3 }, { "X99_0", true }, }; var items = writeData.Keys.Select(variable => PlcReadReference.FromAddress($"DB15.{variable}")).ToArray(); using (var sub = _papper.CreateSubscription()) { await Assert.ThrowsAsync <InvalidOperationException>(async() => { var c1 = sub.DetectChangesAsync(); // returns because we start a new detection var c2 = await sub.DetectChangesAsync(); // returns because we start a new detection await c1; }); } }
public async Task MixedAccessTest() { var mapping = "DB_Safety2"; var t = new Stopwatch(); t.Start(); var result1 = _papper.ReadAsync(PlcReadReference.FromAddress($"{mapping}.SafeMotion.Header.NumberOfActiveSlots"), PlcReadReference.FromAddress($"{mapping}.SafeMotion.Header.States.ChecksumInvalid")); var result2 = await _papper.ReadBytesAsync(new List <PlcReadReference> { PlcReadReference.FromAddress($"{mapping}.SafeMotion") }); await result1; t.Stop(); }
public void TestStructuralAccess() { var mapping = "DB_Safety2"; var header = new UDT_SafeMotionHeader { Generated = Normalize(DateTime.Now), NumberOfActiveSlots = 2, Commands = new UDT_SafeMotionHeader_Commands { AllSlotsLocked = true, UpdateAllowed = true }, States = new UDT_SafeMotionHeader_States { ChecksumInvalid = true, UpdateRequested = true } }; var accessDict = new Dictionary <string, object> { { "SafeMotion.Header", header }, }; var result = _papper.ReadAsync(accessDict.Keys.Select(variable => PlcReadReference.FromAddress($"{mapping}.{variable}")).ToArray()).GetAwaiter().GetResult(); Assert.Equal(accessDict.Count, result.Length); var writeResults = _papper.WriteAsync(PlcWriteReference.FromRoot(mapping, accessDict.ToArray()).ToArray()).GetAwaiter().GetResult(); foreach (var item in writeResults) { Assert.Equal(ExecutionResult.Ok, item.ActionResult); } var result2 = _papper.ReadAsync(accessDict.Keys.Select(variable => PlcReadReference.FromAddress($"{mapping}.{variable}")).ToArray()).GetAwaiter().GetResult(); Assert.Equal(accessDict.Count, result2.Length); Assert.False(AreDataEqual(result, result2)); // Assert.True(AreDataEqual(ToExpando(header), result2.Values.FirstOrDefault())); }
public async Task TestMultiWrite(string mapping, Type type) { _client = new Dacs7Client("192.168.0.148:102,0,2", PlcConnectionType.Basic, 5000); await _client.ConnectAsync(); if (_client.IsConnected && (_mapper == null || _mapper.PduSize > _client.PduSize)) { var pduSize = _client.PduSize; _mapper = new PlcDataMapper(pduSize, Papper_OnRead, Papper_OnWrite, OptimizerType.Items); _mapper.AddMapping(type); } var data = await _mapper.ReadAsync(PlcReadReference.FromAddress($"{mapping}.This")); await _mapper.WriteAsync(PlcWriteReference.FromAddress($"{mapping}.This", data)); await _client.DisconnectAsync(); }
private void Test <T>(string mapping, Dictionary <string, object> accessDict, T defaultValue) { //Initial read to ensure all are false var toRead = accessDict.Keys.Select(variable => PlcReadReference.FromAddress($"{mapping}.{variable}")).ToArray(); var result = _papper.ReadAsync(toRead).GetAwaiter().GetResult(); Assert.Equal(accessDict.Count, result.Length); foreach (var item in result) { Assert.Equal(defaultValue, (T)item.Value); } //Write the value _papper.WriteAsync(PlcWriteReference.FromRoot(mapping, accessDict.ToArray()).ToArray()).GetAwaiter().GetResult(); //Second read to ensure correct written result = _papper.ReadAsync(accessDict.Keys.Select(variable => PlcReadReference.FromAddress($"{mapping}.{variable}")).ToArray()).GetAwaiter().GetResult(); Assert.Equal(accessDict.Count, result.Length); foreach (var item in result) { Assert.Equal((T)accessDict[item.Variable], (T)item.Value); } }
public PlcReadReference ParseReadReference() => PlcReadReference.FromAddress($"DB_Safety2.SafeMotion.Header.States.ChecksumInvalid");
public void PerformReadWriteRaw() { var papper = new PlcDataMapper(960, Papper_OnRead, Papper_OnWrite); var readResults = papper.ReadAsync(PlcReadReference.FromAddress("DB2000.W2")).GetAwaiter().GetResult(); var writeResults = papper.WriteAsync(PlcWriteReference.FromAddress("DB2000.W2", (UInt16)3)).GetAwaiter().GetResult(); }
/// <summary> /// /// </summary> /// <param name="address"> [Mapping].[Variable]</param> /// <returns></returns> public static PlcWatchReference FromPlcReadReference(PlcReadReference reference, int watchCycle) => new PlcWatchReference(reference.Address, watchCycle);