first commit
This commit is contained in:
151
ChamChat/Client_TSx/Client.TSx.Specific.cs
Normal file
151
ChamChat/Client_TSx/Client.TSx.Specific.cs
Normal file
@@ -0,0 +1,151 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace ChamChat
|
||||
{
|
||||
public partial class TSx_Client : Client
|
||||
{
|
||||
public bool ShiftToA()
|
||||
{
|
||||
string sAddr = _Address.ToString();
|
||||
string cmd;
|
||||
string read;
|
||||
|
||||
cmd = sAddr + ", TAREA?";
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms);
|
||||
|
||||
// If moving, wait to finish
|
||||
if (read.Contains("MOVE"))
|
||||
{
|
||||
bool moving = true;
|
||||
while (moving)
|
||||
{
|
||||
System.Threading.Thread.Sleep(2000);
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms);
|
||||
if (!read.Contains("MOVE"))
|
||||
moving = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Already in Cold
|
||||
if (read.Contains("C"))
|
||||
return true;
|
||||
|
||||
|
||||
cmd = sAddr + ", MODE, TAREAMOVE";
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms);
|
||||
|
||||
System.Threading.Thread.Sleep(5000); // Wait for move to finish
|
||||
|
||||
cmd = sAddr + ", TAREA?";
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms);
|
||||
|
||||
// If moving, wait to finish
|
||||
if (read.Contains("MOVE"))
|
||||
{
|
||||
bool moving = true;
|
||||
while (moving)
|
||||
{
|
||||
System.Threading.Thread.Sleep(2000);
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms);
|
||||
if (!read.Contains("MOVE"))
|
||||
moving = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Already in Cold
|
||||
if (read.Contains("C"))
|
||||
return true;
|
||||
|
||||
// Not in Cold, not moving towards cold
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool ShiftToB()
|
||||
{
|
||||
string sAddr = _Address.ToString();
|
||||
string cmd;
|
||||
string read;
|
||||
|
||||
cmd = sAddr + ", TAREA?";
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms);
|
||||
|
||||
// If moving, wait to finish
|
||||
if (read.Contains("MOVE"))
|
||||
{
|
||||
bool moving = true;
|
||||
while (moving)
|
||||
{
|
||||
System.Threading.Thread.Sleep(2000);
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms);
|
||||
if (!read.Contains("MOVE"))
|
||||
moving = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Already in Hot
|
||||
if (read.Contains("H"))
|
||||
return true;
|
||||
|
||||
|
||||
cmd = sAddr + ", MODE, TAREAMOVE";
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms);
|
||||
|
||||
System.Threading.Thread.Sleep(5000); // Wait for move to finish
|
||||
|
||||
cmd = sAddr + ", TAREA?";
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms);
|
||||
|
||||
// If moving, wait to finish
|
||||
if (read.Contains("MOVE"))
|
||||
{
|
||||
bool moving = true;
|
||||
while (moving)
|
||||
{
|
||||
System.Threading.Thread.Sleep(2000);
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms);
|
||||
if (!read.Contains("MOVE"))
|
||||
moving = false;
|
||||
}
|
||||
}
|
||||
|
||||
// In Hot
|
||||
if (read.Contains("H"))
|
||||
return true;
|
||||
|
||||
// Not in Hot, not moving towards Hot
|
||||
return false;
|
||||
}
|
||||
|
||||
public Boolean AwaitMoving(Int32 timeOutSec)
|
||||
{
|
||||
string sAddr = _Address.ToString();
|
||||
string cmd = sAddr + ", TAREA?";;
|
||||
string read;
|
||||
|
||||
DateTime dtTimeOut = DateTime.Now.AddSeconds(timeOutSec);
|
||||
while (DateTime.Now < dtTimeOut)
|
||||
{
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms);
|
||||
if (!read.Contains("MOVE"))
|
||||
return true;
|
||||
System.Threading.Thread.Sleep(2000);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public Double CurrentTemperature()
|
||||
{
|
||||
string sAddr = _Address.ToString();
|
||||
string cmd;
|
||||
string read;
|
||||
|
||||
cmd = sAddr + ", TEMP?"; // See page 36
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms,1);
|
||||
return Double.Parse(read.Split(',')[6]);
|
||||
}
|
||||
}
|
||||
}
|
||||
724
ChamChat/Client_TSx/Client.TSx.cs
Normal file
724
ChamChat/Client_TSx/Client.TSx.cs
Normal file
@@ -0,0 +1,724 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using ChamChat.Models;
|
||||
|
||||
|
||||
namespace ChamChat
|
||||
{
|
||||
public partial class TSx_Client : Client
|
||||
{
|
||||
private const Int32 _OptionRange = 1000;
|
||||
//private const string _RAM = "RAM:20";
|
||||
private const int _RAM = 20;
|
||||
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 TSx_Client(Int32 MIDS, ClientType Type)
|
||||
: base(MIDS, Type)
|
||||
{
|
||||
|
||||
// Set options available in client
|
||||
_Parameters = new List<Parameter>();
|
||||
_Parameters.Add(Parameter.T);
|
||||
_Parameters.Add(Parameter.PreTemp);
|
||||
_Parameters.Add(Parameter.Tlimit);
|
||||
_Parameters.Add(Parameter.ProceedWithNextStep);
|
||||
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override Profile ReadProfile(int RAM, ref System.ComponentModel.BackgroundWorker bgw)
|
||||
{
|
||||
string sAddr = _Address.ToString();
|
||||
string cmd;
|
||||
string read;
|
||||
|
||||
string ram = string.Format("RAM:{0:00}", RAM);
|
||||
|
||||
|
||||
|
||||
// Communicate with client
|
||||
cmd = sAddr + ",PRGMREAD," + ram;
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms, 1);
|
||||
bgw.ReportProgress(8);
|
||||
|
||||
cmd = sAddr + ",LISTTEMP?";
|
||||
if (!bgw.CancellationPending)
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms, 1);
|
||||
string LISTTEMP = read;
|
||||
bgw.ReportProgress(16);
|
||||
|
||||
cmd = sAddr + ",LISTPREAI?";
|
||||
if (!bgw.CancellationPending)
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms, 1);
|
||||
string LISTPREAI = read;
|
||||
bgw.ReportProgress(24);
|
||||
|
||||
cmd = sAddr + ",LISTPRE?";
|
||||
if (!bgw.CancellationPending)
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms, 1);
|
||||
string LISTPRE = read;
|
||||
bgw.ReportProgress(32);
|
||||
|
||||
cmd = sAddr + ",LISTTIME?";
|
||||
if (!bgw.CancellationPending)
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms, 1);
|
||||
string LISTTIME = read;
|
||||
bgw.ReportProgress(40);
|
||||
|
||||
cmd = sAddr + ",LISTCYCLE?";
|
||||
if (!bgw.CancellationPending)
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms, 1);
|
||||
string LISTCYCLE = read;
|
||||
bgw.ReportProgress(48);
|
||||
|
||||
cmd = sAddr + ",LISTSTARTPOSITION?";
|
||||
if (!bgw.CancellationPending)
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms, 1);
|
||||
string LISTSTARTPOSITION = read;
|
||||
bgw.ReportProgress(56);
|
||||
|
||||
cmd = sAddr + ",LISTEND?";
|
||||
if (!bgw.CancellationPending)
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms, 1);
|
||||
string LISTEND = read;
|
||||
bgw.ReportProgress(64);
|
||||
|
||||
cmd = sAddr + ",LISTNAME?";
|
||||
if (!bgw.CancellationPending)
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms, 1);
|
||||
string LISTNAME = read;
|
||||
bgw.ReportProgress(72);
|
||||
|
||||
cmd = sAddr + ",LISTSENSOR?";
|
||||
if (!bgw.CancellationPending)
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms, 1); // Not used in software.
|
||||
string LISTSENSOR = read;
|
||||
bgw.ReportProgress(80);
|
||||
|
||||
cmd = sAddr + ",LISTTEMPLIMIT?";
|
||||
if (!bgw.CancellationPending)
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms, 1);
|
||||
string LISTTEMPLIMIT = read;
|
||||
bgw.ReportProgress(88);
|
||||
|
||||
// 01728 test
|
||||
// 4,PRGMREAD,RAM:20
|
||||
// 4,LISTTEMPLIMIT?
|
||||
// 4,PRGMREADEND
|
||||
|
||||
cmd = sAddr + ",PRGMREADEND";
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms, 1);
|
||||
bgw.ReportProgress(96);
|
||||
|
||||
|
||||
Profile profile = new Profile();
|
||||
|
||||
// Cancel read out
|
||||
if (bgw.CancellationPending)
|
||||
{
|
||||
profile.Title = "Cancelled";
|
||||
return profile;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
// High temperature
|
||||
double TB = Double.Parse(LISTTEMP.Split(',')[0]);
|
||||
string tB = LISTTIME.Split(',')[1].Trim();
|
||||
double hrsB = Double.Parse(tB.Split(':')[0]);
|
||||
double minB = Double.Parse(tB.Split(':')[1]);
|
||||
double preTB = Double.Parse(LISTPRE.Split(',')[0]);
|
||||
double HL = Double.Parse(LISTTEMPLIMIT.Split(',')[0]);
|
||||
|
||||
|
||||
// Low temperature
|
||||
double TA = Double.Parse(LISTTEMP.Split(',')[1]);
|
||||
string tA = LISTTIME.Split(',')[2].Trim();
|
||||
double hrsA = Double.Parse(tA.Split(':')[0]);
|
||||
double minA = Double.Parse(tA.Split(':')[1]);
|
||||
double preTA = Double.Parse(LISTPRE.Split(',')[1]);
|
||||
double LL = Double.Parse(LISTTEMPLIMIT.Split(',')[1]);
|
||||
|
||||
// Number of cycles
|
||||
Int32 numOfCycles = Int32.Parse(LISTCYCLE);
|
||||
|
||||
// Name
|
||||
String name = LISTNAME;
|
||||
|
||||
// Options: page 44 & 72
|
||||
List<ProfileOption> options = new List<ProfileOption>();
|
||||
if (LISTPREAI == "ON")
|
||||
options.Add(ProfileOption.TSx_PreTempAuto);
|
||||
else
|
||||
options.Add(ProfileOption.TSx_PreTempManual);
|
||||
|
||||
|
||||
switch (LISTEND)
|
||||
{
|
||||
case "HEATRETURN":
|
||||
options.Add(ProfileOption.TSx_EndModeHeatReturn);
|
||||
break;
|
||||
case "SETUP":
|
||||
options.Add(ProfileOption.TSx_EndModeSetup);
|
||||
break;
|
||||
case "DEFROST":
|
||||
options.Add(ProfileOption.TSx_EndModeDefrost);
|
||||
break;
|
||||
case "DRY":
|
||||
options.Add(ProfileOption.TSx_EndModeDry);
|
||||
break;
|
||||
default:
|
||||
options.Add(ProfileOption.TSx_EndModeOff);
|
||||
break;
|
||||
}
|
||||
|
||||
Step B = new Step(hrsB * 60 + minB);
|
||||
B.T = TB;
|
||||
B.PreTemp = preTB;
|
||||
B.LimitT = HL;
|
||||
|
||||
Step A = new Step(hrsA * 60 + minA);
|
||||
A.T = TA;
|
||||
A.PreTemp = preTA;
|
||||
A.LimitT = LL;
|
||||
|
||||
List<Step> steps = new List<Step>();
|
||||
|
||||
|
||||
// If test should start in high, then start with B
|
||||
if (LISTSTARTPOSITION == "H")
|
||||
{
|
||||
steps.Add(B);
|
||||
steps.Add(A);
|
||||
}
|
||||
else
|
||||
{
|
||||
steps.Add(A);
|
||||
steps.Add(B);
|
||||
}
|
||||
|
||||
Loop loop = new Loop(numOfCycles, 0, 1);
|
||||
List<Loop> loops = new List<Loop>();
|
||||
loops.Add(loop);
|
||||
|
||||
// Create profile
|
||||
profile = new Profile(name, steps, loops, options);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
return profile;
|
||||
}
|
||||
|
||||
|
||||
public override Boolean WriteProfile(Profile profile)
|
||||
{
|
||||
// Pass a dummy bacckgroundworker and the default RAM
|
||||
return WriteProfile(profile, _RAM);
|
||||
}
|
||||
|
||||
public override Boolean WriteProfile(Profile profile, int RAM)
|
||||
{
|
||||
// Pass a dummy bacckgroundworker with no event subscriptions
|
||||
System.ComponentModel.BackgroundWorker bgw = new System.ComponentModel.BackgroundWorker();
|
||||
return WriteProfile(profile, _RAM, ref bgw);
|
||||
}
|
||||
|
||||
public override Boolean WriteProfile(Profile profile, int RAM, ref System.ComponentModel.BackgroundWorker bgw)
|
||||
{
|
||||
|
||||
|
||||
// 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 sAddr = _Address.ToString();
|
||||
string cmd;
|
||||
string read;
|
||||
|
||||
string ram = string.Format("RAM:{0:00}", RAM);
|
||||
|
||||
|
||||
Step A, B; // A is low temperature step, B is high temperature step
|
||||
string startPosition;
|
||||
if (profile.Steps[0].T < profile.Steps[1].T)
|
||||
{
|
||||
A = profile.Steps[0];
|
||||
B = profile.Steps[1];
|
||||
startPosition = "L";
|
||||
}
|
||||
else
|
||||
{
|
||||
A = profile.Steps[1];
|
||||
B = profile.Steps[0];
|
||||
startPosition = "H";
|
||||
}
|
||||
|
||||
|
||||
#warning report Progress to bgw
|
||||
bgw.ReportProgress(8);
|
||||
|
||||
|
||||
|
||||
|
||||
// Communicate with client
|
||||
cmd = sAddr + ", PRGMWRITE," + ram;
|
||||
if (!bgw.CancellationPending)
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms);
|
||||
|
||||
|
||||
|
||||
|
||||
// Name of program
|
||||
cmd = sAddr + ", NAME, " + title;
|
||||
if (!bgw.CancellationPending)
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms);
|
||||
|
||||
|
||||
// Temperatures
|
||||
cmd = sAddr + ", TEMP, " + string.Format("S{0:000},{1:+#;-#00}", B.T, A.T);
|
||||
if (A.T == 0)
|
||||
cmd = sAddr + ", TEMP, " + string.Format("S{0:000}, 000", B.T);
|
||||
if (!bgw.CancellationPending)
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms);
|
||||
|
||||
|
||||
// Preheat and precool
|
||||
cmd = sAddr + ", PRE, " + string.Format("{0:000},{1:+#;-#00}", B.PreTemp, A.PreTemp);
|
||||
if (A.PreTemp == 0)
|
||||
cmd = sAddr + ", PRE, " + string.Format("{0:000}, 000", B.PreTemp);
|
||||
if (!bgw.CancellationPending)
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms);
|
||||
|
||||
|
||||
// Dwell times
|
||||
int hrsA = (int)Math.Floor(A.DurationMin / 60);
|
||||
int minA = (int)Math.Floor(A.DurationMin - 60 * hrsA);
|
||||
int hrsB = (int)Math.Floor(B.DurationMin / 60);
|
||||
int minB = (int)Math.Floor(B.DurationMin - 60 * hrsB);
|
||||
cmd = sAddr + ", TIME, " + string.Format("00:00, {0:00}:{1:00}, {2:00}:{3:00}", hrsB, minB, hrsA, minA);
|
||||
if (!bgw.CancellationPending)
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms);
|
||||
|
||||
|
||||
// Start position
|
||||
cmd = sAddr + ", STARTPOSITION, " + startPosition;
|
||||
if (!bgw.CancellationPending)
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms);
|
||||
|
||||
|
||||
// Auto preheat/precool (default is manual): page 44 & 72
|
||||
string preai = "OFF";
|
||||
if (profile.Options.Contains(ProfileOption.TSx_PreTempAuto))
|
||||
preai = "ON";
|
||||
cmd = sAddr + ", PREAI, " + preai;
|
||||
if (!bgw.CancellationPending)
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms);
|
||||
|
||||
|
||||
// Number of cycles
|
||||
int numOfCycles = 1;
|
||||
if (profile.Loops.Count > 0)
|
||||
numOfCycles = profile.Loops[0].N;
|
||||
cmd = sAddr + ", CYCLE, " + string.Format("{0:0000}", numOfCycles);
|
||||
if (!bgw.CancellationPending)
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms);
|
||||
|
||||
|
||||
// End mode (default is off)
|
||||
string end = "OFF";
|
||||
if (profile.Options.Contains(ProfileOption.TSx_EndModeHeatReturn))
|
||||
end = "HEATRETURN";
|
||||
if (profile.Options.Contains(ProfileOption.TSx_EndModeSetup))
|
||||
end = "SETUP";
|
||||
if (profile.Options.Contains(ProfileOption.TSx_EndModeDefrost))
|
||||
end = "DEFROST";
|
||||
if (profile.Options.Contains(ProfileOption.TSx_EndModeDry))
|
||||
end = "DRY";
|
||||
cmd = sAddr + ", END, " + end;
|
||||
if (!bgw.CancellationPending)
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms);
|
||||
|
||||
|
||||
// Overheat/Overcool protection
|
||||
cmd = sAddr + ", TEMPLIMIT, " + string.Format("{0:000},{1:+#;-#00}", B.LimitT, A.LimitT);
|
||||
if (A.LimitT == 0)
|
||||
cmd = sAddr + ", TEMPLIMIT, " + string.Format("{0:000}, 000", B.LimitT);
|
||||
|
||||
if (!bgw.CancellationPending)
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms);
|
||||
|
||||
// Always perform PRGMWRITEEND, also if bgw.CancellationPending
|
||||
cmd = sAddr + ", PRGMWRITEEND," + ram;
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms);
|
||||
|
||||
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 steps 2
|
||||
// number of loops < 2
|
||||
// number of cycles < 9999
|
||||
// -77 < tA < 0
|
||||
// 60 < tB < 205
|
||||
// -77 < Pre-tA < 0
|
||||
// 60 <Pre-tB < 205
|
||||
// Limit overcool is 0..50 °C below tA
|
||||
// Limit overheat is 0..50 °C above tB
|
||||
// Ramp control not used
|
||||
|
||||
double[] preH = new double[2]{60,205};
|
||||
double[] preC = new double[2] { -77, 0 };
|
||||
double[] tB = new double[2] { 60, 205 };
|
||||
double[] tA = new double[2] { -77, 0 };
|
||||
|
||||
|
||||
// Specifics
|
||||
if (_Type == ClientType.TSD100S)
|
||||
{
|
||||
preH[1] = 305;
|
||||
tB[1] = 305;
|
||||
}
|
||||
if (_Type == ClientType.TSD100 && _MIDS == 1728)
|
||||
{
|
||||
preH[0] = 30;
|
||||
tB[0] = 30;
|
||||
}
|
||||
if (_Type == ClientType.TSE11A)
|
||||
{
|
||||
preC[0] = -82;
|
||||
}
|
||||
|
||||
|
||||
foreach (Step step in profile.Steps)
|
||||
if (step.RampCtrlT)
|
||||
{
|
||||
_ClientMessages.Add(new ClientMessage("Program cannot be written to client: ramp control must be off"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (profile.Steps.Count != 2)
|
||||
{
|
||||
_ClientMessages.Add(new ClientMessage("Program cannot be written to client: there must be 2 steps"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (profile.Loops.Count > 1)
|
||||
return false;
|
||||
|
||||
if(profile.Loops.Count == 1)
|
||||
if(profile.Loops[0].N > 9999)
|
||||
{
|
||||
_ClientMessages.Add(new ClientMessage("Program cannot be written to client: number of repeats must ben smaller than 9999"));
|
||||
return false;
|
||||
}
|
||||
|
||||
Step A, B; // A is low temperature step, B is high temperature step
|
||||
if (profile.Steps[0].T < profile.Steps[1].T)
|
||||
{
|
||||
A = profile.Steps[0];
|
||||
B = profile.Steps[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
A = profile.Steps[1];
|
||||
B = profile.Steps[0];
|
||||
}
|
||||
|
||||
// Step A
|
||||
if (A.PreTemp < preC[0] || A.PreTemp > preC[1])
|
||||
{
|
||||
string msg = string.Format("pre-cool must be in range {0:0} to {1:0} °C", preC[0] , preC[1]);
|
||||
_ClientMessages.Add(new ClientMessage("Program cannot be written to client: "+msg));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (A.T < tA[0] || A.T > tA[1])
|
||||
{
|
||||
string msg = string.Format("cold temperature must be in range {0:0} to {1:0} °C", tA[0], tA[1]);
|
||||
_ClientMessages.Add(new ClientMessage("Program cannot be written to client: " + msg));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (A.LimitT > A.T || A.LimitT < A.T-50)
|
||||
{
|
||||
string msg = string.Format("cold limit must be in range {0:0} to {1:0} °C", A.T - 50, A.T);
|
||||
_ClientMessages.Add(new ClientMessage("Program cannot be written to client: " + msg));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Step B
|
||||
if (B.PreTemp < preH[0] || B.PreTemp > preH[1])
|
||||
{
|
||||
string msg = string.Format("pre-heat must be in range {0:0} to {1:0} °C", preH[0], preH[1]);
|
||||
_ClientMessages.Add(new ClientMessage("Program cannot be written to client: " + msg));
|
||||
return false;
|
||||
}
|
||||
if (B.T < tB[0] || B.T > tB[1])
|
||||
{
|
||||
string msg = string.Format("hot temperature must be in range {0:0} to {1:0} °C", tB[0], tB[1]);
|
||||
_ClientMessages.Add(new ClientMessage("Program cannot be written to client: " + msg));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (B.LimitT < B.T || B.LimitT > B.T +50)
|
||||
{
|
||||
string msg = string.Format("hot limit must be in range {0:0} to {1:0} °C", B.T, B.T + 50);
|
||||
_ClientMessages.Add(new ClientMessage("Program cannot be written to client: " + msg));
|
||||
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 34 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;
|
||||
|
||||
// Clear number of remaining cycles
|
||||
cmd = sAddr + ", OPECYCLERESET"; // See ASSIGN page 63
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms,1);
|
||||
|
||||
string ram = string.Format("RAM:{0:00}", _RAM);
|
||||
|
||||
// Assign the profile
|
||||
cmd = sAddr + ", ASSIGN, " + ram; // See ASSIGN page 66
|
||||
if(!DataTransfer(cmd,out read, _ReturnDataWaitms))
|
||||
return false;
|
||||
|
||||
if (_Profile.Options.Contains(ProfileOption.TSx_StartNoSetup))
|
||||
cmd = sAddr + ", OPETEST"; // See page 61
|
||||
else
|
||||
cmd = sAddr + ", OPESETUPEND"; // See page 61
|
||||
|
||||
return DataTransfer(cmd,out read, _ReturnDataWaitms);
|
||||
}
|
||||
|
||||
|
||||
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, _ReturnDataWaitms);
|
||||
|
||||
if (read.Contains("POWER-OFF"))
|
||||
return true;
|
||||
|
||||
if (read.Contains("STANDBY"))
|
||||
return true;
|
||||
|
||||
if (read.Contains("END-SETUP"))
|
||||
return true;
|
||||
|
||||
if (read.Contains("END-READY"))
|
||||
return true;
|
||||
|
||||
if (read.Contains("END-OFF"))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public override Boolean Stop()
|
||||
{
|
||||
string sAddr = _Address.ToString();
|
||||
string cmd;
|
||||
string read;
|
||||
cmd = sAddr + ", OPESTANDBY";
|
||||
return DataTransfer(cmd, out read, _ReturnDataWaitms);
|
||||
}
|
||||
|
||||
|
||||
public override Boolean IsOnline()
|
||||
{
|
||||
try
|
||||
{
|
||||
string sAddr = _Address.ToString();
|
||||
string cmd;
|
||||
string read;
|
||||
cmd = sAddr + ", MODEL?";
|
||||
DataTransfer(cmd, out read, _ReturnDataWaitms);
|
||||
return (read.ToLower().Contains("tsd") || read.ToLower().Contains("tse"));
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public override String Progress()
|
||||
{
|
||||
string sAddr = _Address.ToString();
|
||||
string cmd;
|
||||
string read;
|
||||
cmd = sAddr + ", CYCLE?"; // See page 38
|
||||
DataTransfer(cmd,out read, _ReturnDataWaitms,1);
|
||||
Int32 n = Int32.Parse(read.Split(',')[0]);
|
||||
Int32 N = Int32.Parse(read.Split(',')[1]);
|
||||
double t = CurrentTemperature();
|
||||
return String.Format("{0:0}/{1:0} cycles executed. Temperature is {2:0} °C", n, N, t);
|
||||
}
|
||||
|
||||
|
||||
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 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 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 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("CYCLE?"))
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
63
ChamChat/Client_TSx/Client_TSx.csproj
Normal file
63
ChamChat/Client_TSx/Client_TSx.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>{A863C309-E15C-4EA1-82F2-BDFE83C96D15}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>ChamChat</RootNamespace>
|
||||
<AssemblyName>TSx</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="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Task.TSx.cs" />
|
||||
<Compile Include="Client.TSx.cs" />
|
||||
<Compile Include="Client.TSx.Specific.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_TSx/Properties/AssemblyInfo.cs
Normal file
36
ChamChat/Client_TSx/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")]
|
||||
657
ChamChat/Client_TSx/Task.TSx.cs
Normal file
657
ChamChat/Client_TSx/Task.TSx.cs
Normal file
@@ -0,0 +1,657 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using ChamChat.Models;
|
||||
|
||||
namespace ChamChat
|
||||
{
|
||||
public class TSx_Task : Task
|
||||
{
|
||||
// Each step is separately programmed to the TSE11.
|
||||
// Steps are programmed at 110% of required step duration.
|
||||
// End of program is always of shutdown type to avoid stressing to much. (Excluding last step)
|
||||
// If next step is of different type (tA or tB), then the next temperature is prepared in other chamber.
|
||||
// Default temperatures are 0 °C for tA and 85 °C for tB.
|
||||
|
||||
public TSx_Task(Client Client, Profile Profile)
|
||||
: base(Client, Profile)
|
||||
{
|
||||
_Profile = Profile;
|
||||
_Client = Client;
|
||||
_SerSteps = _Profile.SerializedStepList;
|
||||
|
||||
// Limit tA is overall limit
|
||||
_tAProfileLimit = 0;
|
||||
foreach (Step s in _SerSteps)
|
||||
if (s.LimitT < _tAProfileLimit)
|
||||
_tAProfileLimit = s.LimitT;
|
||||
|
||||
// Limit tB is overall limit
|
||||
_tBProfileLimit = 60;
|
||||
foreach (Step s in _SerSteps)
|
||||
if (s.LimitT > _tBProfileLimit)
|
||||
_tBProfileLimit = s.LimitT;
|
||||
}
|
||||
|
||||
private DateTime _dtIdlingStart = DateTime.Now.AddYears(10);
|
||||
|
||||
private const Int32 PollingIntervalSeconds = 10; // Interval in seconds for updating task progress
|
||||
private const Int32 maxIdlingTimeSec = 60;
|
||||
|
||||
private List<Step> _SerSteps;
|
||||
private double _tAProfileLimit = 0;
|
||||
private double _tBProfileLimit = 0;
|
||||
|
||||
|
||||
public override Boolean IsControlledProgrammable(Profile profile)
|
||||
{
|
||||
// Clear existing ClientMessages
|
||||
_Client.ClientMessages = new List<ClientMessage>();
|
||||
|
||||
|
||||
_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;
|
||||
}
|
||||
|
||||
|
||||
foreach (Profile p in profiles)
|
||||
if (!_Client.IsProgrammable(p))
|
||||
return false;
|
||||
|
||||
|
||||
// If subsequent tA resp. tB steps differ more than 50 °C, overheat/overcool alarm will sound immediately.
|
||||
// Limits can be set to 50 °C from temperature.
|
||||
|
||||
List<Step> tASteps = new List<Step>();
|
||||
List<Step> tBSteps = new List<Step>();
|
||||
|
||||
// Create list of all tA steps resp. tB steps
|
||||
foreach (Step s in _SerSteps)
|
||||
if (s.T > 25)
|
||||
tBSteps.Add(s);
|
||||
else
|
||||
tASteps.Add(s);
|
||||
|
||||
// Compare subsequent tA steps
|
||||
for (int i = 1; i < tASteps.Count; i++)
|
||||
{
|
||||
double t1 = tASteps[i - 1].T;
|
||||
double t2 = tASteps[i].T;
|
||||
|
||||
if (Math.Abs(t1 - t2) > 50)
|
||||
{
|
||||
string msg = string.Format("stepping from {0:0} to {1:0} will cause overcool alarm", t1, t2);
|
||||
_Client.ClientMessages.Add(new ClientMessage("Program cannot be written to client: " + msg));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Compare subsequent tB steps
|
||||
for (int i = 1; i < tBSteps.Count; i++)
|
||||
{
|
||||
double t1 = tBSteps[i - 1].T;
|
||||
double t2 = tBSteps[i].T;
|
||||
|
||||
if (Math.Abs(t1 - t2) > 50)
|
||||
{
|
||||
string msg = string.Format("stepping from {0:0} to {1:0} will cause overheat alarm", t1, t2);
|
||||
_Client.ClientMessages.Add(new ClientMessage("Program cannot be written to client: " + msg));
|
||||
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 { }
|
||||
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;
|
||||
Profile newProfile;
|
||||
|
||||
while (_Status == TaskStatus.IsRunning || _Status == TaskStatus.NextStepRequested)
|
||||
{
|
||||
|
||||
#warning Update 02/05/2016
|
||||
// Proceed with next step if it is not the last one.
|
||||
if (_Status == TaskStatus.NextStepRequested && iCurrentSerialStep < _SerSteps.Count - 1)
|
||||
{
|
||||
endOfCurrentProgram = DateTime.Now.AddYears(1);
|
||||
_ProfileNumOfSerialSteps = 1;
|
||||
}
|
||||
|
||||
|
||||
if (DateTime.Now > endOfCurrentProgram)
|
||||
{
|
||||
iCurrentSerialStep += _ProfileNumOfSerialSteps; // Is starting step of newProfile to be executed
|
||||
|
||||
// Last step has been performed?
|
||||
if (iCurrentSerialStep > _SerSteps.Count - 1)
|
||||
{
|
||||
_Client.Stop();
|
||||
_Status = TaskStatus.Finished;
|
||||
AddEventLog("Last step performed");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
newProfile = new Profile();
|
||||
try
|
||||
{
|
||||
//AddEventLog("Debugging: Getting profile for iCurrentSerialStep=" + iCurrentSerialStep.ToString());
|
||||
newProfile = GetProfile(iCurrentSerialStep);
|
||||
//AddEventLog("Debugging: Profile for iCurrentSerialStep: " + newProfile.ToString());
|
||||
}
|
||||
catch (Exception ex) { AddEventLog("GetProfile() error: " + ex.Message); }
|
||||
|
||||
|
||||
RestartClient(newProfile); // RestartClient sets TaskStatus to IsRunning if succesfull.
|
||||
|
||||
|
||||
if (_Status != TaskStatus.IsRunning)
|
||||
continue;
|
||||
|
||||
|
||||
// Update variables
|
||||
startOfCurrentProgram = DateTime.Now;
|
||||
endOfCurrentProgram = DateTime.Now.AddMinutes(_NewProfileDuration);
|
||||
lastPolled = DateTime.Now;
|
||||
|
||||
|
||||
// Update events
|
||||
try
|
||||
{
|
||||
Step s1 = newProfile.Steps[0];
|
||||
Step s2 = newProfile.Steps[1];
|
||||
//AddEventLog("Profile in client: " + newProfile.ToString());
|
||||
if (newProfile.Loops.Count == 1)
|
||||
AddEventLog(string.Format("Set conditions: {0:0}h{1:00} @ {2:0} °C, {3:0}h{4:00} @ {5:0} °C, {6:0} cycles", s1.Hours, s1.Minutes, s1.T, s2.Hours, s2.Minutes, s2.T, newProfile.Loops[0].N));
|
||||
else
|
||||
AddEventLog(string.Format("Set conditions: {0:0}h{1:00} @ {2:0} °C, {3:0}h{4:00} @ {5:0} °C", s1.Hours, s1.Minutes, s1.T, s2.Hours, s2.Minutes, s2.T));
|
||||
string 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); }
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Poll only every 'PollingIntervalSeconds' seconds
|
||||
if (DateTime.Now > lastPolled.AddSeconds(PollingIntervalSeconds))
|
||||
{
|
||||
// Is finished?
|
||||
try
|
||||
{
|
||||
if (_Client.IsFinished())
|
||||
{
|
||||
AddEventLog("Client finished, but task did not!");
|
||||
if (_dtIdlingStart < DateTime.Now.AddSeconds(-maxIdlingTimeSec))
|
||||
{
|
||||
AddEventLog("Debugging: _dtIdlingStart < DateTime.Now.AddSeconds(-maxIdlingTimeSec)");
|
||||
// _Status = TaskStatus.Interrupted; // Profile did not finish, client did
|
||||
//continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
_dtIdlingStart = DateTime.Now;
|
||||
AddEventLog("Debugging: _dtIdlingStart set to "+_dtIdlingStart.ToString());
|
||||
}
|
||||
}
|
||||
else
|
||||
_dtIdlingStart = DateTime.Now.AddYears(10);
|
||||
}
|
||||
catch { _dtIdlingStart = DateTime.Now.AddYears(10); } // 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 newProfileRuntime = (DateTime.Now - startOfCurrentProgram).TotalMinutes;
|
||||
double pNewProfile = Math.Min(100, Math.Floor(newProfileRuntime / _NewProfileDuration * 100));
|
||||
|
||||
|
||||
double profileTimeExecutedSoFar = newProfileRuntime;
|
||||
for (int i = 0; i < iCurrentSerialStep; i++)
|
||||
profileTimeExecutedSoFar += _SerSteps[i].DurationMin;
|
||||
|
||||
int serialStepNo = iCurrentSerialStep;
|
||||
double min = 0;
|
||||
for (int i = 0; i < _SerSteps.Count; i++)
|
||||
{
|
||||
min += _SerSteps[i].DurationMin;
|
||||
if (min > profileTimeExecutedSoFar)
|
||||
{
|
||||
serialStepNo = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
_TaskProgress = String.Format("Step #{0:00}/{1:00} progress {2:0}%, test progress {3:0}%, remaining test time {4:0}h{5:00}m", serialStepNo + 1, _Profile.SerializedStepList.Count, pNewProfile, pTest, taskTimeRemainHrs, taskTimeRemainMin);
|
||||
if (serialStepNo + 1 == _Profile.SerializedStepList.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(Profile newProfile)
|
||||
{
|
||||
// Stop client
|
||||
try
|
||||
{
|
||||
AddEventLog("Info: Stopping client");
|
||||
|
||||
|
||||
#warning Do not stop if this is the first parital profile
|
||||
|
||||
|
||||
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");
|
||||
|
||||
|
||||
|
||||
// Wait for move to end
|
||||
try
|
||||
{
|
||||
if (!((TSx_Client)_Client).AwaitMoving(60))
|
||||
{
|
||||
_Status = TaskStatus.Interrupted;
|
||||
AddEventLog("Time out (60 s) in RestartClient.AwaitMoving");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_Status = TaskStatus.ExceptionOccured;
|
||||
_TaskProgress = string.Format("Client AwaitMoving() exception: {0}", ex.Message);
|
||||
AddEventLog(_TaskProgress);
|
||||
return;
|
||||
}
|
||||
|
||||
// AddEventLog("Debugging: Client AwaitMoving done");
|
||||
|
||||
|
||||
|
||||
// Write profile
|
||||
try
|
||||
{
|
||||
AddEventLog("Info: Writing to client");
|
||||
if (!_Client.WriteProfile(newProfile))
|
||||
{
|
||||
_Status = TaskStatus.Interrupted;
|
||||
AddEventLog("Task interrupted while trying to write new profile to client!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_Status = TaskStatus.ExceptionOccured;
|
||||
_TaskProgress = string.Format("Client WriteProfile() exception: {0}", ex.Message);
|
||||
AddEventLog(_TaskProgress);
|
||||
return;
|
||||
}
|
||||
|
||||
AddEventLog("Info: Profile written to client");
|
||||
|
||||
|
||||
// Start client
|
||||
try
|
||||
{
|
||||
AddEventLog("Info: Starting client");
|
||||
if (!_Client.Start())
|
||||
{
|
||||
// Try to start again after 10 sec
|
||||
AddEventLog("First attempt to start client failed!");
|
||||
System.Threading.Thread.Sleep(10000);
|
||||
|
||||
if (!_Client.Start())
|
||||
{
|
||||
_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");
|
||||
|
||||
|
||||
#warning Update 02/05/2016
|
||||
_Status = TaskStatus.IsRunning;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private Profile GetProfile(int iStep)
|
||||
{
|
||||
Step nextStep = null;
|
||||
if (iStep + 1 < _SerSteps.Count)
|
||||
nextStep = _SerSteps[iStep + 1].DeepClone();
|
||||
|
||||
// Last tA set to client
|
||||
double tALastSet = 0;
|
||||
for (int i = 0; i < iStep; i++)
|
||||
if (_SerSteps[i].T < 40)
|
||||
tALastSet = _SerSteps[i].T;
|
||||
double tAsetting = Math.Min(0, tALastSet + 40); // As high as possible without exceeding limits of prev step
|
||||
|
||||
// Last tB set to client
|
||||
double tBLastSet = 0;
|
||||
for (int i = 0; i < iStep; i++)
|
||||
if (_SerSteps[i].T > 40)
|
||||
tBLastSet = _SerSteps[i].T;
|
||||
double tBsetting = Math.Max(60, tBLastSet - 40); // As low as possible without exceeding limits of prev step
|
||||
|
||||
|
||||
// Create standard steps with 1 min duration
|
||||
Step stdA = new Step(1);
|
||||
stdA.T = tAsetting;
|
||||
stdA.LimitT = tAsetting - 50; // Reset later
|
||||
stdA.PreTemp = tAsetting;
|
||||
Step stdB = new Step(1);
|
||||
stdB.T = tBsetting;
|
||||
stdB.LimitT = tBsetting + 50; // Reset later
|
||||
stdB.PreTemp = tBsetting;
|
||||
|
||||
Step step1 = _SerSteps[iStep].DeepClone();
|
||||
Step step2 = new Step(15);
|
||||
|
||||
// Programmed step is minimum 10 minutes, maxmimum 1.5 times the required step duration.
|
||||
// If multiple steps can be performed without restart, the duration is altered below.
|
||||
step1.DurationMin = Math.Max(10, Math.Round(1.5 * step1.DurationMin));
|
||||
|
||||
// Set time of restart to end of current step.
|
||||
// If multiple steps can be performed without restart, the duration is altered below.
|
||||
_NewProfileDuration = _SerSteps[iStep].DurationMin;
|
||||
_ProfileNumOfSerialSteps = 1;
|
||||
|
||||
// Remark: Area to start in is defined by client based on step order.
|
||||
if (step1.T > 40)
|
||||
{
|
||||
// Current step is tB, step 2 programmed to client must be tA
|
||||
step2 = stdA;
|
||||
if (nextStep != null)
|
||||
if (nextStep.T < 40)
|
||||
{
|
||||
// If next step is tA, then program it as is.
|
||||
step2 = nextStep.DeepClone();
|
||||
|
||||
//// The two steps can be run by client without restarting.
|
||||
//// If no restarting takes place, then the next opposite step is not being prepared. The previous retains.
|
||||
//step2.DurationMin = Math.Max(30, Math.Round(1.5 * step2.DurationMin));
|
||||
//step1.DurationMin = _SerSteps[iStep].DurationMin;
|
||||
//_NewProfileDuration = step1.DurationMin + step2.DurationMin;
|
||||
//_ProfileNumOfSerialSteps = 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Current step is tA, step 2 programmed to client must be tB
|
||||
step2 = stdB;
|
||||
if (nextStep != null)
|
||||
if (nextStep.T > 40)
|
||||
{
|
||||
// If next step is tB, then program it as is.
|
||||
step2 = nextStep.DeepClone();
|
||||
|
||||
//// The two steps can be run by client without restarting.
|
||||
//// If no restarting takes place, then the next opposite step is not being prepared. The previous retains.
|
||||
//step2.DurationMin = Math.Max(30, Math.Round(1.5 * step2.DurationMin));
|
||||
//step1.DurationMin = _SerSteps[iStep].DurationMin;
|
||||
//_NewProfileDuration = step1.DurationMin + step2.DurationMin;
|
||||
//_ProfileNumOfSerialSteps = 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Set PK
|
||||
step1.PK = _SerSteps[iStep].PK; // Set for Loop.ToString()
|
||||
step2.PK = _SerSteps[iStep].PK + 1;
|
||||
|
||||
|
||||
// If current step is start of a loop comprising 2 opposite steps, then create loop in newProfile and set end time of newProfile
|
||||
List<Loop> loops = new List<Loop>();
|
||||
int N = 0;
|
||||
foreach (Loop loop in _Profile.Loops)
|
||||
{
|
||||
if (loop.First == _SerSteps[iStep].PK && loop.Last == _SerSteps[iStep].PK + 1)
|
||||
{
|
||||
if ((step1.T < 40 && step2.T > 40) || (step1.T > 40 && step2.T < 40))
|
||||
{
|
||||
// Steps are in different chambers of client.
|
||||
N = loop.N;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (N != 0)
|
||||
{
|
||||
loops.Add(new Loop(N, 0, 1)); // Loop is always from 1st to 2nd step
|
||||
step1.DurationMin = _SerSteps[iStep].DurationMin;
|
||||
step2.DurationMin = nextStep.DurationMin;
|
||||
_NewProfileDuration = N * (step1.DurationMin + step2.DurationMin);
|
||||
_ProfileNumOfSerialSteps = 2 * N;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Set limits to max, but do not exceed profile limits
|
||||
if (step1.T < 40)
|
||||
{
|
||||
step1.LimitT = Math.Max(step1.T - 50, _tAProfileLimit);
|
||||
step2.LimitT = Math.Min(step2.T + 50, _tBProfileLimit);
|
||||
}
|
||||
else
|
||||
{
|
||||
step1.LimitT = Math.Min(step1.T + 50, _tBProfileLimit);
|
||||
step2.LimitT = Math.Max(step2.T - 50, _tAProfileLimit);
|
||||
}
|
||||
|
||||
|
||||
|
||||
List<Step> steps = new List<Step>();
|
||||
steps.Add(step1);
|
||||
steps.Add(step2);
|
||||
|
||||
|
||||
|
||||
List<ProfileOption> options = new List<ProfileOption>();
|
||||
options.Add(ProfileOption.TSx_EndModeOff); // Shut down client
|
||||
|
||||
|
||||
// NOTE: It is impossible to wait for setup, unless endofCurrentProgram is moved forwards.
|
||||
options.Add(ProfileOption.TSx_StartNoSetup); // Do not wait for setup
|
||||
//if (iStep == 0 && _Profile.Options.Contains(ProfileOption.TSE11A_StartSetupTest))
|
||||
// options.Add(ProfileOption.TSE11A_StartSetupTest); // Wait for setup in first step
|
||||
//else
|
||||
// options.Add(ProfileOption.TSE11A_StartNoSetup); // Do not wait for setup
|
||||
|
||||
|
||||
Profile newProfile = new Profile(_Profile.Title, steps, loops, options);
|
||||
return newProfile;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
BIN
ChamChat/Client_TSx/bin/Release/ChamChat.Models.dll
Normal file
BIN
ChamChat/Client_TSx/bin/Release/ChamChat.Models.dll
Normal file
Binary file not shown.
BIN
ChamChat/Client_TSx/bin/Release/ChamChat.Models.pdb
Normal file
BIN
ChamChat/Client_TSx/bin/Release/ChamChat.Models.pdb
Normal file
Binary file not shown.
BIN
ChamChat/Client_TSx/bin/Release/TSx.dll
Normal file
BIN
ChamChat/Client_TSx/bin/Release/TSx.dll
Normal file
Binary file not shown.
BIN
ChamChat/Client_TSx/bin/Release/TSx.pdb
Normal file
BIN
ChamChat/Client_TSx/bin/Release/TSx.pdb
Normal file
Binary file not shown.
@@ -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 @@
|
||||
0d605b8d358746cb8dedaee3da21912cbaeec1bd
|
||||
@@ -0,0 +1,9 @@
|
||||
\\silicium\software\MASER software\Source\ChamChat\Client_TSx\bin\Release\TSx.dll
|
||||
\\silicium\software\MASER software\Source\ChamChat\Client_TSx\bin\Release\TSx.pdb
|
||||
\\silicium\software\MASER software\Source\ChamChat\Client_TSx\bin\Release\ChamChat.Models.dll
|
||||
\\silicium\software\MASER software\Source\ChamChat\Client_TSx\bin\Release\ChamChat.Models.pdb
|
||||
\\silicium\software\MASER software\Source\ChamChat\Client_TSx\obj\Release\Client_TSx.csproj.AssemblyReference.cache
|
||||
\\silicium\software\MASER software\Source\ChamChat\Client_TSx\obj\Release\Client_TSx.csproj.CoreCompileInputs.cache
|
||||
\\silicium\software\MASER software\Source\ChamChat\Client_TSx\obj\Release\Client_TSx.csproj.CopyComplete
|
||||
\\silicium\software\MASER software\Source\ChamChat\Client_TSx\obj\Release\TSx.dll
|
||||
\\silicium\software\MASER software\Source\ChamChat\Client_TSx\obj\Release\TSx.pdb
|
||||
Binary file not shown.
BIN
ChamChat/Client_TSx/obj/Release/TSx.dll
Normal file
BIN
ChamChat/Client_TSx/obj/Release/TSx.dll
Normal file
Binary file not shown.
BIN
ChamChat/Client_TSx/obj/Release/TSx.pdb
Normal file
BIN
ChamChat/Client_TSx/obj/Release/TSx.pdb
Normal file
Binary file not shown.
Reference in New Issue
Block a user