Modbus Easytherm modifications, SetTemperature works OK, ver. 2.12.487
This commit is contained in:
@@ -34,6 +34,7 @@ namespace TBF.BenchControl.Modbus.Common
|
||||
}
|
||||
Queue<byte[]>[] receivedTelegrams;
|
||||
|
||||
|
||||
public Modbus()
|
||||
{
|
||||
}
|
||||
@@ -150,7 +151,8 @@ namespace TBF.BenchControl.Modbus.Common
|
||||
|
||||
if ((nrBytes >= 4) && Telegram.VerifyTelegramCRC(buffer))
|
||||
{
|
||||
receivedTelegrams[deviceAddress].Enqueue(buffer);
|
||||
//receivedTelegrams[deviceAddress].Enqueue(buffer);
|
||||
|
||||
string s = string.Format("{0} address={1} count={2}", Telegram.LogTelegram("Telegram received: ", buffer), deviceAddress, receivedTelegrams[deviceAddress].Count);
|
||||
Debug.WriteLine(s);
|
||||
log.Debug(s);
|
||||
|
||||
@@ -17,7 +17,8 @@ namespace TBF.BenchControl.Modbus.Easytherm
|
||||
readonly EasythermCfg easythermCfg;
|
||||
readonly GenericDevices.IModbus modbus;
|
||||
|
||||
private ushort temperatureSetpoint;
|
||||
private float temperatureSetPoint;
|
||||
private bool temperatureSetPointValid;
|
||||
|
||||
public Easytherm()
|
||||
{
|
||||
@@ -31,6 +32,8 @@ namespace TBF.BenchControl.Modbus.Easytherm
|
||||
modbus = (GenericDevices.IModbus)TbfComponents.FindComponent(cfg.ParentName, components);
|
||||
if (modbus == null) throw new Exception("Cannot find " + Name + " parent");
|
||||
|
||||
temperatureSetPointValid = false;
|
||||
|
||||
log.Debug(this.ToString());
|
||||
}
|
||||
|
||||
@@ -55,14 +58,28 @@ namespace TBF.BenchControl.Modbus.Easytherm
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set outputs of QuidoRS board
|
||||
/// Set Easytherm controller required temperature
|
||||
/// </summary>
|
||||
/// <param name="temperature">output value</param>
|
||||
public void SetTemperature(float temperature)
|
||||
/// <returns>true = OK, false = any error</returns>
|
||||
public bool SetTemperature(float temperature)
|
||||
{
|
||||
if (temperature < 0 || temperature > 100) return; /// temperature out of range
|
||||
if (temperature < 0 || temperature > 100.0f)
|
||||
{
|
||||
return false; /// required temperature out of range
|
||||
}
|
||||
|
||||
ushort temperatureSetpoint = (ushort)(100 * temperature);
|
||||
if (temperatureSetPointValid && (temperature == temperatureSetPoint))
|
||||
{
|
||||
return true; /// already set to the required temperature
|
||||
}
|
||||
|
||||
temperatureSetPoint = temperature;
|
||||
temperatureSetPointValid = true;
|
||||
|
||||
//ushort temperatureSetpoint = (ushort)temperature; // in °C
|
||||
//ushort destAddress = (ushort)1002;
|
||||
ushort temperatureSetpoint = (ushort)((10000.0f / 400.0f) * temperature); // in 0.01% of range (400 °C)
|
||||
ushort destAddress = (ushort)2;
|
||||
|
||||
byte[] msg = new byte[8];
|
||||
@@ -75,6 +92,8 @@ namespace TBF.BenchControl.Modbus.Easytherm
|
||||
msg[5] = (byte)(temperatureSetpoint & 0xFF); /// Output data Lo
|
||||
|
||||
modbus.SendMessage(msg);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user