public void ArrayStringAccessTest() { var mapping = "STRING_ARRAY_TEST_MAPPING"; var accessDict = new Dictionary <string, object> { { "TEXT[1]", "TEST1" }, { "TEXT[5]", "TEST5" }, }; Test(mapping, accessDict, ""); //Byte data check var dbData = MockPlc.GetPlcEntry("DB30").Data; Assert.True(dbData.Slice(0, 2).Span.SequenceEqual(new byte[] { 35, 5 })); Assert.True(dbData.Slice(2, 5).Span.SequenceEqual("TEST1".ToByteArray(5))); Assert.True(dbData.Slice(152, 2).Span.SequenceEqual(new byte[] { 35, 5 })); Assert.True(dbData.Slice(154, 5).Span.SequenceEqual("TEST5".ToByteArray(5))); }
private static Task Papper_OnRead(IEnumerable <DataPack> reads) { var result = reads.ToList(); foreach (var item in result) { Console.WriteLine($"OnRead: selector:{item.Selector}; offset:{item.Offset}; length:{item.Length}"); var res = MockPlc.GetPlcEntry(item.Selector, item.Offset + item.Length).Data.Slice(item.Offset, item.Length); if (!res.IsEmpty) { item.ApplyData(res); item.ExecutionResult = ExecutionResult.Ok; } else { item.ExecutionResult = ExecutionResult.Error; } } return(Task.CompletedTask); }
private static Task Papper_OnWrite(IEnumerable <DataPack> reads) { var result = reads.ToList(); foreach (var item in result) { if (item.BitMask == 0) { Console.WriteLine($"OnWrite: selector:{item.Selector}; offset:{item.Offset}; length:{item.Length}"); item.Data.Slice(0, item.Length).CopyTo(MockPlc.GetPlcEntry(item.Selector, item.Offset + item.Length).Data.Slice(item.Offset, item.Length)); item.ExecutionResult = ExecutionResult.Ok; } else { for (int j = 0; j < item.Data.Length; j++) { var bItem = item.Data.Span[j]; var bm = item.BitMask; for (var i = 0; i < 8; i++) { var bit = bm.GetBit(i); if (bit) { var b = MockPlc.GetPlcEntry(item.Selector, item.Offset + 1).Data.Span[item.Offset]; MockPlc.GetPlcEntry(item.Selector, item.Offset + 1).Data.Span[item.Offset] = b.SetBit(i, bItem.GetBit(i)); item.ExecutionResult = ExecutionResult.Ok; bm = bm.SetBit(i, false); if (bm == 0) { break; } } } } } } return(Task.CompletedTask); }