| THM1176InstrumentDriver 1.2 C++ API for Metrolab THM1176

Loading...
Searching...
No Matches
THM1176.h
Go to the documentation of this file.
1// Copyright (c) 2025 Metrolab Technology S.A., Geneva, Switzerland (www.metrolab.com)
2// See the included file LICENSE.txt for the licensing conditions.
3
7
48
49#pragma once
50
51// Standard includes
52#include <map>
53#include <ctime>
54#include <chrono>
55#include <atomic>
56
57// Eigen library for linear algebra
58#include "Eigen/Core"
59
60// Personal includes
61#include "IEEE488Instrument.h"
62#include "THM1176Types.h"
63
64 using namespace MTL::Instrument;
65
66// Supported versions.
67#define THM1176_SUPPORTED_VERSION_MIN_MAJOR 3
68#define THM1176_SUPPORTED_VERSION_MIN_MINOR 0
69
70 using namespace MTL::Instrument::THM1176Types;
71 using namespace Eigen;
72
73 namespace MTL {
74 namespace Instrument {
75
76 //----------------------------------------------------------------------//
77 // Constants
82 static const I32 THM1176_NO_ANGLE_CORRECTION_CODE = 208;
83
84 //----------------------------------------------------------------------//
85 // Class definition
96 template <class InstrType, class RsrcMgrType>
97 class CTHM1176Instrument: public InstrType
98 {
99 //----------------------------------------------------------------------//
100 // Private Attributes //
101 //----------------------------------------------------------------------//
102 private:
103 // General
104 mutable CRecursiveMutex m_Lock;
105 U32 m_Timeout;
106 std::string m_Identification;
107 sIdentifier m_IdentificationStruct;
108 CErrorList m_ErrorList;
109 CSCPIBuffer m_ReadBuffer;
110 CAbsoluteTimestamp m_BootTime;
111 CFluxList m_Ranges;
112 std::map<eUnits,U32> m_Units;
113 Matrix3f m_RotationMatrix;
114 std::string m_ManufacturingDate;
115 std::string m_CalibrationDate;
116 eUnits m_UnitsParms;
117 sAveraging<uParm> m_AveragingParms;
118 sInputTrigger<uParm> m_TriggerParms;
119 sRange<uParm> m_RangeParms;
120 eCommunicationFormat m_Format;
121 bool m_Sleep;
122 bool m_UseCalibration;
123 sAveraging<uParm> m_AveragingParmsAtInit;
124 sInputTrigger<uParm> m_TriggerParmsAtInit;
125 std::vector<std::chrono::high_resolution_clock::time_point> m_TriggerTimes;
126 std::atomic_bool m_AbortRead;
127
128 //----------------------------------------------------------------------//
129 // Utilities //
130 //----------------------------------------------------------------------//
131 private:
132 bool ReadIdentification(std::string & rIdentification);
133 bool ParseIdentification(struct sIdentifier & rIdentification);
134 bool GetErrorList(CErrorList & rList, const std::string & rContext);
135 bool ReadBootTime(CAbsoluteTimestamp & rBootTime);
136 bool ReadAllRanges(CFluxList & rRanges);
137 bool ReadAllUnits(std::map<eUnits,U32> & rAllUnits);
138 bool ReadUseCalibration(bool & rUseCal);
139 bool ReadManufacturingDate(std::string & rDate);
140 bool ReadRotationMatrix(Matrix3f & rMatrix, std::string & rCalibrationDate);
141 bool ApplyRotationMatrix(tFlux & rBx, tFlux & rBy, tFlux & rBz);
142 bool ApplyRotationMatrix(CFluxList & rBx, CFluxList & rBy, CFluxList & rBz);
143 bool ParseMeasurements(CSCPIBufferParser & rBP, eUnits Units, CFluxList & rMeas, U32 NoMeasurements = 0);
144
145 //----------------------------------------------------------------------//
146 // THM1176 Interface //
147 //----------------------------------------------------------------------//
148 public:
149 //----------------------------------------------------------------------//
150 // Constructors / destructors
154 CTHM1176Instrument(RsrcMgrType & rResourceManager, tResourceName ResourceName);
155
157 virtual ~CTHM1176Instrument();
158
159 //----------------------------------------------------------------------//
160 // General Information
163 const CErrorList & CurrentErrorList();
164
166 void ClearErrorList();
167
168 //----------------------------------------------------------------------//
169 // Open / Close
175 bool Connect(U32 InitialTimeout, bool Exclusive = true, std::string *pErrMsg = nullptr);
176
178 void Disconnect();
179
180 //----------------------------------------------------------------------//
181 // Parameters
182 // Averaging
186 bool ParmAveragingSet(const sAveraging<uParm> & rAvg);
187
191 bool ParmAveragingGet(sAveraging<uParm> & rAvg);
192
196 bool ParmAveragingGet(sAveraging<sBoundedParm> & rAvg);
197
198 // Sleep
202 bool ParmSleepSet(bool Sleep);
203
207 bool ParmSleepGet(bool & rSleep);
208
209 // Trigger
213 bool ParmTriggerInputSet(const sInputTrigger<uParm> & rInputTrig);
214
218 bool ParmTriggerInputGet(sInputTrigger<uParm> & rInputTrig);
219
223 bool ParmTriggerInputGet(sInputTrigger<sBoundedParm> & rInputTrig);
224
225 // Units
229 bool ParmUnitsSet(eUnits Units);
230
234 bool ParmUnitsGet(eUnits & rUnits);
235
236 // Use Calibration
240 bool ParmUseCalibrationSet(bool UseCal);
241
245 bool ParmUseCalibrationGet(bool & rUseCal);
246
247 // Range
251 bool ParmRangeSet(const sRange<uParm> & rRange);
252
256 bool ParmRangeGet(sRange<uParm> & rRange);
257
261 bool ParmRangeGet(sRange<sBoundedParm> & rRange);
262
263 //----------------------------------------------------------------------//
264 // Files
270 bool ReadFileDirectory(U32 & rUsedBytes, U32 & rAvailableBytes, tFileList & rFileList);
271
276 bool ReadFile(std::string Path, std::string & rContent);
277
278 //----------------------------------------------------------------------//
279 // Initiate / Abort / Trigger
283 bool Initiate(bool Continuous = false);
284
287 bool Abort(void);
288
291 bool SendBusTrigger();
292
293 //----------------------------------------------------------------------//
294 // Measurements / Data
309 bool MeasurementsGet(U32 NoMeasurements,
310 CFluxList & rBx, CFluxList & rBy, CFluxList & rBz,
311 eUnits & rUnits, U16 & rTemp, CTimestampList & rTimestampList,
312 sMeasurementConditions * pMeasurementConditions = NULL);
313
328 bool MeasurementsGet(sArbitraryMeasurements ArbSelect,
329 CFluxList & rBx, CFluxList & rBy, CFluxList & rBz,
330 eUnits & rUnits, U16 & rTemp, CTimestampList & rTimestampList,
331 sMeasurementConditions * pMeasurementConditions = NULL);
332
336 bool SetFormat(eCommunicationFormat Format);
337
341 bool GetFormat(eCommunicationFormat & Format);
342
343 //----------------------------------------------------------------------//
344 // High Level Measurement
354 bool Measure(tFlux & rBx, tFlux & rBy, tFlux & rBz,
355 bool DefaultParms = true, eUnits Units = kT,
356 tFlux ExpectedField = 0., unsigned int NoDigits = 0);
357
368 bool Measure(CFluxList & rBx, CFluxList & rBy, CFluxList & rBz, unsigned int NoMeasurements = 1,
369 bool DefaultParms = true, eUnits Units = kT,
370 tFlux ExpectedField = 0., unsigned int NoDigits = 0);
371
372 //----------------------------------------------------------------------//
373 // Status Handling
376 bool StatusPreset();
377
382 bool StatusGet(sStatusRegister Reg, U16 & rStatus);
383
388 bool StatusGet(RegisterList Regs, StatusValues & rStatus);
389
398 bool StatusSetEnableRegister(eStatusRegisterSet Set, U16 DisableMask, U16 EnableMask);
399
400 //----------------------------------------------------------------------//
401 // Utilities
406 bool WriteAndRead(const std::string & rWriteStr, CSCPIBuffer & rReadBuffer);
407
411 bool GetIdentification(std::string & rIdentification);
412
416 bool GetIdentification(sIdentifier & rIdentification);
417
421 bool GetAllRanges(CFluxList & rRanges);
422
427 inline bool ConvertTimestamp(const U64 RawTimestamp, CAbsoluteTimestamp & rTimestamp)
428 {
429 rTimestamp = m_BootTime + CAbsoluteTimestamp(0, RawTimestamp);
430 return true;
431 };
432
436 bool GetAllUnits(CUnitsList & rUnits);
437
442 bool GetDivisor(eUnits Units, U32 & rDivisor);
443
447 bool GetRotationMatrix(Matrix3f & Matrix);
448
454 bool GetImmediateMeasurementPeriod(const sAveraging<uParm> & rAvg, eModelRevision modelRev, F64 & rPeriod);
455
463 bool CalibrateZeroOffset(bool ForceCalibration = false);
464
467 bool RestoreZeroOffset();
468
471 bool Reset();
472
479 bool SwitchToDFUMode();
480
487 bool ReadInformationDates(std::string & rSManufacturingDate, std::time_t & rManufacturingDate, std::string & rSCalibrationDate, std::time_t & rCalibrationDate);
488
495 bool AbortRead();
496
497 };
498
499 } // namespace Instrument
500} // namespace MTL
IEEE488Instrument.h
Abstract IEEE488 instrument class: interface definition.
U64
unsigned long long U64
64-bit unsigned integer.
Definition OSDefines.h:32
I32
int I32
32-bit signed integer.
Definition OSDefines.h:27
U32
unsigned int U32
32-bit unsigned integer.
Definition OSDefines.h:31
F64
double F64
64-bit floating-point number.
Definition OSDefines.h:34
U16
unsigned short U16
16-bit unsigned integer.
Definition OSDefines.h:30
THM1176Types.h
Type definitions for C++ API for Metrolab THM1176/TFM1186.
MTL::Instrument::CSCPIBuffer
Instrument Buffer.
Definition SCPIInstrumentBuffer.h:44
MTL::Instrument::CSCPIBufferParser
SCPI buffer parser.
Definition SCPIInstrumentBuffer.h:217
MTL::Instrument::CTHM1176Instrument::StatusPreset
bool StatusPreset()
Reset OPERation and QUEStionable enable registers.
Definition THM1176.cpp:1890
MTL::Instrument::CTHM1176Instrument::ParmAveragingGet
bool ParmAveragingGet(sAveraging< uParm > &rAvg)
Fetch the currently selected averaging parameter.
Definition THM1176.cpp:958
MTL::Instrument::CTHM1176Instrument::GetIdentification
bool GetIdentification(std::string &rIdentification)
Fetch the intrument's identification string.
Definition THM1176.cpp:2010
MTL::Instrument::CTHM1176Instrument::ReadFileDirectory
bool ReadFileDirectory(U32 &rUsedBytes, U32 &rAvailableBytes, tFileList &rFileList)
Read the instrument's file directory information.
Definition THM1176.cpp:1354
MTL::Instrument::CTHM1176Instrument::StatusGet
bool StatusGet(sStatusRegister Reg, U16 &rStatus)
Fetch current value of a single status register.
Definition THM1176.cpp:1899
MTL::Instrument::CTHM1176Instrument::~CTHM1176Instrument
virtual ~CTHM1176Instrument()
Destructor.
Definition THM1176.cpp:835
MTL::Instrument::CTHM1176Instrument::ParmUseCalibrationGet
bool ParmUseCalibrationGet(bool &rUseCal)
Fetch parameter whether to return calibrated results.
Definition THM1176.cpp:1227
MTL::Instrument::CTHM1176Instrument::Initiate
bool Initiate(bool Continuous=false)
Initiate measurements.
Definition THM1176.cpp:1463
MTL::Instrument::CTHM1176Instrument::GetAllRanges
bool GetAllRanges(CFluxList &rRanges)
Fetch all the intrument's ranges.
Definition THM1176.cpp:2030
MTL::Instrument::CTHM1176Instrument::ParmUnitsGet
bool ParmUnitsGet(eUnits &rUnits)
Fetch currently selected measurement units.
Definition THM1176.cpp:1186
MTL::Instrument::CTHM1176Instrument::SetFormat
bool SetFormat(eCommunicationFormat Format)
Select whether data is returned as text or binary.
Definition THM1176.cpp:1699
MTL::Instrument::CTHM1176Instrument::ParmSleepGet
bool ParmSleepGet(bool &rSleep)
Fetch parameter whether to sleep after each acquisition.
Definition THM1176.cpp:1020
MTL::Instrument::CTHM1176Instrument::ParmRangeSet
bool ParmRangeSet(const sRange< uParm > &rRange)
Set measurement range.
Definition THM1176.cpp:1237
MTL::Instrument::CTHM1176Instrument::Abort
bool Abort(void)
Abort a measurement in progress.
Definition THM1176.cpp:1479
MTL::Instrument::CTHM1176Instrument::ReadInformationDates
bool ReadInformationDates(std::string &rSManufacturingDate, std::time_t &rManufacturingDate, std::string &rSCalibrationDate, std::time_t &rCalibrationDate)
Fetch the intrument's date information.
Definition THM1176.cpp:2261
MTL::Instrument::CTHM1176Instrument::Connect
bool Connect(U32 InitialTimeout, bool Exclusive=true, std::string *pErrMsg=nullptr)
Open the connection to the instrument.
Definition THM1176.cpp:866
MTL::Instrument::CTHM1176Instrument::Measure
bool Measure(tFlux &rBx, tFlux &rBy, tFlux &rBz, bool DefaultParms=true, eUnits Units=kT, tFlux ExpectedField=0., unsigned int NoDigits=0)
High-level measurement: single measurement.
Definition THM1176.cpp:1773
MTL::Instrument::CTHM1176Instrument::Disconnect
void Disconnect()
Close the connection to the instrument.
Definition THM1176.cpp:933
MTL::Instrument::CTHM1176Instrument::CTHM1176Instrument
CTHM1176Instrument(RsrcMgrType &rResourceManager, tResourceName ResourceName)
Constructor.
Definition THM1176.cpp:828
MTL::Instrument::CTHM1176Instrument::ParmTriggerInputSet
bool ParmTriggerInputSet(const sInputTrigger< uParm > &rInputTrig)
Set trigger input parameters.
Definition THM1176.cpp:1030
MTL::Instrument::CTHM1176Instrument::GetDivisor
bool GetDivisor(eUnits Units, U32 &rDivisor)
Fetch divisor to convert instrument's base units to given units.
Definition THM1176.cpp:2054
MTL::Instrument::CTHM1176Instrument::ParmRangeGet
bool ParmRangeGet(sRange< uParm > &rRange)
Fetch currently selected measurement range.
Definition THM1176.cpp:1263
MTL::Instrument::CTHM1176Instrument::AbortRead
bool AbortRead()
Abort a read operation.
Definition THM1176.cpp:2316
MTL::Instrument::CTHM1176Instrument::StatusSetEnableRegister
bool StatusSetEnableRegister(eStatusRegisterSet Set, U16 DisableMask, U16 EnableMask)
Disable and enable bits in the given enable register.
Definition THM1176.cpp:1974
MTL::Instrument::CTHM1176Instrument::WriteAndRead
bool WriteAndRead(const std::string &rWriteStr, CSCPIBuffer &rReadBuffer)
Write an arbitrary command and read the result.
Definition THM1176.cpp:324
MTL::Instrument::CTHM1176Instrument::ParmUnitsSet
bool ParmUnitsSet(eUnits Units)
Set measurement units.
Definition THM1176.cpp:1164
MTL::Instrument::CTHM1176Instrument::GetImmediateMeasurementPeriod
bool GetImmediateMeasurementPeriod(const sAveraging< uParm > &rAvg, eModelRevision modelRev, F64 &rPeriod)
Compute measurement interval for Immediate Trigger, for a given averaging parameter.
Definition THM1176.cpp:2081
MTL::Instrument::CTHM1176Instrument::ConvertTimestamp
bool ConvertTimestamp(const U64 RawTimestamp, CAbsoluteTimestamp &rTimestamp)
Convert a raw timestamp to UNIX Epoch time and nanoseconds.
Definition THM1176.h:427
MTL::Instrument::CTHM1176Instrument::ReadFile
bool ReadFile(std::string Path, std::string &rContent)
Read a file from the instrument's file system.
Definition THM1176.cpp:1419
MTL::Instrument::CTHM1176Instrument::ParmAveragingSet
bool ParmAveragingSet(const sAveraging< uParm > &rAvg)
Set the averaging parameter.
Definition THM1176.cpp:946
MTL::Instrument::CTHM1176Instrument::Reset
bool Reset()
Reset the instrument to power-on configuration.
Definition THM1176.cpp:2198
MTL::Instrument::CTHM1176Instrument::SendBusTrigger
bool SendBusTrigger()
Send a USB bus trigger.
Definition THM1176.cpp:1488
MTL::Instrument::CTHM1176Instrument::CalibrateZeroOffset
bool CalibrateZeroOffset(bool ForceCalibration=false)
Perform the Zero Offset calibration procedure.
Definition THM1176.cpp:2107
MTL::Instrument::CTHM1176Instrument::ParmSleepSet
bool ParmSleepSet(bool Sleep)
Set parameter whether to sleep after each acquisition.
Definition THM1176.cpp:1010
MTL::Instrument::CTHM1176Instrument::ParmTriggerInputGet
bool ParmTriggerInputGet(sInputTrigger< uParm > &rInputTrig)
Fetch current trigger input parameters.
Definition THM1176.cpp:1068
MTL::Instrument::CTHM1176Instrument::SwitchToDFUMode
bool SwitchToDFUMode()
Enter the Device Firmware Upgrade mode.
Definition THM1176.cpp:2251
MTL::Instrument::CTHM1176Instrument::GetAllUnits
bool GetAllUnits(CUnitsList &rUnits)
Fetch all units supported by instrument.
Definition THM1176.cpp:2042
MTL::Instrument::CTHM1176Instrument::ParmUseCalibrationSet
bool ParmUseCalibrationSet(bool UseCal)
Set whether to return calibrated results.
Definition THM1176.cpp:1210
MTL::Instrument::CTHM1176Instrument::GetRotationMatrix
bool GetRotationMatrix(Matrix3f &Matrix)
Fetch the intrument's rotation matrix, to correct angular error.
Definition THM1176.cpp:2074
MTL::Instrument::CTHM1176Instrument::RestoreZeroOffset
bool RestoreZeroOffset()
Restore the factory values for the Zero Offset.
Definition THM1176.cpp:2167
MTL::Instrument::CTHM1176Instrument::GetFormat
bool GetFormat(eCommunicationFormat &Format)
Retrieve whether data is returned as text or binary.
Definition THM1176.cpp:1736
MTL::Instrument::CTHM1176Instrument::CurrentErrorList
const CErrorList & CurrentErrorList()
Fetch current error list.
Definition THM1176.cpp:848
MTL::Instrument::CTHM1176Instrument::MeasurementsGet
bool MeasurementsGet(U32 NoMeasurements, CFluxList &rBx, CFluxList &rBy, CFluxList &rBz, eUnits &rUnits, U16 &rTemp, CTimestampList &rTimestampList, sMeasurementConditions *pMeasurementConditions=NULL)
Retrieve measurements: short form.
Definition THM1176.cpp:1507
MTL::Instrument::CTHM1176Instrument::ClearErrorList
void ClearErrorList()
Clear the error list.
Definition THM1176.cpp:854
MTL::Instrument::THM1176Types::CAbsoluteTimestamp
Timestamp for a measurement.
Definition THM1176Types.h:551
MTL::Instrument::THM1176Types::CErrorList
List of errors returned by the instrument.
Definition THM1176Types.h:232
MTL::Instrument::THM1176Types::CFluxList
List of flux density values.
Definition THM1176Types.h:170
MTL::Instrument::THM1176Types::CTimestampList
List of timestamps.
Definition THM1176Types.h:576
MTL::Instrument::THM1176Types::CUnitsList
List of measurement units.
Definition THM1176Types.h:194
MTL::Instrument::THM1176Types::RegisterList
List of SCPI status registers.
Definition THM1176Types.h:66
MTL::Instrument::THM1176Types::StatusValues
List of values returned for several SCPI status registers.
Definition THM1176Types.h:76
MTL::Instrument::THM1176Types
Definition THM1176TypeConversions.h:20
MTL::Instrument::THM1176Types::tFlux
F32 tFlux
Flux density value, as 32-bit floating-point number.
Definition THM1176Types.h:30
MTL::Instrument::THM1176Types::eCommunicationFormat
eCommunicationFormat
Enumeration of possible formats for returned data.
Definition THM1176Types.h:466
MTL::Instrument::THM1176Types::tFileList
std::vector< sFile > tFileList
List of directory entries.
Definition THM1176Types.h:532
MTL::Instrument::THM1176Types::eModelRevision
eModelRevision
THM1176 type A or B.
Definition THM1176Types.h:347
MTL::Instrument::THM1176Types::eUnits
eUnits
Enumeration of possible measurement units.
Definition THM1176Types.h:182
MTL::Instrument::THM1176Types::kT
@ kT
Tesla.
Definition THM1176Types.h:183
MTL::Instrument::THM1176Types::eStatusRegisterSet
eStatusRegisterSet
Enumeration of SCPI status register sets.
Definition THM1176Types.h:37
MTL::Instrument
Definition THM1176.h:74
MTL::Instrument::tResourceName
std::string tResourceName
IEEE488 resource name.
Definition IEEE488InstrumentTypes.h:22
MTL::Instrument::THM1176_NO_ANGLE_CORRECTION_CODE
static const I32 THM1176_NO_ANGLE_CORRECTION_CODE
Warning that angle correction was not applied.
Definition THM1176.h:82
MTL::Synchronization::CRecursiveMutex
std::recursive_mutex CRecursiveMutex
Recursive Mutex.
Definition Synchronization.h:20
MTL
Definition THM1176.h:73
MTL::Instrument::THM1176Types::sArbitraryMeasurements
Specify the measurement data to be returned.
Definition THM1176Types.h:593
MTL::Instrument::THM1176Types::sAveraging
Averaging parameter.
Definition THM1176Types.h:388
MTL::Instrument::THM1176Types::sIdentifier
Instrument's identification string - parsed version.
Definition THM1176Types.h:353
MTL::Instrument::THM1176Types::sInputTrigger
Input trigger parameter.
Definition THM1176Types.h:426
MTL::Instrument::THM1176Types::sMeasurementConditions
Summary of the parameters used to make a measurement.
Definition THM1176Types.h:619
MTL::Instrument::THM1176Types::sRange
Measurement range parameter.
Definition THM1176Types.h:479
MTL::Instrument::THM1176Types::sStatusRegister
Complete identification of a SCPI status register.
Definition THM1176Types.h:52