init
This commit is contained in:
279
DataPRO/RibeyeCommands/InformationCommands.cs
Normal file
279
DataPRO/RibeyeCommands/InformationCommands.cs
Normal file
@@ -0,0 +1,279 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using DTS.Common.Enums.DASFactory;
|
||||
using DTS.Common.ICommunication;
|
||||
|
||||
namespace DTS.DASLib.Command.Ribeye
|
||||
{
|
||||
public abstract class InformationCommands : CommandBase
|
||||
{
|
||||
protected enum Commands
|
||||
{
|
||||
Reserved = 0x00,
|
||||
QueryNumberOfLEDs = 0x01,
|
||||
QueryDataAvailable = 0x02,
|
||||
QuerySerialNumber = 0x03
|
||||
};
|
||||
|
||||
protected abstract Commands _Command { get; }
|
||||
|
||||
protected InformationCommands(DTS.Common.Interface.DASFactory.ICommunication sock)
|
||||
: base(sock)
|
||||
{
|
||||
command.Type = CommandPacket.CommandType.Information;
|
||||
command.SetCommand((byte)_Command, _Command.ToString());
|
||||
}
|
||||
|
||||
protected InformationCommands(DTS.Common.Interface.DASFactory.ICommunication sock, int TimeoutMillisec)
|
||||
: base(sock, TimeoutMillisec)
|
||||
{
|
||||
command.Type = CommandPacket.CommandType.Information;
|
||||
command.SetCommand((byte)_Command, _Command.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public class QueryProtocolVersion : InformationCommands
|
||||
{
|
||||
protected override InformationCommands.Commands _Command
|
||||
{
|
||||
get {
|
||||
}
|
||||
byte _versionbyte = (byte)0;
|
||||
|
||||
public int Version { get { return _versionbyte; } }
|
||||
|
||||
public QueryProtocolVersion(DTS.Common.Interface.DASFactory.ICommunication sock)
|
||||
: base(sock)
|
||||
{
|
||||
// this.command.Command = (byte)Commands.QueryProtocolVersion;
|
||||
}
|
||||
|
||||
public QueryProtocolVersion(DTS.Common.Interface.DASFactory.ICommunication sock, int TimeoutMillisec)
|
||||
: base(sock, TimeoutMillisec)
|
||||
{
|
||||
// this.command.Command = (byte)Commands.QueryProtocolVersion;
|
||||
}
|
||||
|
||||
protected override CommandReceiveAction WholePackage()
|
||||
{
|
||||
// we have a whole package
|
||||
if (response.Status == DFConstantsAndEnums.CommandStatus.StatusNoError)
|
||||
{
|
||||
// response.GetParameter(0, out _versionbyte);
|
||||
}
|
||||
return CommandReceiveAction.StopReceiving;
|
||||
}
|
||||
|
||||
public override string CommandToString()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public override string ResponseToString()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine();
|
||||
sb.AppendFormat(" Status: {0}, Version: {1}", ResponseStatus, Version);
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
*/
|
||||
/*
|
||||
public class QueryFirmwareVersion : InformationCommands
|
||||
{
|
||||
string _versionstring = string.Empty;
|
||||
|
||||
public string Version { get { return _versionstring; } }
|
||||
|
||||
public QueryFirmwareVersion(DTS.Common.Interface.DASFactory.ICommunication sock)
|
||||
: base(sock)
|
||||
{
|
||||
// this.command.Command = (byte)Commands.QueryFirmwareVersion;
|
||||
}
|
||||
|
||||
public QueryFirmwareVersion(DTS.Common.Interface.DASFactory.ICommunication sock, int TimeoutMillisec)
|
||||
: base(sock, TimeoutMillisec)
|
||||
{
|
||||
// this.command.Command = (byte)Commands.QueryFirmwareVersion;
|
||||
}
|
||||
|
||||
protected override CommandReceiveAction WholePackage()
|
||||
{
|
||||
// we have a whole package
|
||||
if (response.Status == DFConstantsAndEnums.CommandStatus.StatusNoError)
|
||||
{
|
||||
response.GetParameter(0, out _versionstring);
|
||||
}
|
||||
return CommandReceiveAction.StopReceiving;
|
||||
}
|
||||
|
||||
public override string CommandToString()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public override string ResponseToString()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine();
|
||||
sb.AppendFormat(" Status: {0}, Version: {1}", ResponseStatus, Version);
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
*/
|
||||
public class QuerySerialNumber : InformationCommands
|
||||
{
|
||||
// note - the existing implementation doesn't set a command for this
|
||||
// class, so I will preserve that by changing it not to be set
|
||||
// in the parent class for this one instance
|
||||
protected override InformationCommands.Commands _Command
|
||||
{
|
||||
get { return Commands.QuerySerialNumber; }
|
||||
}
|
||||
|
||||
string _serialnumber = string.Empty;
|
||||
const string SerialNumberCommand = "SERIAL_NUMBER";
|
||||
|
||||
public string SerialNumber { get { return _serialnumber; } }
|
||||
|
||||
public QuerySerialNumber(DTS.Common.Interface.DASFactory.ICommunication sock)
|
||||
: base(sock)
|
||||
{
|
||||
command.Parameter = new string[1];
|
||||
command.SetParameter(0, SerialNumberCommand);
|
||||
}
|
||||
|
||||
public QuerySerialNumber(DTS.Common.Interface.DASFactory.ICommunication sock, int TimeoutMillisec)
|
||||
: base(sock, TimeoutMillisec)
|
||||
{
|
||||
command.Parameter = new string[1];
|
||||
command.SetParameter(0, SerialNumberCommand);
|
||||
}
|
||||
|
||||
protected override CommandReceiveAction WholePackage()
|
||||
{
|
||||
// we have a whole package
|
||||
if (response.Status == DFConstantsAndEnums.CommandStatus.StatusNoError)
|
||||
{
|
||||
try
|
||||
{
|
||||
response.GetParameter(1, out _serialnumber);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.ToString();
|
||||
}
|
||||
}
|
||||
return CommandReceiveAction.StopReceiving;
|
||||
}
|
||||
}
|
||||
|
||||
public class QueryNumberOfLEDs : InformationCommands
|
||||
{
|
||||
protected override InformationCommands.Commands _Command
|
||||
{
|
||||
get { return Commands.QueryNumberOfLEDs; }
|
||||
}
|
||||
|
||||
uint _numberOfLEDs = 0;
|
||||
const string NumberOfLEDsCommand = "HOW_MANY_LEDS";
|
||||
|
||||
public uint NumberOfLEDs { get { return _numberOfLEDs; } }
|
||||
|
||||
public QueryNumberOfLEDs(DTS.Common.Interface.DASFactory.ICommunication sock)
|
||||
: base(sock)
|
||||
{
|
||||
InitializeMembers();
|
||||
}
|
||||
|
||||
public QueryNumberOfLEDs(DTS.Common.Interface.DASFactory.ICommunication sock, int TimeoutMillisec)
|
||||
: base(sock, TimeoutMillisec)
|
||||
{
|
||||
InitializeMembers();
|
||||
}
|
||||
|
||||
private void InitializeMembers()
|
||||
{
|
||||
command.Parameter = new string[1];
|
||||
command.SetParameter(0, NumberOfLEDsCommand);
|
||||
}
|
||||
|
||||
protected override CommandReceiveAction WholePackage()
|
||||
{
|
||||
// we have a whole package
|
||||
if (response.Status == DFConstantsAndEnums.CommandStatus.StatusNoError)
|
||||
{
|
||||
response.GetParameter(1, out _numberOfLEDs);
|
||||
}
|
||||
return CommandReceiveAction.StopReceiving;
|
||||
}
|
||||
|
||||
public override void ResponseToString(ref List<List<string>> lines)
|
||||
{
|
||||
base.ResponseToString(ref lines);
|
||||
lines.Add(new List<string>()
|
||||
{
|
||||
string.Format("NumberOfLEDs: {0}", NumberOfLEDs)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class QueryDataAvailable : InformationCommands
|
||||
{
|
||||
//a note - I'm preserving the existing code that was using the command
|
||||
//querynumberofled's - but I'm thinking it probably should have been using
|
||||
//querydataavailable ...
|
||||
protected override InformationCommands.Commands _Command
|
||||
{
|
||||
get { return Commands.QueryNumberOfLEDs; }
|
||||
}
|
||||
float _totalMS = 0;
|
||||
float _preTriggerMS = 0;
|
||||
float _postTriggerMS = 0;
|
||||
|
||||
const string DumpInfoCommand = "DUMPINFO";
|
||||
|
||||
public float TotalMS { get { return _totalMS; } }
|
||||
public float PreTriggerMS { get { return _preTriggerMS; } }
|
||||
public float PostTriggerMS { get { return _postTriggerMS; } }
|
||||
|
||||
public QueryDataAvailable(DTS.Common.Interface.DASFactory.ICommunication sock)
|
||||
: base(sock)
|
||||
{
|
||||
InitializeMembers();
|
||||
}
|
||||
|
||||
public QueryDataAvailable(DTS.Common.Interface.DASFactory.ICommunication sock, int TimeoutMillisec)
|
||||
: base(sock, TimeoutMillisec)
|
||||
{
|
||||
InitializeMembers();
|
||||
}
|
||||
|
||||
private void InitializeMembers()
|
||||
{
|
||||
//is this really the right command? - it doesn't match the name
|
||||
//this.command.Command = (byte)Commands.QueryNumberOfLEDs;
|
||||
command.Parameter = new string[1];
|
||||
command.SetParameter(0, DumpInfoCommand);
|
||||
}
|
||||
|
||||
protected override CommandReceiveAction WholePackage()
|
||||
{
|
||||
// we have a whole package
|
||||
if (response.Status == DFConstantsAndEnums.CommandStatus.StatusNoError)
|
||||
{
|
||||
int NegativePreTriggerMS;
|
||||
response.GetParameter(1, out NegativePreTriggerMS);
|
||||
_preTriggerMS = Math.Abs(NegativePreTriggerMS);
|
||||
response.GetParameter(2, out _postTriggerMS);
|
||||
_totalMS = _postTriggerMS + _preTriggerMS;
|
||||
}
|
||||
return CommandReceiveAction.StopReceiving;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user