Some progress on Easytherm communication.
This commit is contained in:
parent
9ff58c9e0b
commit
dc2b945230
@ -265,7 +265,7 @@ namespace DeviceTest
|
|||||||
{
|
{
|
||||||
radioButton1.Text = "SetTemperature(10)";
|
radioButton1.Text = "SetTemperature(10)";
|
||||||
radioButton2.Text = "SetTemperature(20)";
|
radioButton2.Text = "SetTemperature(20)";
|
||||||
radioButton3.Text = "SetTemperature(30)";
|
radioButton3.Text = "GetSomethig(0,1)";
|
||||||
}
|
}
|
||||||
else if (className == "Modbus.TankSelector")
|
else if (className == "Modbus.TankSelector")
|
||||||
{
|
{
|
||||||
@ -286,7 +286,7 @@ namespace DeviceTest
|
|||||||
{
|
{
|
||||||
radioButton21.Text = "SetTemperature(10)";
|
radioButton21.Text = "SetTemperature(10)";
|
||||||
radioButton22.Text = "SetTemperature(20)";
|
radioButton22.Text = "SetTemperature(20)";
|
||||||
radioButton23.Text = "SetTemperature(30)";
|
radioButton23.Text = "GetSomethig(0,1)";
|
||||||
}
|
}
|
||||||
else if (className == "Modbus.TankSelector")
|
else if (className == "Modbus.TankSelector")
|
||||||
{
|
{
|
||||||
@ -307,7 +307,7 @@ namespace DeviceTest
|
|||||||
{
|
{
|
||||||
radioButton31.Text = "SetTemperature(10)";
|
radioButton31.Text = "SetTemperature(10)";
|
||||||
radioButton32.Text = "SetTemperature(20)";
|
radioButton32.Text = "SetTemperature(20)";
|
||||||
radioButton33.Text = "SetTemperature(30)";
|
radioButton33.Text = "GetSomethig(0,1)";
|
||||||
}
|
}
|
||||||
else if (className == "Modbus.TankSelector")
|
else if (className == "Modbus.TankSelector")
|
||||||
{
|
{
|
||||||
@ -659,7 +659,7 @@ namespace DeviceTest
|
|||||||
{
|
{
|
||||||
operation1 = (tbfComponent1forOp as TBF.BenchControl.Modbus.Easytherm.Easytherm).SetTemperatureOp(10);
|
operation1 = (tbfComponent1forOp as TBF.BenchControl.Modbus.Easytherm.Easytherm).SetTemperatureOp(10);
|
||||||
operation2 = (tbfComponent1forOp as TBF.BenchControl.Modbus.Easytherm.Easytherm).SetTemperatureOp(20);
|
operation2 = (tbfComponent1forOp as TBF.BenchControl.Modbus.Easytherm.Easytherm).SetTemperatureOp(20);
|
||||||
operation3 = (tbfComponent1forOp as TBF.BenchControl.Modbus.Easytherm.Easytherm).SetTemperatureOp(30);
|
operation3 = (tbfComponent1forOp as TBF.BenchControl.Modbus.Easytherm.Easytherm).ReadTemperatureOp();
|
||||||
}
|
}
|
||||||
else if (tbfComponent1forOp is TBF.BenchControl.Modbus.TankSelector.TankSelector)
|
else if (tbfComponent1forOp is TBF.BenchControl.Modbus.TankSelector.TankSelector)
|
||||||
{
|
{
|
||||||
@ -687,7 +687,7 @@ namespace DeviceTest
|
|||||||
{
|
{
|
||||||
operation21 = (tbfComponent1forOp as TBF.BenchControl.Modbus.Easytherm.Easytherm).SetTemperatureOp(10);
|
operation21 = (tbfComponent1forOp as TBF.BenchControl.Modbus.Easytherm.Easytherm).SetTemperatureOp(10);
|
||||||
operation22 = (tbfComponent1forOp as TBF.BenchControl.Modbus.Easytherm.Easytherm).SetTemperatureOp(20);
|
operation22 = (tbfComponent1forOp as TBF.BenchControl.Modbus.Easytherm.Easytherm).SetTemperatureOp(20);
|
||||||
operation23 = (tbfComponent1forOp as TBF.BenchControl.Modbus.Easytherm.Easytherm).SetTemperatureOp(30);
|
operation23 = (tbfComponent1forOp as TBF.BenchControl.Modbus.Easytherm.Easytherm).ReadTemperatureOp();
|
||||||
}
|
}
|
||||||
else if (tbfComponent2forOp is TBF.BenchControl.Modbus.TankSelector.TankSelector)
|
else if (tbfComponent2forOp is TBF.BenchControl.Modbus.TankSelector.TankSelector)
|
||||||
{
|
{
|
||||||
@ -715,7 +715,7 @@ namespace DeviceTest
|
|||||||
{
|
{
|
||||||
operation31 = (tbfComponent1forOp as TBF.BenchControl.Modbus.Easytherm.Easytherm).SetTemperatureOp(10);
|
operation31 = (tbfComponent1forOp as TBF.BenchControl.Modbus.Easytherm.Easytherm).SetTemperatureOp(10);
|
||||||
operation32 = (tbfComponent1forOp as TBF.BenchControl.Modbus.Easytherm.Easytherm).SetTemperatureOp(20);
|
operation32 = (tbfComponent1forOp as TBF.BenchControl.Modbus.Easytherm.Easytherm).SetTemperatureOp(20);
|
||||||
operation33 = (tbfComponent1forOp as TBF.BenchControl.Modbus.Easytherm.Easytherm).SetTemperatureOp(30);
|
operation33 = (tbfComponent1forOp as TBF.BenchControl.Modbus.Easytherm.Easytherm).ReadTemperatureOp();
|
||||||
}
|
}
|
||||||
else if (tbfComponent3forOp is TBF.BenchControl.Modbus.TankSelector.TankSelector)
|
else if (tbfComponent3forOp is TBF.BenchControl.Modbus.TankSelector.TankSelector)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -16,6 +16,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ResultsBrowser", "ResultsBr
|
|||||||
EndProjectSection
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DeviceTest", "DeviceTest\DeviceTest.csproj", "{6D3384DC-4638-4A92-91A8-F39D900377C6}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DeviceTest", "DeviceTest\DeviceTest.csproj", "{6D3384DC-4638-4A92-91A8-F39D900377C6}"
|
||||||
|
ProjectSection(ProjectDependencies) = postProject
|
||||||
|
{439D0878-C76E-452B-B17D-209A89E91D36} = {439D0878-C76E-452B-B17D-209A89E91D36}
|
||||||
|
{9D0DCC88-DC81-47EB-9FDD-4C3907871BFB} = {9D0DCC88-DC81-47EB-9FDD-4C3907871BFB}
|
||||||
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dirichlet.Numerics", "Dirichlet.Numerics\Dirichlet.Numerics.csproj", "{439D0878-C76E-452B-B17D-209A89E91D36}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dirichlet.Numerics", "Dirichlet.Numerics\Dirichlet.Numerics.csproj", "{439D0878-C76E-452B-B17D-209A89E91D36}"
|
||||||
EndProject
|
EndProject
|
||||||
|
|||||||
@ -128,8 +128,9 @@ namespace TBF.BenchControl.Modbus.Common
|
|||||||
|
|
||||||
serialPort.Write(message, 0, message.Length);
|
serialPort.Write(message, 0, message.Length);
|
||||||
|
|
||||||
Debug.WriteLine(Telegram.LogTelegram("Sending message ", message));
|
string s = Telegram.LogTelegram("Sending message ", message);
|
||||||
log.Debug(Telegram.LogTelegram("Sending message ", message));
|
Debug.WriteLine(s);
|
||||||
|
log.Debug(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -143,19 +144,22 @@ namespace TBF.BenchControl.Modbus.Common
|
|||||||
{
|
{
|
||||||
byte[] buffer = new byte[nrBytes];
|
byte[] buffer = new byte[nrBytes];
|
||||||
serialPort.Read(buffer, 0, nrBytes);
|
serialPort.Read(buffer, 0, nrBytes);
|
||||||
string s = Telegram.LogTelegram("Received: ", buffer);
|
|
||||||
Debug.WriteLine(s);
|
|
||||||
|
|
||||||
if (nrBytes >=3)
|
int deviceAddress = (nrBytes >= 1) ? buffer[0] : 0;
|
||||||
|
int function = (nrBytes >= 2) ? buffer[1] : 0;
|
||||||
|
|
||||||
|
if ((nrBytes >= 4) && Telegram.VerifyTelegramCRC(buffer))
|
||||||
{
|
{
|
||||||
int deviceAddress = buffer[0];
|
receivedTelegrams[deviceAddress].Enqueue(buffer);
|
||||||
int function = buffer[1];
|
string s = string.Format("{0} address={1} count={2}", Telegram.LogTelegram("Telegram received: ", buffer), deviceAddress, receivedTelegrams[deviceAddress].Count);
|
||||||
int bytesCount = buffer[2];
|
Debug.WriteLine(s);
|
||||||
if (nrBytes == bytesCount + 5 && Telegram.VerifyTelegramCRC(buffer))
|
log.Debug(s);
|
||||||
{
|
}
|
||||||
receivedTelegrams[deviceAddress].Enqueue(buffer);
|
else
|
||||||
Debug.WriteLine("Valid telegram received: ReceivedTelegrams[{0}].Count = {1}", deviceAddress, receivedTelegrams[deviceAddress].Count);
|
{
|
||||||
}
|
string s = Telegram.LogTelegram("Invalid data received ", buffer);
|
||||||
|
Debug.WriteLine(s);
|
||||||
|
log.Debug(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -58,26 +58,48 @@ namespace TBF.BenchControl.Modbus.Easytherm
|
|||||||
/// Set outputs of QuidoRS board
|
/// Set outputs of QuidoRS board
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="temperature">output value</param>
|
/// <param name="temperature">output value</param>
|
||||||
public void SetTemperature(ushort temperature)
|
public void SetTemperature(float temperature)
|
||||||
{
|
{
|
||||||
temperatureSetpoint = temperature;
|
if (temperature < 0 || temperature > 100) return; /// temperature out of range
|
||||||
SendTemperature(temperatureSetpoint);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SendTemperature(ushort temperatureSetpoint)
|
ushort temperatureSetpoint = (ushort)(100 * temperature);
|
||||||
{
|
ushort destAddress = (ushort)2;
|
||||||
byte[] msg = new byte[8];
|
|
||||||
|
byte[] msg = new byte[8];
|
||||||
|
|
||||||
msg[0] = easythermCfg.ModbusAddress;
|
msg[0] = easythermCfg.ModbusAddress;
|
||||||
msg[1] = (byte)Function.PresetSingleRegister;
|
msg[1] = (byte)Function.PresetSingleRegister;
|
||||||
msg[2] = 0; /// Relative address Hi
|
msg[2] = (byte)(destAddress >> 8); /// Relative address Hi
|
||||||
msg[3] = 2; /// Relative address Lo
|
msg[3] = (byte)(destAddress & 0xFF); /// Relative address Lo
|
||||||
msg[4] = (byte)(temperatureSetpoint >> 8); /// Output data Hi
|
msg[4] = (byte)(temperatureSetpoint >> 8); /// Output data Hi
|
||||||
msg[5] = (byte)(temperatureSetpoint & 0xFF); /// Output data Lo
|
msg[5] = (byte)(temperatureSetpoint & 0xFF); /// Output data Lo
|
||||||
|
|
||||||
modbus.SendMessage(msg);
|
modbus.SendMessage(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Set outputs of QuidoRS board
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="temperature">output value</param>
|
||||||
|
public void GetSomething(ushort address, int len)
|
||||||
|
{
|
||||||
|
ReadSomething(address, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ReadSomething(ushort address, int len)
|
||||||
|
{
|
||||||
|
byte[] msg = new byte[8];
|
||||||
|
|
||||||
|
msg[0] = easythermCfg.ModbusAddress;
|
||||||
|
msg[1] = (byte)Function.ReadInputRegister;
|
||||||
|
msg[2] = (byte)(address >> 8); /// Relative address Hi
|
||||||
|
msg[3] = (byte)(address & 0xFF); /// Relative address Lo
|
||||||
|
msg[4] = (byte)((len >> 8) & 0xFF); /// Data length Hi
|
||||||
|
msg[5] = (byte)(len & 0xFF); /// Data length Lo
|
||||||
|
|
||||||
|
modbus.SendMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Events: SetOpututsDone, Error
|
/// Events: SetOpututsDone, Error
|
||||||
@ -95,9 +117,9 @@ namespace TBF.BenchControl.Modbus.Easytherm
|
|||||||
/// <param name="outValue">Reference to a variable for the pressure in Bar</param>
|
/// <param name="outValue">Reference to a variable for the pressure in Bar</param>
|
||||||
/// <param name="setOutputsDone">Event returned when SetOutput is done</param>
|
/// <param name="setOutputsDone">Event returned when SetOutput is done</param>
|
||||||
/// <returns>SetOutputsOp instance reference casted to IOperaton</returns>
|
/// <returns>SetOutputsOp instance reference casted to IOperaton</returns>
|
||||||
public IOperation ReadTemperatureOp(ushort outValue, Event setOutputsDone)
|
public IOperation ReadTemperatureOp()
|
||||||
{
|
{
|
||||||
return new ReadTemperatureOp(this, outValue, setOutputsDone);
|
return new ReadTemperatureOp(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,24 +23,25 @@ namespace TBF.BenchControl.Modbus.Easytherm
|
|||||||
/// <param name="easytherm">Pressure meter reference</param>
|
/// <param name="easytherm">Pressure meter reference</param>
|
||||||
/// <param name="pressure">Reference to the measured pressure variable, value is in bar</param>
|
/// <param name="pressure">Reference to the measured pressure variable, value is in bar</param>
|
||||||
/// <param name="eventDone">Event to be returned by Run() when completed OK</param>
|
/// <param name="eventDone">Event to be returned by Run() when completed OK</param>
|
||||||
public ReadTemperatureOp(Easytherm easytherm, ushort outValue, Event eventDone)
|
public ReadTemperatureOp(Easytherm easytherm, Event eventDone)
|
||||||
{
|
{
|
||||||
if (easytherm == null) throw new ArgumentNullException("easytherm");
|
if (easytherm == null) throw new ArgumentNullException("easytherm");
|
||||||
this.easytherm = easytherm;
|
this.easytherm = easytherm;
|
||||||
this.outValue = outValue;
|
//this.outValue = outValue;
|
||||||
this.eventDone = eventDone;
|
this.eventDone = eventDone;
|
||||||
|
|
||||||
log.Debug(this.ToString());
|
log.Debug(this.ToString());
|
||||||
}
|
}
|
||||||
public ReadTemperatureOp(Easytherm easytherm, ushort outValue)
|
public ReadTemperatureOp(Easytherm easytherm)
|
||||||
: this(easytherm, outValue, Event.SetOutputsDone)
|
: this(easytherm, Event.Done)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Start this operation</summary>
|
/// <summary>Start this operation</summary>
|
||||||
public void Start()
|
public void Start()
|
||||||
{
|
{
|
||||||
}
|
easytherm.GetSomething(0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>Run this operation</summary>
|
/// <summary>Run this operation</summary>
|
||||||
public Event Run()
|
public Event Run()
|
||||||
|
|||||||
@ -15,7 +15,7 @@ namespace TBF.BenchControl.Modbus.Easytherm
|
|||||||
/// Set by the constructor
|
/// Set by the constructor
|
||||||
readonly Easytherm easytherm;
|
readonly Easytherm easytherm;
|
||||||
readonly Event eventDone;
|
readonly Event eventDone;
|
||||||
ushort temperatureSetpoint;
|
float temperatureSetpoint;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Events: PressureInDone, PressureOutDone or Error
|
/// Events: PressureInDone, PressureOutDone or Error
|
||||||
@ -23,7 +23,7 @@ namespace TBF.BenchControl.Modbus.Easytherm
|
|||||||
/// <param name="easytherm">Pressure meter reference</param>
|
/// <param name="easytherm">Pressure meter reference</param>
|
||||||
/// <param name="pressure">Reference to the measured pressure variable, value is in bar</param>
|
/// <param name="pressure">Reference to the measured pressure variable, value is in bar</param>
|
||||||
/// <param name="eventDone">Event to be returned by Run() when completed OK</param>
|
/// <param name="eventDone">Event to be returned by Run() when completed OK</param>
|
||||||
public SetTemperatureOp(Easytherm easytherm, ushort temperatureSetpoint, Event eventDone)
|
public SetTemperatureOp(Easytherm easytherm, float temperatureSetpoint, Event eventDone)
|
||||||
{
|
{
|
||||||
if (easytherm == null) throw new ArgumentNullException("easytherm");
|
if (easytherm == null) throw new ArgumentNullException("easytherm");
|
||||||
this.easytherm = easytherm;
|
this.easytherm = easytherm;
|
||||||
@ -32,8 +32,8 @@ namespace TBF.BenchControl.Modbus.Easytherm
|
|||||||
|
|
||||||
log.Debug(this.ToString());
|
log.Debug(this.ToString());
|
||||||
}
|
}
|
||||||
public SetTemperatureOp(Easytherm easytherm, ushort outValue)
|
public SetTemperatureOp(Easytherm easytherm, float temperatureSetpoint)
|
||||||
: this(easytherm, outValue, Event.SetOutputsDone)
|
: this(easytherm, temperatureSetpoint, Event.SetOutputsDone)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user