first commit
This commit is contained in:
45
ChamChat/Client_PLxKPH/Client.PLxKPH.Specific.cs
Normal file
45
ChamChat/Client_PLxKPH/Client.PLxKPH.Specific.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using ChamChat.Models;
|
||||
|
||||
namespace ChamChat
|
||||
{
|
||||
public partial class PLxKPH_Client : Client
|
||||
{
|
||||
// Run a single step.
|
||||
// The last setting is held when the program ends.
|
||||
// See page 60.
|
||||
public Boolean Start(Double DurationMin, Double StartT, Double TargetT, Double StartRH, Double TargetRH )
|
||||
{
|
||||
|
||||
// Example: RUN PRGM, TEMP10.0 GOTEMP23.0 HUMI85 GOHUMI100 TIME1:00
|
||||
string sAddr = _Address.ToString();
|
||||
string cmd;
|
||||
string read;
|
||||
|
||||
cmd = sAddr + ", RUN PRGM, ";
|
||||
|
||||
cmd += string.Format("TEMP{0:0.0} ", StartT);
|
||||
if (StartT != TargetT) // Ramping required
|
||||
cmd += string.Format("GOTEMP{0:0.0} ", TargetT);
|
||||
|
||||
if (TargetRH > 0)
|
||||
{
|
||||
cmd += string.Format("HUMI{0:0} ", StartRH);
|
||||
if (StartRH != TargetRH) // Ramping required
|
||||
cmd += string.Format("GOHUMI{0:0} ", TargetRH);
|
||||
}
|
||||
else cmd += "HUMI OFF "; // No RH set
|
||||
|
||||
double hrs = Math.Floor(DurationMin/60);
|
||||
double min = Math.Floor(DurationMin - hrs * 60);
|
||||
cmd += String.Format("TIME{0:0}:{1:0}", hrs, min);
|
||||
|
||||
return DataTransfer(cmd, out read, _ReturnDataWaitms);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
384
ChamChat/Client_PLxKPH/Client.PLxKPH.cs
Normal file
384
ChamChat/Client_PLxKPH/Client.PLxKPH.cs
Normal file
@@ -0,0 +1,384 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using ChamChat.Models;
|
||||
|
||||
namespace ChamChat
|
||||
{
|
||||
public partial class PLxKPH_Client : Client
|
||||
{
|
||||
private const Int32 _OptionRange = 2000;
|
||||
private const int _RAM = 1;
|
||||
private const Int32 _ReturnDataWaitms = 300; // Time out for client to prepare and return data
|
||||
private DateTime _ReadyToSend = DateTime.Now; // Timestamp when client is ready to communicate
|
||||
|
||||
|
||||
public PLxKPH_Client(Int32 MIDS, ClientType Type)
|
||||
: base(MIDS, Type)
|
||||
{
|
||||
|
||||
// Set options available in client
|
||||
_Parameters = new List<Parameter>();
|
||||
_Parameters.Add(Parameter.T);
|
||||
_Parameters.Add(Parameter.RH);
|
||||
_Parameters.Add(Parameter.RampT);
|
||||
_Parameters.Add(Parameter.RampRH);
|
||||
|
||||
|
||||
// Add option range
|
||||
_ClientOptions = new List<ProfileOption>();
|
||||
foreach (ProfileOption o in Enum.GetValues(typeof(ProfileOption)))
|
||||
if ((int)o >= _OptionRange && (int)o < _OptionRange + 999)
|
||||
_ClientOptions.Add(o);
|
||||
|
||||
// Set availabel addresses for programming
|
||||
_AvailableRAMs = new List<int>();
|
||||
for (int i = 1; i < 21; i++)
|
||||
_AvailableRAMs.Add(i);
|
||||
|
||||
_InterfaceType = InterfaceType.FDTI_USB_COM422;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// To do
|
||||
public override Profile ReadProfile(int RAM, ref System.ComponentModel.BackgroundWorker bgw)
|
||||
{
|
||||
Profile profile = new Profile();
|
||||
return profile;
|
||||
}
|
||||
|
||||
|
||||
public override Boolean WriteProfile(Profile profile)
|
||||
{
|
||||
return WriteProfile(profile, _RAM);
|
||||
}
|
||||
|
||||
public override Boolean WriteProfile(Profile profile, int RAM)
|
||||
{
|
||||
// Only stand alone profiles allowed!
|
||||
if( !IsProgrammable(profile))
|
||||
return false;
|
||||
|
||||
string title = profile.Title.Substring(0, (int)Math.Min(14, profile.Title.Length)).Trim();
|
||||
|
||||
string sRAM = string.Format("{0:0}", RAM);
|
||||
|
||||
string sAddr = _Address.ToString();
|
||||
string cmd;
|
||||
string read;
|
||||
string cmd_pre = sAddr + ", PRGM DATA WRITE, PGM" + sRAM + ", ";
|
||||
|
||||
|
||||
|
||||
// Cancel RAM program editing
|
||||
cmd = cmd_pre + "EDIT CANCEL";
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms,1);
|
||||
if( !read.Contains("ERR-3"))
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms, 3);
|
||||
|
||||
|
||||
|
||||
// Open RAM program
|
||||
cmd = cmd_pre + "EDIT START";
|
||||
DataTransfer(cmd,out read, _ReturnDataWaitms);
|
||||
|
||||
|
||||
// Steps
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < profile.Steps.Count; i++)
|
||||
{
|
||||
Step step = profile.Steps[i];
|
||||
cmd = cmd_pre;
|
||||
cmd += String.Format("STEP{0:0}, ", i + 1);
|
||||
cmd += String.Format("TEMP{0:0.0}, ", step.T);
|
||||
cmd += step.RampCtrlT ? "TRAMPON, " : "TRAMPOFF, ";
|
||||
cmd += step.HasRH ? String.Format("HUMI{0:0}, ", step.RH) : "HUMI OFF, ";
|
||||
cmd += step.RampCtrlRH ? "HRAMPON, " : "HRAMPOFF, ";
|
||||
cmd += String.Format("TIME{0:00}:{1:00}, ", step.Hours, step.Minutes);
|
||||
cmd += "GRANTY OFF, ";
|
||||
cmd += "PAUSE OFF";
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { throw new Exception("writing steps - " + ex.Message); }
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
// Loops
|
||||
if (profile.Loops.Count > 0)
|
||||
{
|
||||
Loop loop = profile.Loops[0];
|
||||
cmd = cmd_pre;
|
||||
cmd += String.Format("COUNT, A({0}.{1}.{2})", loop.N - 1, loop.Last + 1, loop.First + 1);
|
||||
|
||||
if (profile.Loops.Count > 1)
|
||||
{
|
||||
loop = profile.Loops[1];
|
||||
cmd += String.Format(", B({0}.{1}.{2})", loop.N - 1, loop.Last + 1, loop.First + 1);
|
||||
}
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { throw new Exception("writing loops - " + ex.Message); }
|
||||
|
||||
|
||||
|
||||
// End mode
|
||||
try
|
||||
{
|
||||
cmd = profile.Options.Contains(ProfileOption.PLxKPH_EndModeHold) ? cmd_pre + "END, HOLD" : cmd_pre + "END, OFF";
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms);
|
||||
}
|
||||
catch (Exception ex) { throw new Exception("writing end mode - " + ex.Message); }
|
||||
|
||||
|
||||
|
||||
// Name of program
|
||||
cmd = cmd_pre + "NAME, " + title;
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms);
|
||||
|
||||
|
||||
// Close and save RAM program
|
||||
cmd = cmd_pre + "EDIT END";
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms);
|
||||
|
||||
// Wait 3 seconds to close program
|
||||
System.Threading.Thread.Sleep(3000);
|
||||
|
||||
Boolean result = false;
|
||||
if (_Interface.InterfaceStatus == null)
|
||||
result = true;
|
||||
|
||||
_Profile = profile;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public override Boolean IsProgrammable(Profile profile)
|
||||
{
|
||||
// Profile is programmable if all below applies
|
||||
// number of profile steps 99
|
||||
// number of loops < 3
|
||||
// -40 < t < 150
|
||||
|
||||
if(profile.Steps.Count > 99)
|
||||
return false;
|
||||
|
||||
if (profile.Loops.Count > 2)
|
||||
return false;
|
||||
|
||||
foreach (Loop loop in profile.Loops)
|
||||
if (loop.N > 99 || loop.N < 2)
|
||||
return false;
|
||||
|
||||
foreach (Step step in profile.Steps)
|
||||
{
|
||||
if (step.T < -40 || step.T > 150)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public override Boolean HasAlarm(out List<Alarm> alarms)
|
||||
{
|
||||
alarms = new List<Alarm>();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public override Boolean IsIdle()
|
||||
{
|
||||
// IsIdle() returns true if status of chamber is 'Standby'. See page 36 MODE?.
|
||||
|
||||
string sAddr = _Address.ToString();
|
||||
string cmd;
|
||||
string read;
|
||||
|
||||
cmd = sAddr + ", MODE?";
|
||||
DataTransfer(cmd,out read, _ReturnDataWaitms);
|
||||
|
||||
if (read.Contains("STANDBY"))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public override Boolean Start()
|
||||
{
|
||||
if (_Profile == null)
|
||||
return false;
|
||||
|
||||
string sAddr = _Address.ToString();
|
||||
string cmd;
|
||||
string read;
|
||||
|
||||
cmd = sAddr + ", PRGM, RUN, RAM:" + _RAM+", STEP1"; // See page 56
|
||||
|
||||
return DataTransfer(cmd,out read, _ReturnDataWaitms);
|
||||
}
|
||||
|
||||
|
||||
public override Boolean IsFinished()
|
||||
{
|
||||
// Finished() returns true if chamber is not running. See page 36 MODE?.
|
||||
string sAddr = _Address.ToString();
|
||||
string cmd;
|
||||
string read;
|
||||
|
||||
cmd = sAddr + ", MON?";
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms);
|
||||
|
||||
try
|
||||
{
|
||||
double t = Double.Parse(read.Split(',')[0]);
|
||||
double RH = Double.Parse(read.Split(',')[1]);
|
||||
_Progress = String.Format("Current conditions are {0:0.0} °C and {1:0} %rh", t, RH);
|
||||
_LastProgressUpdate = DateTime.Now;
|
||||
}
|
||||
catch { _Progress = DateTime.Now.ToString("yyyy-MM-dd @ hh:mm"); }
|
||||
|
||||
|
||||
if (read.Contains("STANDBY"))
|
||||
return true;
|
||||
|
||||
if (read.Contains("OFF"))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public override Boolean Stop()
|
||||
{
|
||||
string sAddr = _Address.ToString();
|
||||
string cmd;
|
||||
string read;
|
||||
cmd = sAddr + ", MODE, STANDBY";
|
||||
return DataTransfer(cmd, out read, _ReturnDataWaitms);
|
||||
}
|
||||
|
||||
|
||||
public override Boolean IsOnline()
|
||||
{
|
||||
try
|
||||
{
|
||||
string sAddr = _Address.ToString();
|
||||
string cmd;
|
||||
string read;
|
||||
cmd = sAddr + ", TYPE?";
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms);
|
||||
return (read.ToLower().Contains("scp220") );
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private string _Progress = "";
|
||||
private DateTime _LastProgressUpdate = DateTime.Now;
|
||||
public override String Progress()
|
||||
{
|
||||
if(_LastProgressUpdate.AddMinutes(3) < DateTime.Now)
|
||||
IsFinished();
|
||||
return _Progress;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private bool TxRxSucces(string cmd, string read)
|
||||
{
|
||||
// Command not correctly processed
|
||||
if (read.StartsWith("NA:"))
|
||||
return false;
|
||||
|
||||
// No response received
|
||||
if (read.Trim().Length < 1)
|
||||
return false;
|
||||
|
||||
// Handle monitoring commands
|
||||
if (cmd.Trim().Contains("?"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (read.Trim().StartsWith("OK:"))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private Boolean DataTransfer(string cmd, out string read, int ReturnDataWaitms)
|
||||
{
|
||||
// If no maximum number of attempts is given, it defaults to 4.
|
||||
return DataTransfer(cmd, out read, ReturnDataWaitms,4);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Performs transfer and adds interface logs to list in Client parent class
|
||||
private Boolean DataTransfer(string cmd, out string read, int ReturnDataWaitms, int MaxNumOfAttempts)
|
||||
{
|
||||
// Construct command to send
|
||||
cmd += (char)13; // CR
|
||||
cmd += (char)10; // LF
|
||||
cmd = cmd.Replace(" ", "");
|
||||
|
||||
|
||||
// Wait for _ReadyToSend or max 1 seconds
|
||||
DateTime go = DateTime.Now.AddSeconds(1);
|
||||
while (DateTime.Now < _ReadyToSend && DateTime.Now < go)
|
||||
System.Threading.Thread.Sleep(10);
|
||||
|
||||
read = "";
|
||||
bool success = false;
|
||||
int attempt = 0;
|
||||
while (!success && attempt < MaxNumOfAttempts)
|
||||
{
|
||||
DataTransferLog log = _Interface.DataTransfer(cmd, out read, ReturnDataWaitms);
|
||||
success = TxRxSucces(cmd, read);
|
||||
attempt++;
|
||||
|
||||
// Mask for showing in GUI
|
||||
if (cmd.Contains("MON?") || cmd.Contains("EDIT CANCEL") || cmd.Contains("EDITCANCEL"))
|
||||
log.ShowInGUI = false;
|
||||
|
||||
|
||||
// Notify user via GUI of failed attempts
|
||||
if (attempt > 1)
|
||||
log.Command += string.Format(" [Attempt {0:0}]", attempt);
|
||||
|
||||
// Add to logs
|
||||
AppendDataTransferLog(log);
|
||||
|
||||
|
||||
// Set _ReadyToSend acc. manual specs
|
||||
if (cmd.Contains("?"))
|
||||
_ReadyToSend = DateTime.Now.AddMilliseconds(500);
|
||||
else
|
||||
_ReadyToSend = DateTime.Now.AddMilliseconds(1200);
|
||||
|
||||
|
||||
// Sleeps
|
||||
if (!success)
|
||||
System.Threading.Thread.Sleep(5000); // Sleep 5 seconds before resending if failed
|
||||
}
|
||||
return success;
|
||||
}
|
||||
}
|
||||
}
|
||||
63
ChamChat/Client_PLxKPH/Client_PLxKPH.csproj
Normal file
63
ChamChat/Client_PLxKPH/Client_PLxKPH.csproj
Normal file
@@ -0,0 +1,63 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.30703</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{1FB70C9C-6F0B-4580-9682-A85B40C90B38}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>ChamChat</RootNamespace>
|
||||
<AssemblyName>PLxKPH</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Client.PLxKPH.cs" />
|
||||
<Compile Include="Client.PLxKPH.Specific.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Task.PLxKPH.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Models\Models.csproj">
|
||||
<Project>{09375A4A-28B8-427B-853D-75C03A070728}</Project>
|
||||
<Name>Models</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
20
ChamChat/Client_PLxKPH/Client_PLxKPH.sln
Normal file
20
ChamChat/Client_PLxKPH/Client_PLxKPH.sln
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||
# Visual C# Express 2010
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Client_PLxKPH", "Client_PLxKPH.csproj", "{1FB70C9C-6F0B-4580-9682-A85B40C90B38}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{1FB70C9C-6F0B-4580-9682-A85B40C90B38}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1FB70C9C-6F0B-4580-9682-A85B40C90B38}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1FB70C9C-6F0B-4580-9682-A85B40C90B38}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1FB70C9C-6F0B-4580-9682-A85B40C90B38}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
BIN
ChamChat/Client_PLxKPH/Client_PLxKPH.suo
Normal file
BIN
ChamChat/Client_PLxKPH/Client_PLxKPH.suo
Normal file
Binary file not shown.
36
ChamChat/Client_PLxKPH/Properties/AssemblyInfo.cs
Normal file
36
ChamChat/Client_PLxKPH/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("TSD100S")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Microsoft")]
|
||||
[assembly: AssemblyProduct("TSD100S")]
|
||||
[assembly: AssemblyCopyright("Copyright © Microsoft 2015")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("2fc0fe7d-2c1d-4983-a44a-6c1fd33288e3")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
347
ChamChat/Client_PLxKPH/Task.PLxKPH.cs
Normal file
347
ChamChat/Client_PLxKPH/Task.PLxKPH.cs
Normal file
@@ -0,0 +1,347 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using ChamChat.Models;
|
||||
|
||||
namespace ChamChat
|
||||
{
|
||||
public class PLxKPH_Task : Task
|
||||
{
|
||||
public PLxKPH_Task(Client Client, Profile Profile)
|
||||
: base(Client, Profile)
|
||||
{
|
||||
_Profile = Profile;
|
||||
_Client = Client;
|
||||
_SerSteps = _Profile.SerializedStepList;
|
||||
}
|
||||
|
||||
private const Int32 PollingIntervalSeconds = 10;
|
||||
|
||||
private List<Step> _SerSteps;
|
||||
|
||||
|
||||
public override Boolean IsControlledProgrammable(Profile profile)
|
||||
{
|
||||
ClientMessage msg = new ClientMessage(String.Format("The {0} can only operate in stand alone mode.", _Client.TypeDescription));
|
||||
_Client.ClientMessages = new List<ClientMessage>();
|
||||
_Client.ClientMessages.Add(msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
protected override void ThreadStandAlone()
|
||||
{
|
||||
// Write profile
|
||||
try
|
||||
{
|
||||
if (!_Client.WriteProfile(_Profile))
|
||||
{
|
||||
_Status = TaskStatus.Stopped;
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_Status = TaskStatus.ExceptionOccured;
|
||||
_TaskProgress = string.Format("Client WriteProfile() exception: {0}", ex.Message);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Start client
|
||||
try
|
||||
{
|
||||
if (!_Client.Start())
|
||||
{
|
||||
_Status = TaskStatus.Stopped;
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_Status = TaskStatus.ExceptionOccured;
|
||||
_TaskProgress = string.Format("Client Start() exception: {0}", ex.Message);
|
||||
return;
|
||||
}
|
||||
|
||||
DateTime lastPolled = DateTime.Now;
|
||||
|
||||
while (_Status == TaskStatus.IsRunning)
|
||||
{
|
||||
// Poll only every 'PollingIntervalSeconds' seconds
|
||||
if (DateTime.Now > lastPolled.AddSeconds(PollingIntervalSeconds))
|
||||
{
|
||||
// Is finished?
|
||||
try
|
||||
{
|
||||
if (_Client.IsFinished())
|
||||
{
|
||||
_Status = TaskStatus.Finished;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
try
|
||||
{
|
||||
// Client return "Current conditions are x °C and x %rh"
|
||||
_TaskProgress = _Client.Progress();
|
||||
double runTimeMin = (DateTime.Now - StartOfTask).TotalMinutes;
|
||||
double p = runTimeMin / _Profile.DurationMin * 100;
|
||||
double remainTimeMin = Math.Max(0,_Profile.DurationMin - runTimeMin);
|
||||
double hrs = Math.Floor(remainTimeMin /60);
|
||||
double min = Math.Floor(remainTimeMin - 60 * hrs);
|
||||
_TaskProgress += String.Format(", {0:0.0}% completed, {1:0}h{2:00} remaining",p, hrs,min );
|
||||
|
||||
}
|
||||
catch { }
|
||||
lastPolled = DateTime.Now;
|
||||
}
|
||||
|
||||
System.Threading.Thread.Sleep(100);
|
||||
|
||||
if (_Status == TaskStatus.AbortRequested)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_Client.Stop())
|
||||
_Status = TaskStatus.Aborted;
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
_isKicking = true;
|
||||
}
|
||||
_isKicking = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
protected override void ThreadControlled()
|
||||
{
|
||||
Int32 iCurrentSerialStep = -1;
|
||||
DateTime startOfCurrentProgram = new DateTime(1900, 1, 1);
|
||||
DateTime endOfCurrentProgram = new DateTime(1900, 1, 1);
|
||||
Step currentStep = _SerSteps[0];
|
||||
DateTime lastPolled = DateTime.Now;
|
||||
|
||||
while (_Status == TaskStatus.IsRunning)
|
||||
{
|
||||
if (DateTime.Now > endOfCurrentProgram)
|
||||
{
|
||||
iCurrentSerialStep++;
|
||||
|
||||
// Last step has been performed?
|
||||
if (iCurrentSerialStep > _SerSteps.Count - 1)
|
||||
{
|
||||
_Client.Stop();
|
||||
_Status = TaskStatus.Finished;
|
||||
AddEventLog("Last step performed");
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get step details
|
||||
currentStep = _SerSteps[iCurrentSerialStep];
|
||||
double TargetT = currentStep.T;
|
||||
double TargetRH = currentStep.RH;
|
||||
double DurationMin = currentStep.DurationMin;
|
||||
|
||||
double StartT = currentStep.T; // Set start to be target, but change to value of previous step if ramped.
|
||||
if (currentStep.RampCtrlT)
|
||||
{
|
||||
if (iCurrentSerialStep == 0)
|
||||
StartT = 23;
|
||||
else
|
||||
StartT = _SerSteps[iCurrentSerialStep - 1].T;
|
||||
}
|
||||
|
||||
double StartRH = currentStep.RH; // Set start to be target, but change to value of previous step if ramped.
|
||||
if (currentStep.RampCtrlRH)
|
||||
{
|
||||
if (iCurrentSerialStep == 0)
|
||||
StartRH = 60;
|
||||
else
|
||||
StartRH = _SerSteps[iCurrentSerialStep - 1].RH;
|
||||
}
|
||||
|
||||
RestartClient(DurationMin, StartT, TargetT, StartRH, TargetRH);
|
||||
|
||||
if (_Status != TaskStatus.IsRunning)
|
||||
continue;
|
||||
|
||||
|
||||
// Update variables
|
||||
startOfCurrentProgram = DateTime.Now;
|
||||
endOfCurrentProgram = DateTime.Now.AddMinutes(DurationMin);
|
||||
lastPolled = DateTime.Now;
|
||||
|
||||
|
||||
#region Update events
|
||||
try
|
||||
{
|
||||
string s = "Set conditions: ";
|
||||
if (currentStep.RampCtrlT)
|
||||
s += String.Format("to {0:0.0} °C ({1:0.00} ˜°C/min), ", TargetT, (TargetT - StartT) / DurationMin);
|
||||
else
|
||||
s += String.Format("{0:0.0} °C, ", TargetT);
|
||||
if (currentStep.RampCtrlRH)
|
||||
s += String.Format("to {0:0.0} %rh ({1:0.00} ˜%rh/min), ", TargetRH, (TargetRH - StartRH) / DurationMin);
|
||||
else
|
||||
s += String.Format("{0:0.0} %rh, ", TargetRH);
|
||||
|
||||
s += string.Format("{0:0}h{1:00}", currentStep.Hours, currentStep.Minutes);
|
||||
|
||||
AddEventLog(s);
|
||||
s = string.Format("Partial profile end is {0:00}-{1:00} @ {2:00}:{3:00}:{4:00}", endOfCurrentProgram.Day, endOfCurrentProgram.Month, endOfCurrentProgram.Hour, endOfCurrentProgram.Minute, endOfCurrentProgram.Second);
|
||||
AddEventLog(s);
|
||||
}
|
||||
catch (Exception ex) { AddEventLog("Update events: " + ex.Message); }
|
||||
#endregion Update events
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Poll only every 'PollingIntervalSeconds' seconds
|
||||
if (DateTime.Now > lastPolled.AddSeconds(PollingIntervalSeconds))
|
||||
{
|
||||
// Is finished?
|
||||
try
|
||||
{
|
||||
if (_Client.IsFinished())
|
||||
{
|
||||
// Last step is held (page 61) when program ends. Client will never finish by itself.
|
||||
AddEventLog("Client finished, but task did not!");
|
||||
_Status = TaskStatus.Interrupted; // Profile did not finish, client did
|
||||
continue;
|
||||
}
|
||||
}
|
||||
catch { } // Always continue and keep trying
|
||||
|
||||
|
||||
#region Taskprogress
|
||||
try
|
||||
{
|
||||
double taskRunTime = (DateTime.Now - _startThread).TotalMinutes;
|
||||
double pTest = Math.Min(100, Math.Floor(taskRunTime / _Profile.DurationMin * 100));
|
||||
double taskTimeRemain = _Profile.DurationMin - taskRunTime;
|
||||
double taskTimeRemainHrs = Math.Floor(taskTimeRemain / 60);
|
||||
double taskTimeRemainMin = Math.Floor(taskTimeRemain - 60 * taskTimeRemainHrs);
|
||||
double currentStepRuntime = (DateTime.Now - startOfCurrentProgram).TotalMinutes;
|
||||
double pStep = Math.Min(100, Math.Floor(currentStepRuntime / currentStep.DurationMin * 100));
|
||||
_TaskProgress = String.Format("Step #{0:0}/{1:0} progress {2:0}%, test progress {3:0}%, remaining test time {4:0}h{5:00}m", iCurrentSerialStep + 1,_SerSteps.Count, pStep, pTest, taskTimeRemainHrs, taskTimeRemainMin);
|
||||
if (iCurrentSerialStep + 1 == _SerSteps.Count && pTest > 99.99)
|
||||
_TaskProgress = "Profile executed";
|
||||
}
|
||||
catch { _TaskProgress = "n/a"; }
|
||||
#endregion Taskprogress
|
||||
|
||||
|
||||
lastPolled = DateTime.Now;
|
||||
}
|
||||
|
||||
System.Threading.Thread.Sleep(200);
|
||||
|
||||
_isKicking = true;
|
||||
}
|
||||
|
||||
|
||||
if (_Status == TaskStatus.AbortRequested)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_Client.Stop())
|
||||
_Status = TaskStatus.Aborted;
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
_isKicking = false;
|
||||
}
|
||||
|
||||
|
||||
private void RestartClient(Double DurationMin, Double StartT, Double TargetT, Double StartRH, Double TargetRH)
|
||||
{
|
||||
// Stop client
|
||||
try
|
||||
{
|
||||
AddEventLog("Info: Stopping client");
|
||||
if (!_Client.Stop())
|
||||
{
|
||||
_Status = TaskStatus.Interrupted;
|
||||
AddEventLog("Task interrupted while trying to stop client!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_Status = TaskStatus.ExceptionOccured;
|
||||
_TaskProgress = string.Format("Client Stop() exception: {0}", ex.Message);
|
||||
AddEventLog(_TaskProgress);
|
||||
return;
|
||||
}
|
||||
|
||||
// Wait to finish
|
||||
try
|
||||
{
|
||||
Boolean timedOut = true;
|
||||
|
||||
DateTime startWait = DateTime.Now;
|
||||
while (DateTime.Now < startWait.AddSeconds(60))
|
||||
{
|
||||
System.Threading.Thread.Sleep(1000);
|
||||
if (_Client.IsFinished())
|
||||
{
|
||||
timedOut = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (timedOut)
|
||||
{
|
||||
_Status = TaskStatus.Interrupted;
|
||||
AddEventLog("Time out (60 s) in RestartClient.WaitForFinish");
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_Status = TaskStatus.ExceptionOccured;
|
||||
_TaskProgress = string.Format("Client WaitForFinish exception: {0}", ex.Message);
|
||||
AddEventLog(_TaskProgress);
|
||||
return;
|
||||
}
|
||||
|
||||
AddEventLog("Info: Client stopped");
|
||||
|
||||
|
||||
// Start client
|
||||
try
|
||||
{
|
||||
AddEventLog("Info: Starting client");
|
||||
|
||||
if (!((PLxKPH_Client)_Client).Start(DurationMin, StartT, TargetT, StartRH, TargetRH))
|
||||
{
|
||||
// Try to start again after 10 sec
|
||||
AddEventLog("First attempt to start client failed!");
|
||||
System.Threading.Thread.Sleep(10000);
|
||||
|
||||
if (!((PLxKPH_Client)_Client).Start(DurationMin, StartT, TargetT, StartRH, TargetRH))
|
||||
{
|
||||
_Status = TaskStatus.Interrupted;
|
||||
AddEventLog("Task interrupted while trying to start client!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_Status = TaskStatus.ExceptionOccured;
|
||||
_TaskProgress = string.Format("Client Start() exception: {0}", ex.Message);
|
||||
AddEventLog(_TaskProgress);
|
||||
return;
|
||||
}
|
||||
AddEventLog("Info: Client started");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// <autogenerated />
|
||||
using System;
|
||||
using System.Reflection;
|
||||
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.0", FrameworkDisplayName = ".NET Framework 4")]
|
||||
Binary file not shown.
@@ -0,0 +1 @@
|
||||
030d805dcba3c63f1b65d4f63d5ddc35bc93310a
|
||||
@@ -0,0 +1,2 @@
|
||||
\\silicium\software\MASER software\Source\ChamChat\Client_PLxKPH\obj\Release\Client_PLxKPH.csproj.AssemblyReference.cache
|
||||
\\silicium\software\MASER software\Source\ChamChat\Client_PLxKPH\obj\Release\Client_PLxKPH.csproj.CoreCompileInputs.cache
|
||||
Binary file not shown.
Reference in New Issue
Block a user