public void DataPointScaling(float engHi, float engLow, float rawHi, float rawLow) { Debug.Print("Enter {0}:DataPointScaling", GetType()); Debug.Indent(); ValuePostGetAction = value => (((value - rawLow) * (engHi - engLow)) / (rawHi - rawLow)) + engLow; ValuePreSetAction = value => (((value - engLow) * (rawHi - rawLow)) / (engHi - engLow)) + rawLow; Debug.Unindent(); Debug.Print("Exit {0}:DataPointScaling", GetType()); }
public IPLCDataPoint AddDataPoint(string point, PostGetValue postGetAction = null, PreSetValue preSetAction = null) { Debug.Print("Enter {0}:AddDataPoint", GetType()); if (point == null) { throw new ArgumentNullException("point"); } // Look for duplicate point in list var existingDataPoint = dataPointList.GetPLCDataPoint(point); // IDEA: Verify that Points are equal if (existingDataPoint != null) { Debug.Print("Symbol found in list returning item"); Debug.Unindent(); Debug.Print("Exit {0}:AddDataPoint", GetType()); return(existingDataPoint); } PLCDataPoint dataPoint; if (point.Trim(' ').Contains(" ")) { Debug.Print("Address Detected"); string dataType = ""; switch (point.Substring(1, 1)) { case "D": { dataType = "DWORD"; break; } case "W": { dataType = "WORD"; break; } case "B": { dataType = "BYTE"; break; } default: { if (point.Contains(".")) { dataType = "BOOL"; } break; } } dataPoint = new PLCDataPoint { Address = point, Symbol = point, DataType = dataType }; } else { Debug.Print("Symbol Detected"); try { dataPoint = (PLCDataPoint)Project.PCS7SymbolTable.GetEntryFromSymbol(point); } catch (NullReferenceException e) { throw new ApplicationException("PCS7Project is not intialized ", e); } } if (dataPoint == null) { throw new NoNullAllowedException(string.Format("Null Returned from PCS7Project Call for point {0}", point)); } GetValue getAction = offset => 0; SetValue setAction = (offset, value) => { }; switch (dataPoint.DataType.ToUpper()) { case "WORD": getAction = item => outputImageBuffer.ToBEInt16(item.Offset); setAction = (item, val) => dataPointList.WriteDataPoints.Push(new WritePLCDataBytes(item.Offset, BigEndianBitConverter.GetBytes((Int16)val))); break; case "DWORD": getAction = item => outputImageBuffer.ToBEInt32(item.Offset); setAction = (item, val) => dataPointList.WriteDataPoints.Push(new WritePLCDataBytes(item.Offset, BigEndianBitConverter.GetBytes((int)val))); break; case "REAL": getAction = item => outputImageBuffer.ToBESingle(item.Offset); setAction = (item, val) => dataPointList.WriteDataPoints.Push(new WritePLCDataBytes(item.Offset, BigEndianBitConverter.GetBytes((float)val))); break; case "BYTE": getAction = item => outputImageBuffer.ToBEByte(item.Offset); setAction = (item, val) => dataPointList.WriteDataPoints.Push(new WritePLCDataBytes(item.Offset, BigEndianBitConverter.GetBytes((byte)val))); break; case "BOOL": getAction = item => { byte by = outputImageBuffer.ToBEByte(item.Offset); byte bit = (byte)((by >> item.Bit) & 0x01); return(bit); }; setAction = (item, val) => dataPointList.WriteDataBits.Push(new WritePLCDataBits(item.Offset, item.Bit, Convert.ToBoolean(val))); break; default: Trace.TraceWarning("Unknown data type for point {1] unable to register read write actions {0}", dataPoint.DataType, point); break; } switch (dataPoint.Address.Trim().ToUpper().First()) { case 'Q': dataPoint.ValueGetAction = getAction; break; case 'I': dataPoint.ValueSetAction = setAction; break; default: dataPoint.ValueGetAction = getAction; dataPoint.ValueSetAction = setAction; break; } if (postGetAction != null) { dataPoint.ValuePostGetAction = postGetAction; } if (preSetAction != null) { dataPoint.ValuePreSetAction = preSetAction; } dataPointList.Add(dataPoint); UpdateImages(); Debug.Unindent(); Debug.Print("Exit {0}:AddDataPoint", GetType()); return(dataPoint); }
public PLCDataPoint() { ValuePostGetAction = value => value; ValuePreSetAction = value => value; }
public IPLCDataPoint AddDataPoint(string point, PostGetValue postGetAction = null, PreSetValue preSetAction = null) { Debug.Print("Enter {0}:AddDataPoint", GetType()); if (point == null) throw new ArgumentNullException("point"); // Look for duplicate point in list var existingDataPoint = dataPointList.GetPLCDataPoint(point); // IDEA: Verify that Points are equal if (existingDataPoint != null) { Debug.Print("Symbol found in list returning item"); Debug.Unindent(); Debug.Print("Exit {0}:AddDataPoint", GetType()); return existingDataPoint; } PLCDataPoint dataPoint; if (point.Trim(' ').Contains(" ")) { Debug.Print("Address Detected"); string dataType = ""; switch (point.Substring(1,1)) { case "D": { dataType = "DWORD"; break; } case "W": { dataType = "WORD"; break; } case "B": { dataType = "BYTE"; break; } default: { if (point.Contains(".")) dataType = "BOOL"; break; } } dataPoint = new PLCDataPoint { Address = point, Symbol = point, DataType = dataType }; } else { Debug.Print("Symbol Detected"); try { dataPoint = (PLCDataPoint)Project.PCS7SymbolTable.GetEntryFromSymbol(point); } catch (NullReferenceException e) { throw new ApplicationException("PCS7Project is not intialized ", e); } } if (dataPoint == null) throw new NoNullAllowedException(string.Format("Null Returned from PCS7Project Call for point {0}", point)); GetValue getAction = offset => 0; SetValue setAction = (offset, value) => { }; switch(dataPoint.DataType.ToUpper()) { case "WORD": getAction = item => outputImageBuffer.ToBEInt16(item.Offset); setAction = (item, val) => dataPointList.WriteDataPoints.Push(new WritePLCDataBytes(item.Offset, BigEndianBitConverter.GetBytes((Int16)val))); break; case "DWORD": getAction = item => outputImageBuffer.ToBEInt32(item.Offset); setAction = (item,val) => dataPointList.WriteDataPoints.Push(new WritePLCDataBytes(item.Offset, BigEndianBitConverter.GetBytes((int)val))); break; case "REAL": getAction = item => outputImageBuffer.ToBESingle(item.Offset); setAction = (item, val) => dataPointList.WriteDataPoints.Push(new WritePLCDataBytes(item.Offset, BigEndianBitConverter.GetBytes((float)val))); break; case "BYTE": getAction = item => outputImageBuffer.ToBEByte(item.Offset); setAction = (item, val) => dataPointList.WriteDataPoints.Push(new WritePLCDataBytes(item.Offset, BigEndianBitConverter.GetBytes((byte)val))); break; case "BOOL": getAction = item => { byte by = outputImageBuffer.ToBEByte(item.Offset); byte bit = (byte)((by >> item.Bit) & 0x01); return bit; }; setAction = (item, val) => dataPointList.WriteDataBits.Push(new WritePLCDataBits(item.Offset, item.Bit, Convert.ToBoolean(val))); break; default: Trace.TraceWarning("Unknown data type for point {1] unable to register read write actions {0}", dataPoint.DataType, point ); break; } switch (dataPoint.Address.Trim().ToUpper().First()) { case 'Q': dataPoint.ValueGetAction = getAction; break; case 'I': dataPoint.ValueSetAction = setAction; break; default: dataPoint.ValueGetAction = getAction; dataPoint.ValueSetAction = setAction; break; } if (postGetAction != null) dataPoint.ValuePostGetAction = postGetAction; if (preSetAction != null) dataPoint.ValuePreSetAction = preSetAction; dataPointList.Add(dataPoint); UpdateImages(); Debug.Unindent(); Debug.Print("Exit {0}:AddDataPoint", GetType()); return dataPoint; }