Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions WasatchNET/AndorSpectrometer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@

namespace WasatchNET
{
public struct camSpeed
{
public int channel;
public int speedIndex;
public float speed;
}

public class AndorSpectrometer : Spectrometer
{
#if WIN32
Expand All @@ -28,6 +35,7 @@ public class AndorSpectrometer : Spectrometer
internal int specIndex;
int cameraHandle = 0;
int yPixels;
public List<camSpeed> speedOptions = new List<camSpeed>();

//see page 330 of Andor SDK documentation
public const int DRV_SUCCESS = 20002;
Expand Down Expand Up @@ -81,12 +89,14 @@ internal AndorSpectrometer(UsbRegistry usbReg, int index = 0) : base(usbReg)
}

// Set Horizontal Speed to max (step 13)
// Populate speed list
float STemp = 0;
int HSnumber = 0;
int ADnumber = 0;
int nAD = 0;
int sIndex = 0;
errorValue = andorDriver.GetNumberADChannels(ref nAD); // 13.1
speedOptions.Clear();
if (errorValue != DRV_SUCCESS)
{

Expand All @@ -99,6 +109,14 @@ internal AndorSpectrometer(UsbRegistry usbReg, int index = 0) : base(usbReg)
for (int iSpeed = 0; iSpeed < sIndex; iSpeed++)
{
andorDriver.GetHSSpeed(iAD, 0, iSpeed, ref speed); // 13.3
speedOptions.Add(
new camSpeed
{
channel = iAD,
speedIndex = iSpeed,
speed = speed
});

if (speed > STemp)
{
STemp = speed;
Expand Down Expand Up @@ -297,6 +315,17 @@ protected override async Task<double[]> getSpectrumRawAsync(bool skipTrigger = f

}

public bool setCamSpeed(camSpeed option)
{
uint errorValue = andorDriver.SetADChannel(option.channel);

if (errorValue != DRV_SUCCESS)
return false;

errorValue = andorDriver.SetHSSpeed(0, option.speedIndex);

return errorValue == DRV_SUCCESS;
}

public override bool areaScanEnabled
{
Expand Down Expand Up @@ -389,6 +418,7 @@ public override LaserPowerResolution laserPowerResolution

public override bool laserInterlockEnabled { get => false; }
public override byte laserWarningDelaySec { get => 0; set { } }
public override byte laserPowerAttenuation { get => 0; set { } }

public override UInt64 laserModulationPeriod { get => 100; }

Expand Down
1 change: 1 addition & 0 deletions WasatchNET/BoulderSpectrometer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,7 @@ public override LaserPowerResolution laserPowerResolution

public override bool laserInterlockEnabled { get => false; }
public override byte laserWarningDelaySec { get => 0; set { } }
public override byte laserPowerAttenuation { get => 0; set { } }

public override UInt64 laserModulationPeriod { get => 100; }

Expand Down
20 changes: 17 additions & 3 deletions WasatchNET/COMOCTSpectrometer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ internal override async Task<bool> openAsync()

if (!sendCOMCommand(Opcodes.GET_LINE_PERIOD, ref resp, null))
{
port.Close();
port.Dispose();
port = null;
return false;
}
Expand Down Expand Up @@ -343,7 +341,23 @@ internal bool sendCOMCommand(Opcodes opcode, ref string response, float[] args,
}
command += "\r";

port.Write(command);
try
{
Thread t1 = new Thread(() => port.Write(command));
t1.Start();
if (!t1.Join(TimeSpan.FromMilliseconds(100)))
{
return false;
}

}
catch (Exception e)
{
logger.info("{0} failed with exception {1}", portName, e.Message);
return false;
}


Thread.Sleep(33);
string resp = "";
Thread t = new Thread(() => resp = tryPort(port));
Expand Down
132 changes: 128 additions & 4 deletions WasatchNET/EEPROM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class EEPROM : IEEPROM
/// accessible from existing firmware on our ARM models. A future update
/// to /FX2 firmware will make them available on all spectrometers.
/// </remarks>
internal const int MAX_PAGES = 8;
internal const int MAX_PAGES = 9;
internal const int MAX_PAGES_REAL = 512;
internal const int MAX_NAME_LEN = 16;
internal const int MAX_LIB_ENTRIES = 8;
Expand All @@ -54,7 +54,7 @@ public class EEPROM : IEEPROM
/// - rev 14
/// - adds SiG laser TEC and Has interlock feedback to feature mask
/// </remarks>
protected const byte FORMAT = 17;
protected const byte FORMAT = 18;

protected Spectrometer spectrometer;
protected Logger logger = Logger.getInstance();
Expand Down Expand Up @@ -678,6 +678,20 @@ public float[] linearityCoeffs
// public int laserLifetimeOperationMinutes { get; private set; }
// public short laserTemperatureMax { get; private set; }
// public short laserTemperatureMin { get; private set; }

public byte maxLaserTempDegC
{
get { return _maxLaserTempDegC; }
set
{
EventHandler handler = EEPROMChanged;
_maxLaserTempDegC = value;
handler?.Invoke(this, new EventArgs());
}
}
byte _maxLaserTempDegC;


public float maxLaserPowerMW
{
get { return _maxLaserPowerMW; }
Expand Down Expand Up @@ -800,6 +814,18 @@ public HORIZONTAL_BINNING_METHOD horizontalBinningMethod
}
HORIZONTAL_BINNING_METHOD _horizontalBinningMethod = HORIZONTAL_BINNING_METHOD.BIN_2X2;

public byte laserDacAttenuation
{
get { return _laserDacAttenuation; }
set
{
EventHandler handler = EEPROMChanged;
_laserDacAttenuation = value;
handler?.Invoke(this, new EventArgs());
}
}
byte _laserDacAttenuation = 0;

/////////////////////////////////////////////////////////////////////////
// Page 4
/////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -907,6 +933,18 @@ public string productConfiguration

string _productConfiguration;

public byte[] assemblyRevision
{
get { return _assemblyRevision; }
set
{
EventHandler handler = EEPROMChanged;
_assemblyRevision = value;
handler?.Invoke(this, new EventArgs());
}
}
byte[] _assemblyRevision;

public PAGE_SUBFORMAT subformat
{
get { return _subformat; }
Expand Down Expand Up @@ -1256,6 +1294,25 @@ public byte librarySpectraNum
}
byte _librarySpectraNum = 1;

/////////////////////////////////////////////////////////////////////////
// Page 8 Handheld Devices
/////////////////////////////////////////////////////////////////////////

public string laserPassword
{
get { return _laserPassword; }
set
{
EventHandler handler = EEPROMChanged;
_laserPassword = value;
handler?.Invoke(this, new EventArgs());
}
}

string _laserPassword;

public FeatureMaskXS featureMaskXS = new FeatureMaskXS();

/////////////////////////////////////////////////////////////////////////
// Pages 10-73 (subformat UNTETHERED_DEVICE)
/////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1645,6 +1702,12 @@ public virtual async Task<bool> readAsync(bool skipRead = false)
maxIntegrationTimeMS = ParseData.toUInt32(pages[3], 44);
}

if (format >= 18)
{
maxLaserTempDegC = ParseData.toUInt8(pages[3], 11);
}


userData = format < 4 ? new byte[63] : new byte[64];
Array.Copy(pages[4], userData, userData.Length);

Expand All @@ -1663,6 +1726,14 @@ public virtual async Task<bool> readAsync(bool skipRead = false)
else
productConfiguration = "";


assemblyRevision = new byte[6];
if (format >= 18)
{
Array.Copy(pages[5], 46, assemblyRevision, 0, assemblyRevision.Length);
}


if (format >= 6 && (subformat == PAGE_SUBFORMAT.INTENSITY_CALIBRATION ||
subformat == PAGE_SUBFORMAT.UNTETHERED_DEVICE))
{
Expand Down Expand Up @@ -1749,6 +1820,15 @@ public virtual async Task<bool> readAsync(bool skipRead = false)
horizontalBinningMethod = HORIZONTAL_BINNING_METHOD.BIN_2X2;
}

if (format >= 18)
{
laserDacAttenuation = ParseData.toUInt8(pages[3], 61);
}
else
{
//default to halfway point
laserDacAttenuation = 127;
}

if (format < 12)
featureMask.evenOddHardwareCorrected = false;
Expand Down Expand Up @@ -1829,6 +1909,12 @@ public virtual async Task<bool> readAsync(bool skipRead = false)
regionCount = ParseData.toUInt8(pages[7], 0);
}
}

if (format >= 18 && spectrometer.isSiG && pages.Count >= 8)
{
laserPassword = ParseData.toString(pages[8], 0, 16);
featureMaskXS = new FeatureMaskXS(ParseData.toUInt32(pages[8], 16));
}
}
catch (Exception ex)
{
Expand Down Expand Up @@ -1990,6 +2076,9 @@ public void setFromJSON(EEPROMJSON json)
featureMask.disableBLEPower = json.DisableBLEPower;
featureMask.disableLaserArmedIndication = json.DisableLaserArmedIndication;
featureMask.interlockExcluded = json.InterlockExcluded;
featureMask.laserTimeoutInCounts = json.LaserTimeoutInCounts;
featureMask.isOEM = json.IsOEM;
featureMaskXS.BLEDoorSensor = json.BLEDoorSensor;

wavecalCoeffs[0] = (float)json.WavecalCoeffs[0];
wavecalCoeffs[1] = (float)json.WavecalCoeffs[1];
Expand Down Expand Up @@ -2038,10 +2127,12 @@ public void setFromJSON(EEPROMJSON json)
linearityCoeffs[3] = (float)json.LinearityCoeffs[3];
linearityCoeffs[4] = (float)json.LinearityCoeffs[4];

maxLaserTempDegC = json.MaxLaserTempDegC;
maxLaserPowerMW = (float)json.MaxLaserPowerMW;
minLaserPowerMW = (float)json.MinLaserPowerMW;
laserWarmupSec = json.LaserWarmupS;
laserExcitationWavelengthNMFloat = (float)json.ExcitationWavelengthNM;
laserDacAttenuation = json.LaserDACAttenuation;
avgResolution = (float)json.AvgResolution;

if (json.LaserPowerCoeffs != null)
Expand Down Expand Up @@ -2074,7 +2165,12 @@ public void setFromJSON(EEPROMJSON json)
badPixels[12] = (Int16)json.BadPixels[12];
badPixels[13] = (Int16)json.BadPixels[13];
badPixels[14] = (Int16)json.BadPixels[14];

if (json.AssemblyRevision != null)
{
assemblyRevision = new byte[json.AssemblyRevision.Length];
Array.Copy(json.AssemblyRevision, assemblyRevision, json.AssemblyRevision.Length);
}

detectorSerialNumber = json.DetectorSN;

if (json.ProductConfig != null)
Expand Down Expand Up @@ -2128,7 +2224,7 @@ public void setFromJSON(EEPROMJSON json)
regionCount = json.RegionCount;
}


laserPassword = json.LaserPassword;
}

