You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
using Mirle.Component.MPLC.DataBlocks; using Mirle.Component.MPLC.Interfaces; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq;
namespace Mirle.Component.MPLC.FileData { /// <summary>
///
/// </summary>
public class FileDataViewer : IMPLCProvider { /// <summary>
/// 建構式
/// </summary>
/// <param name="fileReader">檔案讀取器</param>
public FileDataViewer(FileReader fileReader) { _fileReader = fileReader; foreach (FileDataBlock fileReaderDataBlock in _fileReader.GetDataBlocks()) { _dataBlocks.Add(new FileDataBlock(fileReaderDataBlock.DeviceRange, fileReaderDataBlock.ColumnIndex)); } } /// <summary>
/// 檔案讀取器
/// </summary>
private readonly FileReader _fileReader; /// <summary>
/// 資料區塊
/// </summary>
private readonly List<FileDataBlock> _dataBlocks = new List<FileDataBlock>(); /// <summary>
/// 是否連線
/// </summary>
public bool IsConnected => true; /// <summary>
///
/// </summary>
/// <param name="begin"></param>
/// <param name="end"></param>
/// <returns></returns>
public IEnumerable<DateTime> Query(DateTime begin, DateTime end) { return _fileReader.GetDateTimeIndexes().Where(t => t.TimeOfDay >= begin.TimeOfDay && t.TimeOfDay <= end.TimeOfDay).OrderBy(i => i); } /// <summary>
///
/// </summary>
/// <param name="index"></param>
public void RefreshRawData(DateTime index) { foreach (FileDataBlock block in _dataBlocks) { try { byte[] newByteArray = _fileReader.GetRawDataByDateTimeIndex(index, block.ColumnIndex); if (newByteArray != null) block.SetRawData(newByteArray); } catch (Exception ex) { Debug.WriteLine($"{ex.Message}-{ex.StackTrace}"); } } } /// <summary>
/// 取得位元
/// </summary>
/// <param name="address">位置</param>
/// <returns>True/False</returns>
public bool GetBit(string address) { foreach (var block in _dataBlocks) { if (block.TryGetBit(address, out bool value)) return value; } return false; } /// <summary>
/// 設置位元開啟
/// </summary>
/// <param name="address">位置</param>
public void SetBitOn(string address) { return; } /// <summary>
/// 設置位元關閉
/// </summary>
/// <param name="address">位置</param>
public void SetBitOff(string address) { return; } /// <summary>
/// 讀取字元
/// </summary>
/// <param name="address">位置</param>
/// <returns>字元</returns>
public int ReadWord(string address) { foreach (var block in _dataBlocks) { if (block.TryGetWord(address, out int value)) return value; } return 0; } /// <summary>
/// 寫入字元
/// </summary>
/// <param name="address">位置</param>
/// <param name="data">字元</param>
public void WriteWord(string address, int data) { return; } /// <summary>
/// 讀取多個字元
/// </summary>
/// <param name="startAddress">起始位置</param>
/// <param name="length">長度</param>
/// <returns>字元陣列</returns>
public int[] ReadWords(string startAddress, int length) { foreach (var block in _dataBlocks) { if (block.TryGetWords(startAddress, out int[] data, length)) return data; } return new int[length]; } /// <summary>
/// 寫入多個字元
/// </summary>
/// <param name="startAddress">起始位置</param>
/// <param name="data">字元陣列</param>
public void WriteWords(string startAddress, int[] data) { return; } } }
|