first commit

This commit is contained in:
Wesley Hofman
2025-09-18 14:23:18 +02:00
commit 2f1f4199ad
293 changed files with 54467 additions and 0 deletions

View File

@@ -0,0 +1,308 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ChamChat.Models;
namespace ChamChat
{
public partial class HTS7057_Client : Client
{
private const Int32 _OptionRange = 4000;
private const Int32 _DataTransferTimeOut = 1000;
private DateTime _ReadyToSend = DateTime.Now; // Timestamp when client is ready to communicate
private DateTime _dtTestStart = DateTime.Now;
public HTS7057_Client(Int32 MIDS, ClientType Type)
: base(MIDS, Type)
{
// Set options available in client
_Parameters = new List<Parameter>();
_Parameters.Add(Parameter.T);
//_Parameters.Add(Parameter.RampT);
// 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);
_InterfaceType = InterfaceType.FDTI_USB_COM422;
}
public override Profile ReadProfile(int RAM, ref System.ComponentModel.BackgroundWorker bgw)
{
String title = string.Format("{0:00000} {1}", _MIDS, _Type.ToStr());
List<Step> steps = new List<Step>();
Step step = new Step(365 * 24 * 60);
string cmd;
string read;
cmd = string.Format("${0:00}I", _Address);
DataTransfer(cmd, out read, _DataTransferTimeOut);
if (read.Length >= 6)
{
double sw = 0;
if (double.TryParse(read.Substring(0, 6), out sw))
{
step.T = sw;
}
}
steps.Add(step);
return new Profile(title, steps, new List<Loop>(), new List<ProfileOption>());
}
public override Boolean WriteProfile(Profile profile)
{
return WriteProfile(profile, -1);
}
public override Boolean WriteProfile(Profile profile, int RAM)
{
// Only stand alone profiles allowed!
if (!IsProgrammable(profile))
return false;
_Profile = profile;
return true;
}
public override Boolean IsProgrammable(Profile profile)
{
// Profile is programmable if all below applies
// Profile contains just 1 step
if (profile.SerializedStepList.Count != 1)
{
_ClientMessages.Add(new ClientMessage("Temperature range is -70 to 200 °C"));
return false;
}
Step step = profile.SerializedStepList[0];
// Temperature is limited between -70 & 200 °C
if (step.T < -70 || step.T > 200)
{
_ClientMessages.Add(new ClientMessage("Temperature range is -70 to 200 °C"));
return false;
}
return true;
}
// To do
public override Boolean HasAlarm(out List<Alarm> alarms)
{
alarms = new List<Alarm>();
return true;
}
public override Boolean IsIdle()
{
// Chamber is idle if return value's last 16 chars are 0
string cmd;
string read;
cmd = string.Format("${0:00}I", _Address);
DataTransfer(cmd, out read, _DataTransferTimeOut);
try
{
if (read.Substring(15,1) == "0")
return true;
}
catch { }
return false;
}
public override Boolean Start()
{
// Command consists of $01E xXxx.x bbbbbbbb
// The minus sign for temperature must be on location of X
// Bit 3 is on/off bit of chamber (return as bit 1 in 16-bit output)
// Bit 5 is on/off bit of heater/cooler (return as bit 3 in 16-bit output)
if (_Profile == null)
return false;
string cmd;
string read;
double t = _Profile.Steps[0].T;
if( t< 0)
cmd = string.Format("${0:00}E 0-{1:00.0} 00010100", _Address, Math.Abs(t));
else
cmd = string.Format("${0:00}E {1:0000.0} 00010100", _Address, t);
DataTransfer(cmd, out read, _DataTransferTimeOut);
_dtTestStart = DateTime.Now;
return TxRxSucces(cmd, read);
}
public override Boolean IsFinished()
{
// Chambers does not finish on its own
return IsIdle();
}
public override Boolean Stop()
{
string cmd;
string read;
cmd = string.Format("${0:00}E 0023.0 00000000", _Address);
DataTransfer(cmd, out read, _DataTransferTimeOut);
return TxRxSucces(cmd, read);
}
public override Boolean IsOnline()
{
// Chamber is online if Sollwert in °C is returned
string cmd;
string read;
cmd = string.Format("${0:00}I", _Address);
DataTransfer(cmd, out read, _DataTransferTimeOut);
if (read.Length < 6)
return false;
double sw = 0;
if (double.TryParse(read.Substring(0, 6), out sw))
return true;
return false;
}
public override String Progress()
{
string cmd;
string read;
cmd = string.Format("${0:00}I", _Address);
DataTransfer(cmd, out read, _DataTransferTimeOut);
if (read.Length < 13)
return "n/a";
string progress = "";
double sw = 0;
if (double.TryParse(read.Substring(0, 6), out sw))
progress += string.Format("Setting is {0:0.0} °C", sw);
double iw = 0;
if (double.TryParse(read.Substring(7, 6), out iw))
progress += string.Format(", current temperature is {0:0.0} °C",iw);
if (progress.Length == 0)
progress += "n/a";
return progress;
}
private bool TxRxSucces(string cmd, string read)
{
if (cmd.Contains("I"))
if (read.Length == 30)
if (read.Substring(4, 1) == "." && read.Substring(11, 1) == ".")
return true;
if (cmd.Contains("E"))
return read == "0";
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 = 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(50);
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("I"))
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
_ReadyToSend = DateTime.Now.AddMilliseconds(2000);
// Sleeps
if (!success)
System.Threading.Thread.Sleep(3000); // Sleep 3 seconds before resending if failed
}
return success;
}
}
}

