Some progress on Easytherm communication.

This commit is contained in:
Milan Hanajik 2017-03-06 00:33:44 +01:00
parent 9ff58c9e0b
commit dc2b945230
6 changed files with 70 additions and 39 deletions

View File

@ -265,7 +265,7 @@ namespace DeviceTest
{
radioButton1.Text = "SetTemperature(10)";
radioButton2.Text = "SetTemperature(20)";
radioButton3.Text = "SetTemperature(30)";
radioButton3.Text = "GetSomethig(0,1)";
}
else if (className == "Modbus.TankSelector")
{
@ -286,7 +286,7 @@ namespace DeviceTest
{
radioButton21.Text = "SetTemperature(10)";
radioButton22.Text = "SetTemperature(20)";
radioButton23.Text = "SetTemperature(30)";
radioButton23.Text = "GetSomethig(0,1)";
}
else if (className == "Modbus.TankSelector")
{
@ -307,7 +307,7 @@ namespace DeviceTest
{
radioButton31.Text = "SetTemperature(10)";
radioButton32.Text = "SetTemperature(20)";
radioButton33.Text = "SetTemperature(30)";
radioButton33.Text = "GetSomethig(0,1)";
}
else if (className == "Modbus.TankSelector")
{
@ -659,7 +659,7 @@ namespace DeviceTest
{
operation1 = (tbfComponent1forOp as TBF.BenchControl.Modbus.Easytherm.Easytherm).SetTemperatureOp(10);
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)
{
@ -687,7 +687,7 @@ namespace DeviceTest
{
operation21 = (tbfComponent1forOp as TBF.BenchControl.Modbus.Easytherm.Easytherm).SetTemperatureOp(10);
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)
{
@ -715,7 +715,7 @@ namespace DeviceTest
{
operation31 = (tbfComponent1forOp as TBF.BenchControl.Modbus.Easytherm.Easytherm).SetTemperatureOp(10);
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)
{

View File

@ -16,6 +16,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ResultsBrowser", "ResultsBr
EndProjectSection
EndProject
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
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dirichlet.Numerics", "Dirichlet.Numerics\Dirichlet.Numerics.csproj", "{439D0878-C76E-452B-B17D-209A89E91D36}"
EndProject

View File

@ -128,8 +128,9 @@ namespace TBF.BenchControl.Modbus.Common
serialPort.Write(message, 0, message.Length);
Debug.WriteLine(Telegram.LogTelegram("Sending message ", message));
log.Debug(Telegram.LogTelegram("Sending message ", message));
string s = 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];
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];
int function = buffer[1];
int bytesCount = buffer[2];
if (nrBytes == bytesCount + 5 && Telegram.VerifyTelegramCRC(buffer))
{
receivedTelegrams[deviceAddress].Enqueue(buffer);
Debug.WriteLine("Valid telegram received: ReceivedTelegrams[{0}].Count = {1}", deviceAddress, receivedTelegrams[deviceAddress].Count);
}
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);
}
else
{
string s = Telegram.LogTelegram("Invalid data received ", buffer);
Debug.WriteLine(s);
log.Debug(s);
}
}
}

View File

@ -58,26 +58,48 @@ namespace TBF.BenchControl.Modbus.Easytherm
/// Set outputs of QuidoRS board
/// </summary>
/// <param name="temperature">output value</param>
public void SetTemperature(ushort temperature)
public void SetTemperature(float temperature)
{
temperatureSetpoint = temperature;
SendTemperature(temperatureSetpoint);
}
if (temperature < 0 || temperature > 100) return; /// temperature out of range
private void SendTemperature(ushort temperatureSetpoint)
{
byte[] msg = new byte[8];
ushort temperatureSetpoint = (ushort)(100 * temperature);
ushort destAddress = (ushort)2;
byte[] msg = new byte[8];
msg[0] = easythermCfg.ModbusAddress;
msg[1] = (byte)Function.PresetSingleRegister;
msg[2] = 0; /// Relative address Hi
msg[3] = 2; /// Relative address Lo
msg[2] = (byte)(destAddress >> 8); /// Relative address Hi
msg[3] = (byte)(destAddress & 0xFF); /// Relative address Lo
msg[4] = (byte)(temperatureSetpoint >> 8); /// Output data Hi
msg[5] = (byte)(temperatureSetpoint & 0xFF); /// Output data Lo
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>
/// 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="setOutputsDone">Event returned when SetOutput is done</param>
/// <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);
}
}
}

View File

@ -23,24 +23,25 @@ namespace TBF.BenchControl.Modbus.Easytherm
/// <param name="easytherm">Pressure meter reference</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>
public ReadTemperatureOp(Easytherm easytherm, ushort outValue, Event eventDone)
public ReadTemperatureOp(Easytherm easytherm, Event eventDone)
{
if (easytherm == null) throw new ArgumentNullException("easytherm");
this.easytherm = easytherm;
this.outValue = outValue;
//this.outValue = outValue;
this.eventDone = eventDone;
log.Debug(this.ToString());
}
public ReadTemperatureOp(Easytherm easytherm, ushort outValue)
: this(easytherm, outValue, Event.SetOutputsDone)
public ReadTemperatureOp(Easytherm easytherm)
: this(easytherm, Event.Done)
{
}
/// <summary>Start this operation</summary>
public void Start()
{
}
easytherm.GetSomething(0, 1);
}
/// <summary>Run this operation</summary>
public Event Run()

View File

@ -15,7 +15,7 @@ namespace TBF.BenchControl.Modbus.Easytherm
/// Set by the constructor
readonly Easytherm easytherm;
readonly Event eventDone;
ushort temperatureSetpoint;
float temperatureSetpoint;
/// <summary>
/// Events: PressureInDone, PressureOutDone or Error
@ -23,7 +23,7 @@ namespace TBF.BenchControl.Modbus.Easytherm
/// <param name="easytherm">Pressure meter reference</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>
public SetTemperatureOp(Easytherm easytherm, ushort temperatureSetpoint, Event eventDone)
public SetTemperatureOp(Easytherm easytherm, float temperatureSetpoint, Event eventDone)
{
if (easytherm == null) throw new ArgumentNullException("easytherm");
this.easytherm = easytherm;
@ -32,8 +32,8 @@ namespace TBF.BenchControl.Modbus.Easytherm
log.Debug(this.ToString());
}
public SetTemperatureOp(Easytherm easytherm, ushort outValue)
: this(easytherm, outValue, Event.SetOutputsDone)
public SetTemperatureOp(Easytherm easytherm, float temperatureSetpoint)
: this(easytherm, temperatureSetpoint, Event.SetOutputsDone)
{
}