OMNI: first test at the production
This commit is contained in:
@@ -60,7 +60,7 @@ namespace OmniPlus
|
||||
this.Write(request);
|
||||
this.InvokeLogMessage($"TX: {BitConverter.ToString(command)}");
|
||||
|
||||
while (!received /*&& sleep >= 0*/)
|
||||
while (!received && sleep >= 0)
|
||||
{
|
||||
sleep -= delay;
|
||||
|
||||
|
||||
@@ -154,14 +154,15 @@ namespace OmniPlus
|
||||
|
||||
protected void Write(params byte[] bytes)
|
||||
{
|
||||
this.BeginWaitingResponseAsync();
|
||||
|
||||
lock (this.serialPort)
|
||||
if (this.BeginWaitingResponseAsync())
|
||||
{
|
||||
this.serialPort.Write(bytes, 0, bytes.Length);
|
||||
}
|
||||
lock (this.serialPort)
|
||||
{
|
||||
this.serialPort.Write(bytes, 0, bytes.Length);
|
||||
}
|
||||
|
||||
this.LogMessage?.Invoke($"TX: {BitConverter.ToString(bytes)}");
|
||||
this.LogMessage?.Invoke($"TX: {BitConverter.ToString(bytes)}");
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void SerialPortConnection_DataReceived(byte[] bytes);
|
||||
@@ -227,16 +228,21 @@ namespace OmniPlus
|
||||
this.LogMessage?.Invoke($"RX: {BitConverter.ToString(bytes)}");
|
||||
}
|
||||
|
||||
private void BeginWaitingResponseAsync()
|
||||
private bool BeginWaitingResponseAsync()
|
||||
{
|
||||
var buffer = new byte[1024];
|
||||
var stream = this.serialPort.BaseStream;
|
||||
|
||||
this.serialPort.BaseStream.BeginRead(buffer, 0, buffer.Length, delegate(IAsyncResult asyncResult)
|
||||
this.serialPort?.BaseStream?.BeginRead(buffer, 0, buffer.Length, delegate(IAsyncResult asyncResult)
|
||||
{
|
||||
try
|
||||
{
|
||||
var actualLength = this.serialPort.BaseStream.EndRead(asyncResult);
|
||||
var actualLength = this.serialPort?.BaseStream?.EndRead(asyncResult) ?? 0;
|
||||
|
||||
if (actualLength <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var received = new byte[actualLength];
|
||||
|
||||
Buffer.BlockCopy(buffer, 0, received, 0, actualLength);
|
||||
@@ -249,7 +255,9 @@ namespace OmniPlus
|
||||
this.StateChanged?.Invoke(this.state, $"{this.Options.PortName}: {e}");
|
||||
this.LogMessage?.Invoke(e.ToString());
|
||||
}
|
||||
}, stream);
|
||||
}, null);
|
||||
|
||||
return this.serialPort != null && this.serialPort.IsOpen;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,33 +155,33 @@ namespace OmniPlus
|
||||
|
||||
tasks.ContinueWhenAll();
|
||||
|
||||
//foreach (var point in this.omniType.TestPoints)
|
||||
//{
|
||||
// // TODO: 600 = 10min * 60sec - change for production.
|
||||
foreach (var point in this.omniType.TestPoints)
|
||||
{
|
||||
// TODO: 600 = 10min * 60sec - change for production.
|
||||
|
||||
// if (!this.signalRConnection.SetQAndWaitUntilReached(point.VolumeM3H))
|
||||
// {
|
||||
// this.CancelExecution();
|
||||
if (!this.signalRConnection.SetQAndWaitUntilReached(point.VolumeM3H))
|
||||
{
|
||||
this.CancelExecution();
|
||||
|
||||
// break;
|
||||
// }
|
||||
break;
|
||||
}
|
||||
|
||||
// tasks = new Task[connectionsCount];
|
||||
tasks = new Task[connectionsCount];
|
||||
|
||||
// foreach (var position in this.connections.Keys)
|
||||
// {
|
||||
// tasks[position - 1] = Task.Factory.StartNew(() => this.StartOmniInspection(position, point), this.cancellationToken);
|
||||
// }
|
||||
foreach (var position in this.connections.Keys)
|
||||
{
|
||||
tasks[position - 1] = Task.Factory.StartNew(() => this.StartOmniInspection(position, point), this.cancellationToken);
|
||||
}
|
||||
|
||||
// tasks.ContinueWhenAll();
|
||||
tasks.ContinueWhenAll();
|
||||
|
||||
// var volume = this.signalRConnection.RequestRefV();
|
||||
var volume = this.signalRConnection.RequestRefV();
|
||||
|
||||
// foreach (var position in this.connections.Keys)
|
||||
// {
|
||||
// this.SetPointDifference(position, point, volume);
|
||||
// }
|
||||
//}
|
||||
foreach (var position in this.connections.Keys)
|
||||
{
|
||||
this.SetPointDifference(position, point, volume);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var position in this.connections.Keys)
|
||||
{
|
||||
|
||||
@@ -104,6 +104,8 @@ namespace OmniPlus
|
||||
|
||||
public void LoadOmniDefaults(byte size, string variant, OmniPlusType omniType)
|
||||
{
|
||||
omniType?.TestPoints?.Clear();
|
||||
|
||||
using (var sqlConnection = new SqlConnection(this.connectionString))
|
||||
{
|
||||
sqlConnection.OpenConnection();
|
||||
@@ -166,15 +168,15 @@ namespace OmniPlus
|
||||
while (sqlDataReader.Read())
|
||||
{
|
||||
field = 0;
|
||||
|
||||
|
||||
omniType.TestPoints.Add(new OmniPlusTestPoint
|
||||
{
|
||||
MlPerRotation = mlPerRotation,
|
||||
GalPerMin = sqlDataReader.GetValue<double>(field++),
|
||||
Rotations = (ushort)sqlDataReader.GetValue<short>(field++),
|
||||
Duration = (ushort)sqlDataReader.GetValue<short>(field++),
|
||||
MinDiff = (ushort)sqlDataReader.GetValue<double>(field++),
|
||||
MaxDiff = (ushort)sqlDataReader.GetValue<double>(field++),
|
||||
MinDiff = sqlDataReader.GetValue<double>(field++),
|
||||
MaxDiff = sqlDataReader.GetValue<double>(field++),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace OmniPlus
|
||||
{
|
||||
internal static class OmniPlusExtensions
|
||||
public static class OmniPlusExtensions
|
||||
{
|
||||
public const int BYTE_BITS = 8;
|
||||
|
||||
@@ -311,6 +311,11 @@ namespace OmniPlus
|
||||
|
||||
public static double GetCorrectionFactor(this double[] points)
|
||||
{
|
||||
if (points?.Length != 3)
|
||||
{
|
||||
return double.MinValue;
|
||||
}
|
||||
|
||||
var min = points[0];
|
||||
var mid = points[1];
|
||||
var max = points[2];
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace OmniPlus
|
||||
{
|
||||
internal class OmniPlusTest
|
||||
public class OmniPlusTest
|
||||
{
|
||||
public double Rotations { get; set; }
|
||||
|
||||
|
||||
@@ -10,9 +10,9 @@ namespace OmniPlus
|
||||
|
||||
public ushort Duration { get; set; }
|
||||
|
||||
public ushort MinDiff { get; set; }
|
||||
public double MinDiff { get; set; }
|
||||
|
||||
public ushort MaxDiff { get; set; }
|
||||
public double MaxDiff { get; set; }
|
||||
|
||||
public double MlPerRotation { get; set; }
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace OmniPlus
|
||||
public InputVolume InputVolume { get; }
|
||||
= new InputVolume();
|
||||
|
||||
public ICollection<OmniPlusTestPoint> TestPoints { get; }
|
||||
public List<OmniPlusTestPoint> TestPoints { get; }
|
||||
= new List<OmniPlusTestPoint>();
|
||||
}
|
||||
}
|
||||
@@ -41,10 +41,10 @@ namespace OmniPlus
|
||||
{
|
||||
var startSeconds = seconds;
|
||||
|
||||
void waitRefStarted() => started = true;
|
||||
void waitRefStarted(int _) => started = true;
|
||||
this.slave.StartRef += waitRefStarted;
|
||||
|
||||
this.slave.NotifyStartRef();
|
||||
this.slave.NotifyStartRef(0);
|
||||
|
||||
while (!started && startSeconds >= 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user