public PlcMemoryValue ReadAsValue(PlcMemoryInfo plcMemoryInfo) { // 固定値の場合即座に返す if (plcMemoryInfo.ConstantValue != null) { return(new PlcMemoryValue(plcMemoryInfo, plcMemoryInfo.ConstantValue)); } Object value; // Offset/Length のCache情報への置換 var readCache = StandardizeAccess(plcMemoryInfo); // 対象Cacheの取得 var targetCache = Caches.First(w => w.WithinValue(readCache.ReadOffset)); // 対象値の取得 var beginOffset = (int)(readCache.ReadOffset - targetCache.ReadOffset); var chacedValues = targetCache.Values.Skip(beginOffset).Take((int)readCache.Length); switch (plcMemoryInfo.AccessSize) { case AccessSize.BIT: value = ((BitPlace)chacedValues.FirstOrDefault() & plcMemoryInfo.BitPlace) != BitPlace.NOBIT; break; case AccessSize.WORD: var valueWord = BitConverter.GetBytes(chacedValues.FirstOrDefault()); value = new Byte[2] { valueWord[1], valueWord[0] }; break; case AccessSize.WORD2SmallInt: value = chacedValues.FirstOrDefault(); //value = (UInt16) (((valueWord & 0xFF00) >> 8) | ((valueWord & 0x00FF) << 8)); break; case AccessSize.BYTE: value = (Byte)(chacedValues.FirstOrDefault()); break; case AccessSize.DWORD: var values = chacedValues.Select(s => BitConverter.GetBytes(s)).ToArray(); value = new Byte[4] { values[1][1], values[1][0], values[0][1], values[0][0] }; break; default: value = null; break; } return(new PlcMemoryValue(plcMemoryInfo, value)); }
public void SetCurrentCacheById(int id) { CurrentCache = Caches.First(c => c.Id == id); }