SchematicDrawing.IDrawingItCmpntWithCustomBmp and several bitmaps added, ver. 3.1.1886
This commit is contained in:
@@ -3,25 +3,29 @@
|
||||
///
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using log4net;
|
||||
using Common;
|
||||
using Config.Entities;
|
||||
using SchematicDrawing;
|
||||
using TBF.Rig.Generic;
|
||||
using TBF.Boxes;
|
||||
using TBF.Rig.Generic;
|
||||
|
||||
namespace TBF.Rig.Modbus.TempControl.Novus
|
||||
{
|
||||
public class TControl : ComponentBase, IDevice, ITempControl, IDrawingItCmpntWithSetpoint, IDrawingItCmpntWithMeasuredVal
|
||||
public class TControl : ComponentBase, IDevice, ITempControl, IDrawingItCmpntWithSetpoint,
|
||||
IDrawingItCmpntWithMeasuredVal, IDrawingItCmpntWithCustomBmp
|
||||
{
|
||||
private static readonly ILog log = LogManager.GetLogger(typeof(TControl));
|
||||
public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); }
|
||||
|
||||
const UInt16 SetpointAddress = 0; /// Temperature setpoint
|
||||
const UInt16 ProcessValueAddress = 1; /// Actual temperature
|
||||
const UInt16 StatusWord1 = 6; /// Status word 1
|
||||
const UInt16 StatusWord2 = 9; /// Status word 2
|
||||
const UInt16 StatusWord3 = 10; /// Status word 3
|
||||
const UInt16 SetpointAddress = 0; /// Temperature setpoint address
|
||||
const UInt16 ProcessValueAddress = 1; /// Actual temperature address
|
||||
const UInt16 Status1Address = 6; /// Status word 1 address
|
||||
const UInt16 FWVersionAddress = 7; /// Firmware version address
|
||||
const UInt16 ControllerIdAddress = 8; /// Controller ID address
|
||||
const UInt16 Status2Address = 9; /// Status word 2 address
|
||||
const UInt16 Status3Address = 10; /// Status word 3 address
|
||||
|
||||
readonly TControlCfg novusCfg;
|
||||
public IDrawingItem DrawingItem { get { return novusCfg as IDrawingItem; } }
|
||||
@@ -51,17 +55,44 @@ namespace TBF.Rig.Modbus.TempControl.Novus
|
||||
if (temperatureSetPoint <= 5) temperatureSetPoint = 5;
|
||||
}
|
||||
|
||||
|
||||
public DrawingShape GetCustomBitmap()
|
||||
{
|
||||
switch (novusCfg.Sz)
|
||||
{
|
||||
case Sz.S:
|
||||
return isHeating ? (isCooling ? TControlCfg.DSBothS : TControlCfg.DSHeatingS)
|
||||
: (isCooling ? TControlCfg.DSCoolingS : TControlCfg.DSIdleS);
|
||||
case Sz.M:
|
||||
return isHeating ? (isCooling ? TControlCfg.DSBothM : TControlCfg.DSHeatingM)
|
||||
: (isCooling ? TControlCfg.DSCoolingM : TControlCfg.DSIdleM);
|
||||
default:
|
||||
case Sz.L:
|
||||
return isHeating ? (isCooling ? TControlCfg.DSBothL : TControlCfg.DSHeatingL)
|
||||
: (isCooling ? TControlCfg.DSCoolingL : TControlCfg.DSIdleL);
|
||||
case Sz.XL:
|
||||
return isHeating ? (isCooling ? TControlCfg.DSBothXL : TControlCfg.DSHeatingXL)
|
||||
: (isCooling ? TControlCfg.DSCoolingXL : TControlCfg.DSIdleXL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool novusDataValid;
|
||||
double temperatureSetPoint;
|
||||
double actualTemperature;
|
||||
bool temperatureSetPointValid { get { return novusDataValid; } }
|
||||
bool temperatureSetPointRequested;
|
||||
|
||||
Int16 status1;
|
||||
Int16 status2;
|
||||
Int16 status3;
|
||||
Int16 fwVersion;
|
||||
Int16 controllerId;
|
||||
double temperatureSetPoint;
|
||||
double actualTemperature;
|
||||
|
||||
bool temperatureSetPointValid;
|
||||
bool temperatureSetPointRequested;
|
||||
bool isInvOutput { get { return (status2 & (1 << 2)) != 0; } }
|
||||
bool isHeating { get { return isInvOutput ? ((status2 & (1 << 11)) == 0) : ((status2 & (1 << 11)) != 0); } } /// Output 1
|
||||
bool isCooling { get { return isInvOutput ? ((status2 & (1 << 12)) == 0) : ((status2 & (1 << 12)) != 0); } } /// Output 2
|
||||
bool isFahrenheit { get { return (status2 & (1 << 9)) != 0; } }
|
||||
|
||||
|
||||
public float requiredTemp
|
||||
@@ -73,9 +104,6 @@ namespace TBF.Rig.Modbus.TempControl.Novus
|
||||
}
|
||||
|
||||
|
||||
bool heating;
|
||||
bool cooling;
|
||||
|
||||
|
||||
public TControl() { }
|
||||
|
||||
@@ -83,17 +111,18 @@ namespace TBF.Rig.Modbus.TempControl.Novus
|
||||
: base(cfg)
|
||||
{
|
||||
novusCfg = cfg as TControlCfg;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Initialize this device</summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
temperatureSetPointValid = false;
|
||||
temperatureSetPointRequested = false;
|
||||
{
|
||||
novusDataValid = false;
|
||||
temperatureSetPointRequested = false;
|
||||
|
||||
if (novusCfg.DebugLevel == DebugMode.Simulate)
|
||||
{
|
||||
actualTemperature = 22;
|
||||
temperatureSetPoint = 18;
|
||||
log.FatalFormat("{0} simulated: {1}", Name, this);
|
||||
}
|
||||
else
|
||||
@@ -131,13 +160,17 @@ namespace TBF.Rig.Modbus.TempControl.Novus
|
||||
- ((telegram[2 * i + 3] & 0x80) != 0 ? 65536 : 0));
|
||||
}
|
||||
|
||||
temperatureSetPoint = (double)values[0] * 0.1; /// setpoint in 0.1 °C
|
||||
actualTemperature = (double)values[1] * 0.1; /// temperature in 0.1 °C
|
||||
status1 = values[6];
|
||||
fwVersion = values[7];
|
||||
controllerId = values[8];
|
||||
status2 = values[9];
|
||||
status3 = values[10];
|
||||
status1 = values[Status1Address];
|
||||
status2 = values[Status2Address];
|
||||
status3 = values[Status3Address];
|
||||
fwVersion = values[FWVersionAddress];
|
||||
controllerId = values[ControllerIdAddress];
|
||||
|
||||
double setpointCorF = (double)values[SetpointAddress] * 0.1;
|
||||
temperatureSetPoint = isFahrenheit ? Units.ConvertFrom(Unit.F, setpointCorF) : setpointCorF;
|
||||
|
||||
double temperatureCorF = (double)values[ProcessValueAddress] * 0.1;
|
||||
actualTemperature = isFahrenheit ? Units.ConvertFrom(Unit.F, temperatureCorF) : temperatureCorF;
|
||||
|
||||
novusDataValid = true;
|
||||
|
||||
@@ -151,10 +184,17 @@ namespace TBF.Rig.Modbus.TempControl.Novus
|
||||
log.InfoFormat("[{0}] received soemthing else", Name);
|
||||
}
|
||||
}
|
||||
else if (novusCfg.DebugLevel == DebugMode.Simulate)
|
||||
{
|
||||
switch ((StateMachine.Time / 3) % 3)
|
||||
{
|
||||
case 0: status2 = 0; break;
|
||||
case 1: status2 = 1 << 11; break;
|
||||
case 2: status2 = 1 << 12; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const int Modulo = 2;
|
||||
|
||||
/// <summary>Run this device</summary>
|
||||
public void RunDeviceAfter()
|
||||
{
|
||||
@@ -192,47 +232,33 @@ namespace TBF.Rig.Modbus.TempControl.Novus
|
||||
/// <summary>
|
||||
/// Set Easytherm controller to specified temperature
|
||||
/// </summary>
|
||||
/// <param name="reqTemp">Temperature in °C</param>
|
||||
/// <param name="reqTempC">Temperature in °C</param>
|
||||
/// <returns>true = OK, false = any error</returns>
|
||||
public bool SetTemperatureSetpoint(float reqTemp)
|
||||
public bool SetTemperatureSetpoint(double reqTempC)
|
||||
{
|
||||
if (reqTemp != 0 && (reqTemp < 5 || reqTemp > 95.0f))
|
||||
if (reqTempC != 0 && (reqTempC < 5.0 || reqTempC > 95.0))
|
||||
{
|
||||
return false; /// required temperature out of range
|
||||
}
|
||||
|
||||
if (novusDataValid && (reqTemp == temperatureSetPoint))
|
||||
if (novusDataValid && (reqTempC == temperatureSetPoint))
|
||||
{
|
||||
return true; /// already set to the required temperature
|
||||
}
|
||||
|
||||
if (reqTemp != 0) /// temperature==0 disables sending the setpoint
|
||||
if (reqTempC != 0) /// temperature==0 disables sending the setpoint
|
||||
{
|
||||
Int16 usTempSetpoint = Convert.ToInt16(Math.Round(10 * reqTemp)); /// setpoint in 0.1 °C
|
||||
double reqTemp = isFahrenheit ? Units.ConvertTo(Unit.F, reqTempC) : reqTempC;
|
||||
Int16 tempSetpointInt16 = Convert.ToInt16(Math.Round(10 * reqTemp)); /// setpoint in 0.1 °C or °F
|
||||
ushort destAddress = SetpointAddress;
|
||||
///
|
||||
SendValueToNovus(Function.PresetSingleRegister, destAddress, usTempSetpoint);
|
||||
SendValueToNovus(Function.PresetSingleRegister, destAddress, tempSetpointInt16);
|
||||
}
|
||||
|
||||
temperatureSetPoint = reqTemp;
|
||||
temperatureSetPointValid = true;
|
||||
temperatureSetPoint = reqTempC;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void RequestTemperatureSetpoint()
|
||||
{
|
||||
SendValueToNovus(Function.ReadHoldingRegisters, SetpointAddress, 1); /// rel.address=2, 1 word
|
||||
}
|
||||
|
||||
public void RequestActualTemperature()
|
||||
{
|
||||
SendValueToNovus(Function.ReadInputRegister, ProcessValueAddress, 1); /// rel.address=x, 1 word
|
||||
}
|
||||
|
||||
public void RequestAll()
|
||||
{
|
||||
SendValueToNovus(Function.ReadInputRegister, 0, 2); /// Registers: Setpoint=0, ProcessValue=1, Status1=6, Status2=9, Status3=10
|
||||
}
|
||||
|
||||
void SendValueToNovus(Function function, UInt16 address, Int16 value)
|
||||
{
|
||||
|
||||
@@ -13,7 +13,7 @@ using TBF.Rig.Generic;
|
||||
namespace TBF.Rig.Modbus.TempControl.Novus
|
||||
{
|
||||
public class TControlCfg : ComponentCfgBase, IChildComponentCfg, IParamsProvider,
|
||||
IDrawingItemWithSetpoint, IDrawingItemWithMeasuredVal
|
||||
IDrawingItemWithSetpoint, IDrawingItemWithMeasuredVal, IDrawingItemWithCustomBmp
|
||||
{
|
||||
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(TControlCfg) })[0];
|
||||
public override XmlSerializer GetSerializer() { return Serializer; }
|
||||
@@ -77,7 +77,7 @@ namespace TBF.Rig.Modbus.TempControl.Novus
|
||||
|
||||
Name = "Novus";
|
||||
ParentName = "Modbus";
|
||||
Shape = Shape.TempControl;
|
||||
Shape = Shape.Custom;
|
||||
Sz = Sz.M;
|
||||
MsrdValLimLo = 5;
|
||||
MsrdValLimHi = 95;
|
||||
@@ -214,5 +214,41 @@ namespace TBF.Rig.Modbus.TempControl.Novus
|
||||
{
|
||||
return true; /// =OK, do nothing
|
||||
}
|
||||
|
||||
///
|
||||
/// SchematicDrawing support
|
||||
///
|
||||
public DrawingShape GetSampleBitmap()
|
||||
{
|
||||
return (Sz == Sz.S) ? DSCoolingS : (Sz == Sz.M) ? DSCoolingM : (Sz == Sz.XL) ? DSCoolingXL : DSCoolingL;
|
||||
}
|
||||
|
||||
///
|
||||
/// Static part, DrawingShape constructor arguments depend on bitmap properties
|
||||
///
|
||||
public static DrawingShape DSIdleS, DSHeatingS, DSCoolingS, DSBothS;
|
||||
public static DrawingShape DSIdleM, DSHeatingM, DSCoolingM, DSBothM;
|
||||
public static DrawingShape DSIdleL, DSHeatingL, DSCoolingL, DSBothL;
|
||||
public static DrawingShape DSIdleXL, DSHeatingXL, DSCoolingXL, DSBothXL;
|
||||
///
|
||||
static TControlCfg()
|
||||
{
|
||||
DSIdleS = new DrawingShape(Shape.Custom, Sz.S, 2, 2, null, null, 0, 0, 20, 20, Properties.Resources.TControl_S_idle);
|
||||
DSHeatingS = new DrawingShape(Shape.Custom, Sz.S, 2, 2, null, null, 0, 0, 20, 20, Properties.Resources.TControl_S_heating);
|
||||
DSCoolingS = new DrawingShape(Shape.Custom, Sz.S, 2, 2, null, null, 0, 0, 20, 20, Properties.Resources.TControl_S_cooling);
|
||||
DSBothS = new DrawingShape(Shape.Custom, Sz.S, 2, 2, null, null, 0, 0, 20, 20, Properties.Resources.TControl_S_both);
|
||||
DSIdleM = new DrawingShape(Shape.Custom, Sz.S, 3, 4, null, null, 0, 5, 30, 30, Properties.Resources.TControl_M_idle);
|
||||
DSHeatingM = new DrawingShape(Shape.Custom, Sz.S, 3, 4, null, null, 0, 5, 30, 30, Properties.Resources.TControl_M_heating);
|
||||
DSCoolingM = new DrawingShape(Shape.Custom, Sz.S, 3, 4, null, null, 0, 5, 30, 30, Properties.Resources.TControl_M_cooling);
|
||||
DSBothM = new DrawingShape(Shape.Custom, Sz.S, 3, 4, null, null, 0, 5, 30, 30, Properties.Resources.TControl_M_both);
|
||||
DSIdleL = new DrawingShape(Shape.Custom, Sz.S, 4, 4, null, null, 0, 0, 40, 40, Properties.Resources.TControl_L_idle);
|
||||
DSHeatingL = new DrawingShape(Shape.Custom, Sz.S, 4, 4, null, null, 0, 0, 40, 40, Properties.Resources.TControl_L_heating);
|
||||
DSCoolingL = new DrawingShape(Shape.Custom, Sz.S, 4, 4, null, null, 0, 0, 40, 40, Properties.Resources.TControl_L_cooling);
|
||||
DSBothL = new DrawingShape(Shape.Custom, Sz.S, 4, 4, null, null, 0, 0, 40, 40, Properties.Resources.TControl_L_both);
|
||||
DSIdleXL = new DrawingShape(Shape.Custom, Sz.S, 5, 6, null, null, 0, 5, 50, 50, Properties.Resources.TControl_XL_idle);
|
||||
DSHeatingXL = new DrawingShape(Shape.Custom, Sz.S, 5, 6, null, null, 0, 5, 50, 50, Properties.Resources.TControl_XL_heating);
|
||||
DSCoolingXL = new DrawingShape(Shape.Custom, Sz.S, 5, 6, null, null, 0, 5, 50, 50, Properties.Resources.TControl_XL_cooling);
|
||||
DSBothXL = new DrawingShape(Shape.Custom, Sz.S, 5, 6, null, null, 0, 5, 50, 50, Properties.Resources.TControl_XL_both);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user