protected override async Task ReadDbAsync(IDatablockModel db) { VerifyConnected(); if (_collectedPlcTasksToExecute.Count > 0) { Console.WriteLine($"BEG ReadDbAsync sec {System.DateTime.Now.Second} ms {System.DateTime.Now.Millisecond}"); } //await _semaphoreSlim.WaitAsync(5); byte[] dbBytes = await _plcReader.ReadBytesAsync(S7.Net.DataType.DataBlock, db.Number, db.FirstByte, db.ByteCount); // TODO change Debug.Assert to if and create scheduler to check if it fails several times, // and throw exception + handling remove this db from read list //Debug.Assert(dbBytes.Length == db.ByteCount - db.FirstByte); List <PlcComIndexValueModel> indexValueModels = new List <PlcComIndexValueModel>(); for (int i = 0; i < db.Signals.Count; i++) { SignalModel s = db.Signals[i]; int signalByteCount = s.ByteCount; int skipBytesValue = s.DbByteIndex() - db.FirstByte; byte[] signalValueArray = dbBytes.Skip(skipBytesValue).Take(s.ByteCount).ToArray(); indexValueModels.Add(new PlcComIndexValueModel(Index, db.Index, s.Index, s.BytesToValue(signalValueArray))); } PlcReadResultEventArgs args = new PlcReadResultEventArgs(indexValueModels); RaiseHasNewData(args); }
protected override async Task ReadDbAsync(IDatablockModel db) { VerifyConnected(); List <PlcComIndexValueModel> indexValueModels = new List <PlcComIndexValueModel>(); for (int i = 0; i < db.Signals.Count; i++) { SignalModel s = db.Signals[i]; double simValue = 0; if (s is BoolSignalModel) { bool boolVal = _simulatedSignals[s.Index].RandomBool(); simValue = boolVal == true ? 1.0 : 0.0; } else { if (i % 3 == 0) { simValue = _simulatedSignals[s.Index].Sine(); } else { simValue = _simulatedSignals[s.Index].RandomFloat(); } } if (i % 3 == 0) { indexValueModels.Add(new PlcComIndexValueModel(Index, db.Index, s.Index, simValue)); } } PlcReadResultEventArgs args = new PlcReadResultEventArgs(indexValueModels); RaiseHasNewData(args); await DelayAsync(100); }
protected abstract Task ReadDbAsync(IDatablockModel db);
protected override Task ReadDbAsync(IDatablockModel db) { throw new NotImplementedException(); }