public EEPROMJSON toJSON()
Expand Down Expand Up @@ -2223,9 +2319,11 @@ public EEPROMJSON toJSON()
json.LaserPowerCoeffs[2] = laserPowerCoeffs[2];
json.LaserPowerCoeffs[3] = laserPowerCoeffs[3];
}
json.MaxLaserTempDegC = maxLaserTempDegC;
json.MaxLaserPowerMW = maxLaserPowerMW;
json.MinLaserPowerMW = minLaserPowerMW;
json.ExcitationWavelengthNM = laserExcitationWavelengthNMFloat;
json.LaserDACAttenuation = laserDacAttenuation;
json.AvgResolution = avgResolution;
json.BadPixels = new int[15];
if (badPixels != null)
Expand All @@ -2246,6 +2344,12 @@ public EEPROMJSON toJSON()
json.BadPixels[13] = badPixels[13];
json.BadPixels[14] = badPixels[14];
}
if (assemblyRevision != null)
{
json.AssemblyRevision = new byte[assemblyRevision.Length];
Array.Copy(assemblyRevision, json.AssemblyRevision, assemblyRevision.Length);
}

json.DetectorSN = detectorSerialNumber;
json.UserText = userText;
json.ProductConfig = productConfiguration;
Expand Down Expand Up @@ -2278,6 +2382,12 @@ public EEPROMJSON toJSON()
json.DisableBLEPower = featureMask.disableBLEPower;
json.DisableLaserArmedIndication = featureMask.disableLaserArmedIndication;
json.InterlockExcluded = featureMask.interlockExcluded;
json.LaserTimeoutInCounts = featureMask.laserTimeoutInCounts;
json.IsOEM = featureMask.isOEM;
}
if (featureMaskXS != null)
{
json.BLEDoorSensor = featureMaskXS.BLEDoorSensor;
}

