/// <summary> /// PLCからのデータ取得 /// 大量のReadが発生しないように、上位概念において連続AddressをMergeして高速化を図ることにしているので、これ以外のReadMethosは現状未使用となっている /// </summary> /// <param name="unitAdr"></param> /// <param name="acMem"></param> /// <param name="readOffset"></param> /// <param name="length"></param> /// <param name="data"></param> /// <returns></returns> public CLK_ReturnCode Read(EventMemory memoryType, UInt32 readOffset, out UInt16[] data, UInt32 wordLength = 1) { CLK_ReturnCode result = CLK_ReturnCode.CLK_SUCCESS; if (memoryType == EventMemory.DM && readOffset > ClkLibConstants.DataLinkEndAddressDM) { // DM で、DataLink対象外のMemoryは、FinsCommandで取得する。→送信&受信待ちとなるので、取得時間が遅くなるけどね・・ var wordLengthWithHeader = wordLength + ClkLibConstants.FinsReceiveHeaderSizeAsWord; data = new UInt16[wordLengthWithHeader]; result = (CLK_ReturnCode)ClkLib_ReadAsUInt16ByFinsAtDM(UnitAdr, readOffset, data, wordLength, ClkLibConstants.FinsReceiveCommandWaitTime); data = data.Skip(ClkLibConstants.FinsReceiveHeaderSizeAsWord).ToArray(); SwapX2(data); return(result); } else { data = new UInt16[wordLength]; result = (CLK_ReturnCode)ClkLib_ReadAsUInt16(UnitAdr, memoryType, readOffset, data, wordLength); // DWORD 時、ここにSwapX2(data)いるかも。未検証。データが結局なかったので } if (result != CLK_ReturnCode.CLK_SUCCESS) { var sb = new StringBuilder("Read error "); sb.Append(result).Append(":"); sb.Append(memoryType).Append(","); sb.Append(readOffset).Append(","); sb.Append(wordLength).Append(","); data.ToList().ForEach(f => sb.Append(f)); Log.Error(sb.ToString()); } return(result); }
/// <summary> /// /// </summary> /// <param name="description"></param> /// <param name="memoryType">CIO はBitのみ</param> /// <param name="readOffset"></param> /// <param name="accessSize">CIO はBit限定</param> /// <param name="isEnable"></param> /// <param name="bitPlace"></param> public PlcMemoryInfo(string name, string description, EventMemory memoryType = EventMemory.DM, UInt32 readOffset = 0, AccessSize accessSize = AccessSize.WORD, BitPlace bitPlace = BitPlace.NOBIT, bool isEnable = true, Object constantValue = null) : this() { // 初期化 Name = name; Description = description; MemoryType = memoryType; AccessSize = accessSize; IsEnable = isEnable; ReadOffset = readOffset; BitPlace = bitPlace; ConstantValue = constantValue; }
// obsoleted private UInt16 ReadAsUInt16(EventMemory memoryType, UInt32 readOffset) { UInt32 length = 1; var data = new UInt16[length]; if (ClkLib_ReadAsUInt16(UnitAdr, memoryType, readOffset, data, length) == (int)CLK_ReturnCode.CLK_SUCCESS) { return(data[0]); } else { return(0); // エラー時は 0 } }
/// <summary> /// ビットの状態確認 obsoleted /// ・WordAccessしてデータ取得して、対象Bitを確認する。 /// </summary> /// <param name="memoryType"></param> /// <param name="readOffset"></param> /// <param name="bitPlace">OR条件での指定</param> /// <returns></returns> private bool HasFlags_OR(EventMemory memoryType, UInt32 readOffset, BitPlace bitPlace) { UInt32 length = 1; var data = new UInt16[length]; if (ClkLib_ReadAsUInt16(UnitAdr, memoryType, readOffset, data, length) == (int)CLK_ReturnCode.CLK_SUCCESS) { return(((BitPlace)data[0] & bitPlace) != BitPlace.NOBIT); } else { return(false); // エラー時は 0 } }
// obsoleted private UInt32 ReadAsUInt32(EventMemory memoryType, UInt32 readOffset, AccessSize accessSize, BitPlace bitPlace = BitPlace.NOBIT) { switch (accessSize) { case AccessSize.BIT: return((UInt16)(HasFlags_AND(memoryType, readOffset, bitPlace) ? 0 : 1)); case AccessSize.BYTE: throw new NotImplementedException("Word Access Address しか無い場合、Byte指定はあり得ない。上位/下位のどちらかが取得不能なので"); case AccessSize.WORD: return(ReadAsUInt16(memoryType, readOffset)); case AccessSize.DWORD: return((UInt32)(ReadAsUInt16(memoryType, readOffset) << 16) + ReadAsUInt16(memoryType, (UInt32)readOffset + 1)); default: return(UInt32.MinValue); } }
/// <summary> /// WORD2SmallInt 未対応。obsoleted /// </summary> /// <param name="memoryType"></param> /// <param name="readOffset"></param> /// <param name="accessSize"></param> /// <param name="bitPlace"></param> /// <returns></returns> private string ReadAsString(EventMemory memoryType, UInt32 readOffset, AccessSize accessSize, BitPlace bitPlace = BitPlace.NOBIT) { switch (accessSize) { case AccessSize.BIT: return(HasFlags_AND(memoryType, readOffset, bitPlace).ToString()); case AccessSize.BYTE: throw new NotImplementedException("Word Access Address しか無い場合、Byte指定はあり得ない。上位/下位のどちらかが取得不能なので"); case AccessSize.WORD: return(ReadAsUInt16(memoryType, readOffset).ToString()); case AccessSize.DWORD: return(ReadAsUInt16(memoryType, readOffset).ToString() + ReadAsUInt16(memoryType, readOffset + 1).ToString()); default: return("illegal parameter"); } }
public bool WithinValue(EventMemory memoryType, UInt32 readOffset) { return(MemoryType == memoryType && WithinValue(readOffset)); }
public PlcMemoryCache(EventMemory memoryType, UInt32 readOffset, UInt32 length) { MemoryType = memoryType; ReadOffset = readOffset; Length = length; }
private static extern Int32 ClkLib_ReadAsUInt16(Int32 unitAdr, EventMemory memoryType, UInt32 readOffset, [Out, MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U2, SizeParamIndex = 4)] UInt16[] result, UInt32 length);
internal PlcMemoryInfoTrigger(Object triggerValue, TriggerTypes type, string name, string description, EventMemory memoryType = EventMemory.DM, UInt32 readOffset = 0, AccessSize accessSize = AccessSize.WORD, BitPlace bitPlace = BitPlace.NOBIT, bool isEnable = true, Object constantValue = null) : base(name, description, memoryType, readOffset, accessSize, bitPlace, isEnable, constantValue) { TriggerValue = triggerValue; TriggerType = type; }