first commit
This commit is contained in:
428
ChamChat/Client_LHL113/Client.LHL113.cs
Normal file
428
ChamChat/Client_LHL113/Client.LHL113.cs
Normal file
@@ -0,0 +1,428 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using ChamChat.Models;
|
||||
|
||||
namespace ChamChat
|
||||
{
|
||||
public partial class LHL113_Client : Client
|
||||
{
|
||||
private const Int32 _OptionRange = 3000;
|
||||
private const Int32 _DataTransferTimeOut = 1000;
|
||||
private DateTime _ReadyToSend = DateTime.Now; // Timestamp when client is ready to communicate
|
||||
private const int _RAM = 1;
|
||||
private DateTime _dtTestStart = DateTime.Now;
|
||||
|
||||
|
||||
// To do
|
||||
public LHL113_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 < 31; i++)
|
||||
_AvailableRAMs.Add(i);
|
||||
|
||||
|
||||
_InterfaceType = InterfaceType.FDTI_USB_COM422;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// To do
|
||||
public override Profile ReadProfile(int RAM, ref System.ComponentModel.BackgroundWorker bgw)
|
||||
{
|
||||
string sAddr = _Address.ToString();
|
||||
string cmd;
|
||||
string read;
|
||||
Profile profile = new Profile();
|
||||
|
||||
try
|
||||
{
|
||||
// Communicate with client
|
||||
cmd = sAddr + ",PRGMREAD,";
|
||||
DataTransfer(cmd, out read, _DataTransferTimeOut);
|
||||
|
||||
|
||||
List<Step> steps = new List<Step>();
|
||||
List<Loop> loops = new List<Loop>();
|
||||
List<ProfileOption> options = new List<ProfileOption>();
|
||||
String name = "LHL113_Client";
|
||||
|
||||
// Create profile
|
||||
profile = new Profile(name, steps, loops, options);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
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 sRAM = String.Format("{0:0}", RAM);
|
||||
|
||||
string sCmdStart = _Address.ToString() + ", PRGM DATA WRITE, PGM:" + sRAM + ", ";
|
||||
string cmd;
|
||||
string read;
|
||||
|
||||
|
||||
// Set to STANDBY if OFF
|
||||
cmd = _Address.ToString() + ", MODE?";
|
||||
DataTransfer(cmd, out read, _DataTransferTimeOut);
|
||||
if (read.Contains("OFF"))
|
||||
{
|
||||
cmd = _Address.ToString() + ", MODE, STANDBY";
|
||||
DataTransfer(cmd, out read, _DataTransferTimeOut);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Communicate with client (page 49)
|
||||
cmd = sCmdStart + "EDIT START";
|
||||
DataTransfer(cmd, out read, _DataTransferTimeOut);
|
||||
|
||||
for (int i = 0; i < profile.SerializedStepList.Count; i++)
|
||||
{
|
||||
Step step = profile.SerializedStepList[i];
|
||||
cmd = sCmdStart;
|
||||
cmd += string.Format("STEP{0:0}, ", i + 1);
|
||||
cmd += string.Format("TEMP{0:00.0}, ", step.T);
|
||||
if (step.RampCtrlT) cmd += "TRAMPON,"; else cmd += "TRAMPOFF,";
|
||||
cmd += string.Format("HUMI{0:00}, ", step.RH);
|
||||
if (step.RampCtrlRH) cmd += "HRAMPON,"; else cmd += "HRAMPOFF,";
|
||||
|
||||
if (step.Hours < 100)
|
||||
cmd += string.Format("TIME{0:00}:{1:00}, ", step.Hours, step.Minutes);
|
||||
else
|
||||
cmd += string.Format("TIME{0:00}:00, ", step.Hours);
|
||||
cmd += "GRANTY OFF, ";
|
||||
DataTransfer(cmd, out read, _DataTransferTimeOut);
|
||||
System.Threading.Thread.Sleep(500);
|
||||
}
|
||||
|
||||
// End options (off is default)
|
||||
if (profile.Options.Contains(ProfileOption.LHL113_EndModeHold))
|
||||
cmd = sCmdStart + "END, HOLD";
|
||||
else
|
||||
cmd = sCmdStart + "END, OFF";
|
||||
DataTransfer(cmd, out read, _DataTransferTimeOut);
|
||||
|
||||
|
||||
|
||||
// Loop (see page 50)
|
||||
if (profile.Loops.Count == 1)
|
||||
{
|
||||
Loop l = profile.Loops[0];
|
||||
cmd = sCmdStart + String.Format("COUNT, ({0:0}. {1:0}. {2:0})", l.First, l.Last, l.N);
|
||||
DataTransfer(cmd, out read, _DataTransferTimeOut);
|
||||
}
|
||||
|
||||
cmd = sCmdStart + "EDIT END";
|
||||
DataTransfer(cmd, out read, _DataTransferTimeOut);
|
||||
|
||||
|
||||
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
|
||||
|
||||
// Step is at least 3 minutes
|
||||
foreach (Step step in profile.Steps)
|
||||
if (step.DurationMin < 3)
|
||||
return false;
|
||||
|
||||
// Temperature is limited between 30 & 90 °C
|
||||
foreach (Step step in profile.Steps)
|
||||
if (step.T < 30 || step.T > 90)
|
||||
return false;
|
||||
|
||||
// RH is limited between 60 & 95 °C
|
||||
foreach (Step step in profile.Steps)
|
||||
if (step.RH < 60 || step.RH > 95)
|
||||
return false;
|
||||
|
||||
// Only one program of a max of 9 steps and a maximum of 99 repeated steps can be stored at a time (page 44 of user's manual).
|
||||
if (profile.Steps.Count > 9)
|
||||
return false;
|
||||
|
||||
if (profile.Loops.Count == 1)
|
||||
{
|
||||
if (profile.Loops[0].N > 99)
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (profile.SerializedStepList.Count > 9)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// To do
|
||||
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 31 MODE?.
|
||||
string sAddr = _Address.ToString();
|
||||
string cmd;
|
||||
string read;
|
||||
|
||||
cmd = sAddr + ", MODE?";
|
||||
DataTransfer(cmd, out read, _DataTransferTimeOut);
|
||||
|
||||
if (read.Contains("STANDBY") || read.Contains("OFF"))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override Boolean Start()
|
||||
{
|
||||
if (_Profile == null)
|
||||
return false;
|
||||
|
||||
string sAddr = _Address.ToString();
|
||||
string cmd;
|
||||
string read;
|
||||
|
||||
cmd = sAddr + ", MODE, RUN "+_RAM; // See page 47.
|
||||
DataTransfer(cmd, out read, _DataTransferTimeOut);
|
||||
|
||||
_dtTestStart = DateTime.Now;
|
||||
|
||||
return TxRxSucces(cmd, read);
|
||||
}
|
||||
|
||||
|
||||
public override Boolean IsFinished()
|
||||
{
|
||||
// Finished() returns true if chamber is not running. See page 34 MODE?.
|
||||
string sAddr = _Address.ToString();
|
||||
string cmd;
|
||||
string read;
|
||||
|
||||
cmd = sAddr + ", MODE?";
|
||||
DataTransfer(cmd, out read, _DataTransferTimeOut);
|
||||
|
||||
if (read.Contains("OFF") || read.Contains("STANDBY"))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override Boolean Stop()
|
||||
{
|
||||
string sAddr = _Address.ToString();
|
||||
string cmd;
|
||||
string read;
|
||||
|
||||
cmd = sAddr + ", MODE, STANDBY"; // Pg. 47
|
||||
DataTransfer(cmd, out read, _DataTransferTimeOut);
|
||||
|
||||
return TxRxSucces(cmd, read);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override Boolean IsOnline()
|
||||
{
|
||||
try
|
||||
{
|
||||
string sAddr = _Address.ToString();
|
||||
string cmd;
|
||||
string read;
|
||||
cmd = sAddr + ", ROM?"; // Pg. 27
|
||||
DataTransfer(cmd, out read, _DataTransferTimeOut);
|
||||
return read.ToLower().Contains("jlc");
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override String Progress()
|
||||
{
|
||||
string sAddr = _Address.ToString();
|
||||
string cmd;
|
||||
string read;
|
||||
|
||||
//cmd = sAddr + ", MON?"; // See page 31
|
||||
//DataTransfer(cmd, out read, _DataTransferTimeOut);
|
||||
//Double T = Double.Parse(read.Split(',')[0]);
|
||||
//Double RH = Double.Parse(read.Split(',')[1]);
|
||||
|
||||
cmd = sAddr + ", PRGM MON?"; // See page 35
|
||||
DataTransfer(cmd, out read, _DataTransferTimeOut);
|
||||
|
||||
int step = Int32.Parse(read.Split(',')[1]) - 1;
|
||||
Double Tset = Double.Parse(read.Split(',')[2]);
|
||||
Double RHset = Double.Parse(read.Split(',')[3]);
|
||||
string time = read.Split(',')[4];
|
||||
int hrs = Int32.Parse(time.Split(':')[0]);
|
||||
int min = Int32.Parse(time.Split(':')[1]);
|
||||
int cyclesLeft = Int32.Parse(read.Split(',')[5]);
|
||||
|
||||
double stepTimeLeft = hrs * 60 + min;
|
||||
double stepDuration = _Profile.SerializedStepList[step].DurationMin;
|
||||
double stepRuntime = stepDuration - stepTimeLeft;
|
||||
double pStep = Math.Min(100, Math.Floor(stepRuntime / stepDuration * 100));
|
||||
|
||||
double testRunTime = (_dtTestStart - DateTime.Now).TotalMinutes;
|
||||
double pTest = Math.Min(100, Math.Floor(testRunTime / _Profile.DurationMin * 100));
|
||||
|
||||
double testTimeRemain = _Profile.DurationMin - testRunTime;
|
||||
double testTimeRemainHrs = Math.Floor(testTimeRemain / 60);
|
||||
double testTimeRemainMin = Math.Floor(testTimeRemain - 60 * testTimeRemainHrs);
|
||||
|
||||
string progress = String.Format("Step #{0:00}/{1:00} progress {2:0}%, ", step + 1, _Profile.SerializedStepList.Count, pStep);
|
||||
progress += String.Format("remaining step time {0:0}h{1:00}m, remaining cycles {2:0}, ",hrs,min, cyclesLeft);
|
||||
progress += String.Format("test progress {0:0}%, remaining test time {1:0}h{2:00}m", pTest, testTimeRemainHrs,testTimeRemainMin);
|
||||
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().Contains("OK:"))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Performs transfer and adds interface logs to list in Client parent class
|
||||
private Boolean DataTransfer(string cmd, out string read, int ReturnDataWaitms)
|
||||
{
|
||||
// If no maximum number of attempts is given, it defaults to 3.
|
||||
return DataTransfer(cmd, out read, ReturnDataWaitms, 3);
|
||||
}
|
||||
|
||||
|
||||
// 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 2 seconds
|
||||
DateTime go = DateTime.Now.AddSeconds(2);
|
||||
while (DateTime.Now < _ReadyToSend && DateTime.Now < go)
|
||||
System.Threading.Thread.Sleep(10);
|
||||
|
||||
read = "";
|
||||
bool success = false;
|
||||
int attempts = 0;
|
||||
while (!success && attempts <= MaxNumOfAttempts)
|
||||
{
|
||||
DataTransferLog log = _Interface.DataTransfer(cmd, out read, ReturnDataWaitms);
|
||||
success = TxRxSucces(cmd, read);
|
||||
attempts++;
|
||||
|
||||
// Mask for showing in GUI
|
||||
if (cmd.Contains("MODE?") || cmd.Contains("MON?"))
|
||||
log.ShowInGUI = false;
|
||||
|
||||
// Notify user via GUI of failed attempts
|
||||
if (attempts > 1)
|
||||
log.Command += string.Format(" [Attempt {0:0}]", attempts);
|
||||
|
||||
// Add to logs
|
||||
AppendDataTransferLog(log);
|
||||
|
||||
|
||||
// Set _ReadyToSend acc. manual specs
|
||||
if (cmd.Contains("?"))
|
||||
_ReadyToSend = DateTime.Now.AddMilliseconds(300);
|
||||
else
|
||||
_ReadyToSend = DateTime.Now.AddMilliseconds(1000);
|
||||
|
||||
|
||||
// Sleeps
|
||||
if (!success)
|
||||
System.Threading.Thread.Sleep(3000); // Sleep 3 seconds before resending if failed
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
61
ChamChat/Client_LHL113/Client_LHL113.csproj
Normal file
61
ChamChat/Client_LHL113/Client_LHL113.csproj
Normal file
@@ -0,0 +1,61 @@
|
||||
<?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>{162E2D74-E197-4188-A3B2-B33B827CC519}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>LHL113</RootNamespace>
|
||||
<AssemblyName>LHL113</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.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Client.LHL113.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Task.LHL113.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>
|
||||
36
ChamChat/Client_LHL113/Properties/AssemblyInfo.cs
Normal file
36
ChamChat/Client_LHL113/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("LHL113")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Microsoft")]
|
||||
[assembly: AssemblyProduct("LHL113")]
|
||||
[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("8354967d-1852-4e51-81c6-2cb820268198")]
|
||||
|
||||
// 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")]
|
||||
388
ChamChat/Client_LHL113/Task.LHL113.cs
Normal file
388
ChamChat/Client_LHL113/Task.LHL113.cs
Normal file
@@ -0,0 +1,388 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using ChamChat.Models;
|
||||
|
||||
namespace ChamChat
|
||||
{
|
||||
public class LHL113_Task : Task
|
||||
{
|
||||
public LHL113_Task(Client Client, Profile Profile)
|
||||
: base(Client, Profile)
|
||||
{
|
||||
_Profile = Profile;
|
||||
_Client = Client;
|
||||
_SerSteps = _Profile.SerializedStepList;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private const Int32 PollingIntervalSeconds = 10;
|
||||
private List<Step> _SerSteps;
|
||||
|
||||
|
||||
|
||||
// To do
|
||||
public override Boolean IsControlledProgrammable(Profile profile)
|
||||
{
|
||||
#warning LHL113_Task to implement: IsControlledProgrammable(Profile profile)
|
||||
return true;
|
||||
|
||||
|
||||
_NewProfileDuration = 0;
|
||||
_ProfileNumOfSerialSteps = 1;
|
||||
|
||||
List<Profile> profiles = new List<Profile>();
|
||||
int k = 0;
|
||||
while( k < _SerSteps.Count)
|
||||
{
|
||||
Profile p = GetProfile(k);
|
||||
profiles.Add(p);
|
||||
k += _ProfileNumOfSerialSteps;
|
||||
}
|
||||
|
||||
// for (int i = 0; i < _SerSteps.Count; i++)
|
||||
//profiles.Add(GetProfile(i));
|
||||
|
||||
foreach (Profile p in profiles)
|
||||
if (!_Client.IsProgrammable(p))
|
||||
return false;
|
||||
|
||||
// In cases below, overheat/overcool alarm will sound immediately.
|
||||
// Limits can be set to 50 °C from temperature.
|
||||
for (int i = 1; i < _SerSteps.Count; i++)
|
||||
{
|
||||
Step step1 = _SerSteps[i - 1];
|
||||
Step step2 = _SerSteps[i];
|
||||
|
||||
if (step1.T < 40 && step2.T < 40)
|
||||
if (step2.T > step1.T + 50)
|
||||
return false;
|
||||
|
||||
if (step1.T > 40 && step2.T > 40)
|
||||
if (step2.T < step1.T - 50)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
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
|
||||
{
|
||||
_TaskProgress = _Client.Progress();
|
||||
}
|
||||
catch
|
||||
{
|
||||
_TaskProgress = "Progress could not be retrieved from client.";
|
||||
}
|
||||
lastPolled = DateTime.Now;
|
||||
}
|
||||
|
||||
System.Threading.Thread.Sleep(100);
|
||||
|
||||
if (_Status == TaskStatus.AbortRequested)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_Client.Stop())
|
||||
_Status = TaskStatus.Aborted;
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
_isKicking = true;
|
||||
}
|
||||
_isKicking = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private Double _NewProfileDuration = 0; // Duration of new profile in minutes
|
||||
private int _ProfileNumOfSerialSteps = 1; // Number of steps from serial step list performed in new profile.
|
||||
|
||||
|
||||
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;
|
||||
_NewProfileDuration = 0;
|
||||
_ProfileNumOfSerialSteps = 1;
|
||||
|
||||
while (_Status == TaskStatus.IsRunning)
|
||||
{
|
||||
if (DateTime.Now > endOfCurrentProgram)
|
||||
{
|
||||
iCurrentSerialStep += _ProfileNumOfSerialSteps;
|
||||
|
||||
// Last step has been performed?
|
||||
if (iCurrentSerialStep > _SerSteps.Count - 1)
|
||||
{
|
||||
_Client.Stop();
|
||||
_Status = TaskStatus.Finished;
|
||||
AddEventLog("Last step performed");
|
||||
continue;
|
||||
}
|
||||
|
||||
currentStep = _SerSteps[iCurrentSerialStep];
|
||||
|
||||
Profile newProfile = GetProfile(iCurrentSerialStep);
|
||||
|
||||
|
||||
if (_ProfileNumOfSerialSteps > 1)
|
||||
{
|
||||
if(newProfile.Loops.Count == 1 )
|
||||
AddEventLog("Program : " + string.Format("{0:0} serial steps, loop {1}", _ProfileNumOfSerialSteps, newProfile.Loops[0].ToString()));
|
||||
else
|
||||
AddEventLog("Program : " + string.Format("{0:0} serial steps, no loops", _ProfileNumOfSerialSteps));
|
||||
}
|
||||
else
|
||||
AddEventLog("Single step : " + currentStep.ToString());
|
||||
|
||||
|
||||
|
||||
RestartClient(newProfile);
|
||||
|
||||
|
||||
|
||||
if (_Status != TaskStatus.IsRunning)
|
||||
continue;
|
||||
|
||||
// Update variables
|
||||
startOfCurrentProgram = DateTime.Now;
|
||||
endOfCurrentProgram = DateTime.Now.AddMinutes(_NewProfileDuration);
|
||||
lastPolled = DateTime.Now;
|
||||
}
|
||||
|
||||
|
||||
// Poll only every 'PollingIntervalSeconds' seconds
|
||||
if (DateTime.Now > lastPolled.AddSeconds(PollingIntervalSeconds))
|
||||
{
|
||||
// Is finished?
|
||||
try
|
||||
{
|
||||
if (_Client.IsFinished())
|
||||
{
|
||||
_Status = TaskStatus.Interrupted; // Profile did not finish, client did
|
||||
continue;
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
try
|
||||
{
|
||||
double taskRunTime = (DateTime.Now - _startThread).TotalMinutes;
|
||||
double pTest = Math.Min(100, Math.Floor(taskRunTime / _Profile.DurationMin * 100));
|
||||
|
||||
double stepRuntime = (DateTime.Now - startOfCurrentProgram).TotalMinutes;
|
||||
double pStep = Math.Min(100,Math.Floor(stepRuntime / _NewProfileDuration * 100));
|
||||
|
||||
double taskTimeRemain = _Profile.DurationMin - taskRunTime;
|
||||
double taskTimeRemainHrs = Math.Floor(taskTimeRemain / 60);
|
||||
double taskTimeRemainMin = Math.Floor(taskTimeRemain - 60 * taskTimeRemainHrs);
|
||||
|
||||
_TaskProgress = String.Format("Step #{0:00}/{1:00} progress {2:0}%, test progress {3:0}%, remaining test time {4:0}h{5:00}m", iCurrentSerialStep + 1, _Profile.SerializedStepList.Count, pStep, pTest, taskTimeRemainHrs, taskTimeRemainMin);
|
||||
}
|
||||
catch
|
||||
{
|
||||
_TaskProgress = "Progress could not be calculated.";
|
||||
}
|
||||
lastPolled = DateTime.Now;
|
||||
}
|
||||
|
||||
|
||||
System.Threading.Thread.Sleep(200);
|
||||
|
||||
if (_Status == TaskStatus.AbortRequested)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_Client.Stop())
|
||||
_Status = TaskStatus.Aborted;
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
_isKicking = true;
|
||||
}
|
||||
_isKicking = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void RestartClient(Profile newProfile)
|
||||
{
|
||||
// Stop client
|
||||
try
|
||||
{
|
||||
if (!_Client.Stop())
|
||||
{
|
||||
_Status = TaskStatus.Interrupted;
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_Status = TaskStatus.ExceptionOccured;
|
||||
_TaskProgress = string.Format("Client Stop() exception: {0}", ex.Message);
|
||||
AddEventLog(_TaskProgress);
|
||||
return;
|
||||
}
|
||||
|
||||
System.Threading.Thread.Sleep(1000);
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Write profile
|
||||
try
|
||||
{
|
||||
if (!_Client.WriteProfile(newProfile))
|
||||
{
|
||||
_Status = TaskStatus.Interrupted;
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_Status = TaskStatus.ExceptionOccured;
|
||||
_TaskProgress = string.Format("Client WriteProfile() exception: {0}", ex.Message);
|
||||
AddEventLog(_TaskProgress);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Start client
|
||||
try
|
||||
{
|
||||
//AddEventLog("RestartClient.Start");
|
||||
if (!_Client.Start())
|
||||
{
|
||||
_Status = TaskStatus.Interrupted;
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_Status = TaskStatus.ExceptionOccured;
|
||||
_TaskProgress = string.Format("Client Start() exception: {0}", ex.Message);
|
||||
AddEventLog(_TaskProgress);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Profile GetProfile(int iStep)
|
||||
{
|
||||
Step step = _SerSteps[iStep].DeepClone();
|
||||
// Duration of programmed step is 15 minutes longer than profile
|
||||
step.DurationMin += 15;
|
||||
|
||||
_NewProfileDuration = _SerSteps[iStep].DurationMin;
|
||||
_ProfileNumOfSerialSteps = 1;
|
||||
|
||||
List<Step> steps = new List<Step>();
|
||||
steps.Add(step);
|
||||
|
||||
|
||||
// Loops
|
||||
List<Loop> loops = new List<Loop>();
|
||||
|
||||
// Options
|
||||
List<ProfileOption> options = new List<ProfileOption>();
|
||||
options.Add(ProfileOption.LHL113_EndModeOff); // Shut down client for safety
|
||||
|
||||
// Create profile
|
||||
return new Profile(_Profile.Title, steps, loops, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 @@
|
||||
ae4a20f7096bc6f8a600f5bcf410b2ab95b95f6c
|
||||
@@ -0,0 +1,2 @@
|
||||
\\silicium\software\MASER software\Source\ChamChat\Client_LHL113\obj\Release\Client_LHL113.csproj.AssemblyReference.cache
|
||||
\\silicium\software\MASER software\Source\ChamChat\Client_LHL113\obj\Release\Client_LHL113.csproj.CoreCompileInputs.cache
|
||||
Binary file not shown.
Reference in New Issue
Block a user