json.LaserWarmupS = laserWarmupSec;
Expand Down Expand Up @@ -2321,7 +2431,9 @@ public EEPROMJSON toJSON()
json.RegionCount = regionCount;
}

json.LaserPassword = laserPassword;
json.FeatureMask = featureMask.ToString();
json.FeatureMaskXS = featureMaskXS.ToString();
json.HexDump = hexdump();

return json;
Expand Down Expand Up @@ -2541,6 +2653,18 @@ protected bool writeParse()
if (!ParseData.writeUInt16(detectorTimeout, pages[3], 57)) return false;
if (!ParseData.writeByte((byte)horizontalBinningMethod, pages[3], 59)) return false;
}
if (format >= 18)
{
if (!ParseData.writeByte(maxLaserTempDegC, pages[3], 11)) return false;
if (!ParseData.writeByte(laserDacAttenuation, pages[3], 61)) return false;

Array.Copy(assemblyRevision, 0, pages[5], 46, assemblyRevision.Length);
if (spectrometer.isSiG && pages.Count >= 8)
{
if (!ParseData.writeString(laserPassword, pages[8], 0, 16)) return false;
if (!ParseData.writeUInt32(featureMaskXS.toUInt32(), pages[8], 16)) return false;
}
}

byte[] userDataChunk2 = new byte[64];
byte[] userDataChunk3 = new byte[64];
Expand Down
Loading