public int GetOffset(DeviceAddress start, DeviceAddress end) { return(start.Area == end.Area && start.DBNumber == end.DBNumber ? start.Start - end.Start : ushort.MaxValue); }
public int WriteValue(DeviceAddress address, object value) { return(this.WriteValueEx(address, value)); }
public byte[] ReadBytes(DeviceAddress address, ushort size) { byte[] bytes = new byte[size]; Array.Copy(_cache, address.CacheIndex, bytes, 0, size); return(bytes); }
public int WriteBit(DeviceAddress address, bool bit) { _cache[address.CacheIndex] |= (byte)(1 << address.Bit); return(0); }
public int WriteBits(DeviceAddress address, byte bits) { _cache[address.CacheIndex] = bits; return(0); }
public ItemData <float> ReadFloat(DeviceAddress address) { return(new ItemData <float>(Utility.NetToSingle(_cache, address.CacheIndex), 0, QUALITIES.QUALITY_GOOD)); }
public ItemData <object> ReadValue(DeviceAddress address) { return(this.ReadValueEx(address)); }
public ItemData <string> ReadString(DeviceAddress address, ushort size = 0xFF) { return(new ItemData <string>(Utility.ConvertToString(_cache, address.CacheIndex, size), 0, QUALITIES.QUALITY_GOOD)); }
public ItemData <byte> ReadByte(DeviceAddress address) { return(new ItemData <byte>(_cache[address.CacheIndex], 0, QUALITIES.QUALITY_GOOD)); }
public ItemData <short> ReadInt16(DeviceAddress address) { return(new ItemData <short>(Utility.NetToInt16(_cache, address.CacheIndex), 0, QUALITIES.QUALITY_GOOD)); }
public ItemData <bool> ReadBit(DeviceAddress address) { return(new ItemData <bool>((_cache[address.CacheIndex] & (1 << address.Bit)) != 0, 0, QUALITIES.QUALITY_GOOD)); }
public static List <PDUArea> AssignFromPDU(this ICache cacheReader, int PDU, params DeviceAddress[] addrsArr) { List <PDUArea> rangeList = new List <PDUArea>(); int count = addrsArr.Length; if (count > 0) { //Array.Sort(addrsArr); DeviceAddress start = addrsArr[0]; start.Bit = 0; int bitCount = cacheReader.ByteCount; if (count > 1) { int cacheLength = 0;//缓冲区的大小 int cacheIndexStart = 0; int startIndex = 0; DeviceAddress segmentEnd, tagAddress; DeviceAddress segmentStart = start; for (int j = 1, i = 1; i < count; i++, j++) { tagAddress = addrsArr[i];//当前变量地址 int offset1 = cacheReader.GetOffset(tagAddress, segmentStart); if (offset1 > (PDU / cacheReader.ByteCount)) { segmentEnd = addrsArr[i - 1]; int len = cacheReader.GetOffset(segmentEnd, segmentStart); len += segmentEnd.DataSize <= bitCount ? 1 : segmentEnd.DataSize / bitCount; tagAddress.CacheIndex = (ushort)(cacheIndexStart + len); addrsArr[i] = tagAddress; rangeList.Add(new PDUArea(segmentStart, len, startIndex, j)); startIndex += j; j = 0; cacheLength += len; //更新缓存长度 cacheIndexStart = cacheLength; segmentStart = tagAddress; //更新数据片段的起始地址 } else { tagAddress.CacheIndex = (ushort)(cacheIndexStart + offset1); addrsArr[i] = tagAddress; } if (i == count - 1) { segmentEnd = addrsArr[i]; int segmentLength = cacheReader.GetOffset(segmentEnd, segmentStart); if (segmentLength > PDU / cacheReader.ByteCount) { segmentEnd = addrsArr[i - 1]; segmentLength = segmentEnd.DataSize <= bitCount ? 1 : segmentEnd.DataSize / bitCount; } tagAddress.CacheIndex = (ushort)(cacheIndexStart + segmentLength); addrsArr[i] = tagAddress; segmentLength += segmentEnd.DataSize <= bitCount ? 1 : segmentEnd.DataSize / bitCount; rangeList.Add(new PDUArea(segmentStart, segmentLength, startIndex, j + 1)); cacheLength += segmentLength; } } cacheReader.Size = cacheLength; } else { cacheReader.Size = start.DataSize <= bitCount ? 1 : start.DataSize / bitCount;//改变Cache的Size属性值将创建Cache的内存区域 } } return(rangeList); }