View 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>{B03537FE-EF64-42E3-A8C0-25C79BB818A7}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Speak</RootNamespace>
<AssemblyName>HTS7057</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.HTS7057.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Task.HTS7057.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>

View 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("Client_HTS7057")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("Client_HTS7057")]
[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("3e41095f-2a04-41f7-989a-d2705d89e835")]
// 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")]

View File

@@ -0,0 +1,226 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ChamChat.Models;
namespace ChamChat
{
public class HTS7057_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 HTS7057_Task(Client Client, Profile Profile)
: base(Client, Profile)
{
_Profile = Profile;
_Client = Client;
_SerSteps = _Profile.SerializedStepList;
}
// Needs to be overriden, because chamber is never stand alone programmable
public override Boolean IsStandAloneProgrammable(Profile profile)
{
return false;
}
private const Int32 PollingIntervalSeconds = 10;
private List<Step> _SerSteps;
public override Boolean IsControlledProgrammable(Profile profile)
{
foreach (Step step in profile.SerializedStepList)
{
List<Step> steps = new List<Step>();
steps.Add(step);
Profile p = new Profile(_Client.Type.ToStr(), steps, new List<Loop>(), profile.Options);
if (!_Client.IsProgrammable(p))
return false;
}
return true;
}
protected override void ThreadStandAlone()
{
_Status = TaskStatus.Aborted;
_TaskProgress = "Client cannot operate in standaline mode";
_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 += 1;
// Last step has been performed?
if (iCurrentSerialStep > _SerSteps.Count - 1)
{
// Do not stop client, but leave running if option given
if (_Profile.Options.Contains(ProfileOption.HTS7057_EndModeHold))
{
_Status = TaskStatus.Finished;
AddEventLog(ProfileOption.HTS7057_EndModeHold.ToStr());
_TaskProgress = ProfileOption.HTS7057_EndModeOff.ToStr();
_TaskProgress += string.Format(" (setting is {0:0.0} °C)", _SerSteps[_SerSteps.Count - 1].T);
continue;
}
else
{
_Client.Stop();
_Status = TaskStatus.Finished;
AddEventLog(ProfileOption.HTS7057_EndModeOff.ToStr());
_TaskProgress = ProfileOption.HTS7057_EndModeOff.ToStr();
continue;
}
}
Profile newProfile = GetProfile(iCurrentSerialStep);
currentStep = _SerSteps[iCurrentSerialStep];
AddEventLog(string.Format("{0} minutes @ {1:0.0} °C", _SerSteps[iCurrentSerialStep].DurationMin, _SerSteps[iCurrentSerialStep].T));
RestartClient(newProfile);
if (_Status != TaskStatus.IsRunning) // Might be altered in RestartClient()
continue;
// Update variables
startOfCurrentProgram = DateTime.Now;
endOfCurrentProgram = startOfCurrentProgram.AddMinutes(newProfile.DurationMin);
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 taskRunTimeMin = (DateTime.Now - _startThread).TotalMinutes;
double pTest = Math.Max(0,Math.Min(100, Math.Floor(taskRunTimeMin / _Profile.DurationMin * 100)));
double stepRuntime = (DateTime.Now - startOfCurrentProgram).TotalMinutes;
double pStep = Math.Max(0,Math.Min(100, Math.Floor(stepRuntime / _SerSteps[iCurrentSerialStep].DurationMin * 100)));
double taskTimeRemain = Math.Max(0, _Profile.DurationMin - taskRunTimeMin);
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)
{
// 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)
{
// Stepslist
List<Step> steps = new List<Step>();
steps.Add(_SerSteps[iStep].DeepClone());
// Loops
List<Loop> loops = new List<Loop>();
// Options
List<ProfileOption> options = new List<ProfileOption>();
// Create profile
return new Profile(_Profile.Title, steps, loops, options);
}
}
}

View File

@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.0", FrameworkDisplayName = ".NET Framework 4")]

View File

@@ -0,0 +1 @@
78ce0a1107047916b3702a482dea8e66722a26e2

View File

@@ -0,0 +1,2 @@
\\silicium\software\MASER software\Source\ChamChat\Client_HTS7057\obj\Release\Client_HTS7057.csproj.AssemblyReference.cache
\\silicium\software\MASER software\Source\ChamChat\Client_HTS7057\obj\Release\Client_HTS7057.csproj.CoreCompileInputs.cache