inserita altra classe gestione TimePeriod
This commit is contained in:
@@ -6,13 +6,20 @@ using System.Threading.Tasks;
|
||||
using SCMCncLib;
|
||||
using XSimGph;
|
||||
using System.Windows.Forms;
|
||||
using System.Threading;
|
||||
|
||||
namespace MTC_Adapter
|
||||
{
|
||||
public class AdapterESA : AdapterGeneric
|
||||
{
|
||||
|
||||
thdNcEsaGvKvara EsaController;
|
||||
/// <summary>
|
||||
/// oggetto onnessione ESA
|
||||
/// </summary>
|
||||
protected thdNcEsaGvKvara ncDevice;
|
||||
/// <summary>
|
||||
/// thread del processo comunicazione esa
|
||||
/// </summary>
|
||||
protected Thread thdDevice;
|
||||
|
||||
/// <summary>
|
||||
/// estende l'init della classe base...
|
||||
@@ -24,18 +31,21 @@ namespace MTC_Adapter
|
||||
string iniPath = string.Format(@"{0}\{1}\{2}", Application.StartupPath, utils.CRS("adapterConfPath"), utils.CRS("defaultEsaFile"));
|
||||
|
||||
if (utils.CRB("verbose")) lg.Info("Start init Adapter ESA dal file {0}", iniPath);
|
||||
|
||||
// !!! 2016.05.25 verificare se serva altro x istanziare oggetto NcEsaGvKvara
|
||||
|
||||
IniFiles.IniFile EsaIni = new IniFiles.IniFile(iniPath);
|
||||
EsaController = new thdNcEsaGvKvara(EsaIni);
|
||||
ncDevice = new thdNcEsaGvKvara(EsaIni);
|
||||
|
||||
// inizializzo posizioni assi...
|
||||
prevPosAxis = new double[adpConf.nAxis];
|
||||
prevDirAxis = new int[adpConf.nAxis];
|
||||
|
||||
|
||||
// verifica modalità avvio...
|
||||
#if false
|
||||
// disconnetto e connetto...
|
||||
if (utils.CRB("verbose")) lg.Info("ESA: tryDisconnect");
|
||||
tryDisconnect();
|
||||
|
||||
#endif
|
||||
if (utils.CRB("verbose")) lg.Info("ESA: tryConnect");
|
||||
tryConnect();
|
||||
if (utils.CRB("verbose")) lg.Info("End init Adapter ESA");
|
||||
@@ -45,11 +55,20 @@ namespace MTC_Adapter
|
||||
public override void tryDisconnect()
|
||||
{
|
||||
base.tryDisconnect();
|
||||
|
||||
ncDevice.RequestStop();
|
||||
// wait for thread
|
||||
while (!ncDevice.Finished)
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
|
||||
public override void tryConnect()
|
||||
{
|
||||
base.tryConnect();
|
||||
|
||||
// !!! 2016.05.25 verificare funzionamento thread... eventualmente portare entro metodo questo thread con suoi timing...
|
||||
// avvio il thread...
|
||||
thdDevice = new Thread(ncDevice.Execute);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="clsTimePeriod.cs" />
|
||||
<Compile Include="IniFile.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="thdNcBase.cs" />
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Collections.Generic;
|
||||
|
||||
internal sealed class TimePeriod : IDisposable
|
||||
{
|
||||
private const string WINMM = "winmm.dll";
|
||||
|
||||
private static TIMECAPS timeCapabilities;
|
||||
|
||||
private static int inTimePeriod;
|
||||
|
||||
private readonly int period;
|
||||
|
||||
private int disposed;
|
||||
|
||||
[DllImport(WINMM, ExactSpelling = true)]
|
||||
private static extern int timeGetDevCaps(ref TIMECAPS ptc, int cbtc);
|
||||
|
||||
[DllImport(WINMM, ExactSpelling = true)]
|
||||
private static extern int timeBeginPeriod(int uPeriod);
|
||||
|
||||
[DllImport(WINMM, ExactSpelling = true)]
|
||||
private static extern int timeEndPeriod(int uPeriod);
|
||||
|
||||
static TimePeriod()
|
||||
{
|
||||
int result = timeGetDevCaps(ref timeCapabilities, Marshal.SizeOf(typeof(TIMECAPS)));
|
||||
if (result != 0)
|
||||
{
|
||||
throw new InvalidOperationException("The request to get time capabilities was not completed because an unexpected error with code " + result + " occured.");
|
||||
}
|
||||
}
|
||||
|
||||
internal TimePeriod(int period)
|
||||
{
|
||||
if (Interlocked.Increment(ref inTimePeriod) != 1)
|
||||
{
|
||||
Interlocked.Decrement(ref inTimePeriod);
|
||||
throw new NotSupportedException("The process is already within a time period. Nested time periods are not supported.");
|
||||
}
|
||||
|
||||
if (period < timeCapabilities.wPeriodMin || period > timeCapabilities.wPeriodMax)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("period", "The request to begin a time period was not completed because the resolution specified is out of range.");
|
||||
}
|
||||
|
||||
int result = timeBeginPeriod(period);
|
||||
if (result != 0)
|
||||
{
|
||||
throw new InvalidOperationException("The request to begin a time period was not completed because an unexpected error with code " + result + " occured.");
|
||||
}
|
||||
|
||||
this.period = period;
|
||||
}
|
||||
|
||||
internal static int MinimumPeriod
|
||||
{
|
||||
get
|
||||
{
|
||||
return timeCapabilities.wPeriodMin;
|
||||
}
|
||||
}
|
||||
|
||||
internal static int MaximumPeriod
|
||||
{
|
||||
get
|
||||
{
|
||||
return timeCapabilities.wPeriodMax;
|
||||
}
|
||||
}
|
||||
|
||||
internal int Period
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.disposed > 0)
|
||||
{
|
||||
throw new ObjectDisposedException("The time period instance has been disposed.");
|
||||
}
|
||||
|
||||
return this.period;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (Interlocked.Increment(ref this.disposed) == 1)
|
||||
{
|
||||
timeEndPeriod(this.period);
|
||||
Interlocked.Decrement(ref inTimePeriod);
|
||||
}
|
||||
else
|
||||
{
|
||||
Interlocked.Decrement(ref this.disposed);
|
||||
}
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
private struct TIMECAPS
|
||||
{
|
||||
internal int wPeriodMin;
|
||||
|
||||
internal int wPeriodMax;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -363,11 +363,7 @@ namespace SCMCncLib
|
||||
/// <returns></returns>
|
||||
public bool CheckMultimediaTimer()
|
||||
{
|
||||
// !!! 2016.05.25 bypass per problemi compilazione
|
||||
int minimumPeriod = 2;
|
||||
#if false
|
||||
int minimumPeriod = TimePeriod.MinimumPeriod;
|
||||
#endif // false
|
||||
int minimumPeriod = TimePeriod.MinimumPeriod;
|
||||
//int maximumPeriod = TimePeriod.MaximumPeriod;
|
||||
return ((minimumPeriod <= 2) && (minimumPeriod > 0));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user