THM1176InstrumentDriver 1.1
C++ API for Metrolab THM1176
Loading...
Searching...
No Matches
THM1176Types.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
8#pragma once
9
10// Standard includes
11#include <string>
12#include <vector>
13#include <cmath>
14#include <ctime>
15
16// Personal includes
17#include "OSDefines.h"
19
20namespace MTL
21{
22namespace Instrument
23{
24namespace THM1176Types
25{
26
27//----------------------------------------------------------------------//
28// Basic Types //
29//----------------------------------------------------------------------//
30typedef F32 tFlux;
31
32//----------------------------------------------------------------------//
33// Status //
34//----------------------------------------------------------------------//
43
50
64
65class RegisterList : public std::vector<sStatusRegister>
66{
67};
68
75class StatusValues : public std::vector<U16>
76{
77};
78
81{
84
87 {
88 // Contains a 1-byte status summary. The THM1176 uses the following bits:
89 U8 NA0_1 : 2;
90 U8 EAV : 1;
91 U8 QSB : 1;
92 U8 MAV : 1;
93 U8 ESB : 1;
94 U8 RQS : 1;
95 U8 OSB : 1;
97};
98
100{
103
106 {
107 // Latches certain standardized events. The THM1176 uses the following bits:
109 U8 NA1 : 1;
114 U8 NA6 : 1;
117};
118
120{
123
126 {
127 // Captures conditions which are part of the instrument's normal operation. The THM1176 uses the following bits:
129 U16 NA1 : 1;
131 U16 NA3 : 1;
134 U16 NA6_15 : 10;
136};
137
139{
142
145 {
146 // Indicates conditions that may reduce the quality of the measurement. The THM1176 sets the following bits:
147 U16 NA0_4 : 5;
149 U16 NA6_8 : 3;
153};
154
155std::ostream & operator<<(std::ostream & Stream, const eStatusRegisterSet & RegSet);
156std::ostream & operator<<(std::ostream & Stream, const eStatusRegisterType & RegType);
157std::ostream & operator<<(std::ostream & Stream, const sStatusRegister & RegDef);
158std::ostream & operator<<(std::ostream & Stream, const RegisterList & RegList);
159std::ostream & operator<<(std::ostream & Stream, const StatusValues & StatusList);
160std::ostream & operator<<(std::ostream & Stream, const uStatusByte & StatusByte);
161std::ostream & operator<<(std::ostream & Stream, const uStandardEvent & StdEventReg);
162std::ostream & operator<<(std::ostream & Stream, const uOPERation & OperReg);
163std::ostream & operator<<(std::ostream & Stream, const uQUEStionable & QuestReg);
164
165//----------------------------------------------------------------------//
166// Flux //
167//----------------------------------------------------------------------//
169class CFluxList : public std::vector<tFlux>
170{
171};
172std::ostream & operator<<(std::ostream & Stream, const CFluxList & FluxList);
173
174//----------------------------------------------------------------------//
175// Units //
176//----------------------------------------------------------------------//
192
193class CUnitsList : public std::vector<eUnits>
194{
195};
196
202class CDivisorList : public std::vector<U32>
203{
204};
205std::ostream & operator<<(std::ostream & Stream, const eUnits & Units);
206std::ostream & operator<<(std::ostream & Stream, const CUnitsList & UnitsList);
207std::ostream & operator<<(std::ostream & Stream, const CDivisorList & DivisorList);
208
209//----------------------------------------------------------------------//
210// Errors //
211//----------------------------------------------------------------------//
213struct sError
214{
216 std::string Description;
217 std::string Context;
218
219public:
224 sError(I32 Code = 0, std::string Description = "", std::string Context = "")
226 { }
227 bool operator==(sError other) const;
228 bool operator!=(sError other) const;
229};
230
231class CErrorList : public std::vector<sError>
232{
233};
234std::ostream & operator<<(std::ostream & Stream, const sError & Error);
235std::ostream & operator<<(std::ostream & Stream, const CErrorList & ErrorList);
236
237//----------------------------------------------------------------------//
238// Parameters //
239//----------------------------------------------------------------------//
240//------------------------------------------//
241// Generic
244template <class DataType>
246{
247 DataType Val{};
248 DataType Min{};
249 DataType Max{};
250 DataType Def{};
251
252public:
258 sBoundedParm(DataType Val = 0, DataType Min = 0, DataType Max = 0, DataType Def = 0)
259 : Val(Val), Min(Min), Max(Max), Def(Def)
260 { }
261 void clear(void)
262 {
263 Val = { };
264 Min = { };
265 Max = { };
266 Def = { };
267 }
268 bool operator==(sBoundedParm other) const
269 {
270 return (
271 Val == other.Val &&
272 Min == other.Min &&
273 Max == other.Max &&
274 Def == other.Def
275 );
276 }
277 bool operator!=(sBoundedParm other) const
278 {
279 return (!operator==(other));
280 }
281 sBoundedParm & operator=(const DataType & scalar)
282 {
283 Val = scalar;
284 Min = scalar;
285 Max = scalar;
286 Def = scalar;
287 return *this;
288 }
289};
290
293template <class DataType>
294using uParm = DataType;
295
302template <template<class> class ParmType>
304{
306 ParmType<F64> ExampleF64;
307 ParmType<F32> ExampleF32;
308};
309
310//------------------------------------------//
311// Version
314{
315 U8 Major = 0;
316 U8 Minor = 0;
317 std::string Name = "";
318
319public:
323 sVersion(U8 Maj = 0, U8 Min = 0)
324 : Major(Maj), Minor(Min)
325 { }
326 void clear(void);
327 bool operator==(sVersion other) const;
328 bool operator!=(sVersion other) const;
329};
330std::ostream & operator<<(std::ostream & Stream, const sVersion & Version);
331
332//------------------------------------------//
333// Instrument enum model
343
344//------------------------------------------//
345// Thm Revision
348
349//------------------------------------------//
350// Identifier
353{
354 std::string Manufacturer;
355 std::string Model;
362
363public:
373 sIdentifier(std::string Mfr = "", std::string Mdl = "", U32 SN = 0, struct sVersion EVsn = { }, struct sVersion PVsn = { }, struct sVersion FVsn = { }, eModelRevision ThmRev = kA, eInstrModel InstrMdl= eInstrModel::kUnknown)
374 : Manufacturer(Mfr), Model(Mdl), SerialNumber(SN), ElectronicsVersion(EVsn), ProbeVersion(PVsn), FirmwareVersion(FVsn), ModelRevision(ThmRev), InstrModel(InstrMdl)
375 { }
376 void clear(void);
377 bool operator==(sIdentifier other) const;
378 bool operator!=(sIdentifier other) const;
379};
380std::ostream & operator<<(std::ostream & Stream, const sIdentifier & ID);
381
382//------------------------------------------//
383// Averaging
386template <template<class> class ParmType>
388{
389 ParmType<U16> NoPoints{};
390
391public:
394 sAveraging(ParmType<U16> NPts = { })
395 : NoPoints(NPts)
396 { }
397 void clear(void)
398 {
399 NoPoints = { };
400 }
401 bool operator==(sAveraging other) const
402 {
403 return (NoPoints == other.NoPoints);
404 }
405 bool operator!=(sAveraging other) const
406 {
407 return (!operator==(other));
408 }
409};
410std::ostream & operator<<(std::ostream & Stream, const sAveraging<uParm> & AvgParm);
411std::ostream & operator<<(std::ostream & Stream, const sAveraging<sBoundedParm> & AvgParm);
412
413//------------------------------------------//
414// Input Trigger
422
424template <template<class> class ParmType>
426{
428 ParmType<F64> Period_s{ };
429 ParmType<U16> Count{ };
430
431public:
436 sInputTrigger(eInputTriggerSource Src = { }, ParmType<F64> Per = { }, ParmType<U16> Cnt = { })
437 : Source(Src), Period_s(Per), Count(Cnt)
438 { }
439 void clear(void)
440 {
441 Source = { };
442 Period_s = { };
443 Count = { };
444 }
445 bool operator==(sInputTrigger other) const
446 {
447 return (
448 Source == other.Source &&
449 Period_s == other.Period_s &&
450 Count == other.Count
451 );
452 }
453 bool operator!=(sInputTrigger other) const
454 {
455 return (!operator==(other));
456 }
457};
458std::ostream & operator<<(std::ostream & Stream, const eInputTriggerSource & TrgSrc);
459std::ostream & operator<<(std::ostream & Stream, const sInputTrigger<uParm> & TrigParm);
460std::ostream & operator<<(std::ostream & Stream, const sInputTrigger<sBoundedParm> & TrigParm);
461
462//------------------------------------------//
463// Format
472std::ostream & operator<<(std::ostream & Stream, const eCommunicationFormat & CommFormat);
473
474//------------------------------------------//
475// Range
477template <template<class> class ParmType>
478struct sRange
479{
480 bool Auto{ };
481 ParmType<tFlux> Range{ };
482
483public:
487 sRange(bool A = { }, ParmType<tFlux> R = { })
488 : Auto(A), Range(R)
489 { }
490 void clear(void)
491 {
492 Auto = { };
493 Range = { };
494 }
495 bool operator==(sRange other) const
496 {
497 return (
498 Auto == other.Auto &&
499 Range == other.Range
500 );
501 }
502 bool operator!=(sRange other) const
503 {
504 return (!operator==(other));
505 }
506};
507std::ostream & operator<<(std::ostream & Stream, const sRange<uParm> & RangeParm);
508std::ostream & operator<<(std::ostream & Stream, const sRange<sBoundedParm> & RangeParm);
509
510//------------------------------------------//
511// Files
513struct sFile
514{
515 size_t Size = 0;
516 std::string Path;
517 std::string Type;
518
519public:
524 sFile(size_t S = 0, std::string P = "", std::string T = "")
525 : Size(S), Path(P), Type(T)
526 { }
527 void clear();
528 bool operator==(sFile other) const;
529 bool operator!=(sFile other) const;
530};
531
532typedef std::vector<sFile> tFileList;
533
534std::ostream & operator<<(std::ostream & Stream, const sFile & FileInfo);
535std::ostream & operator<<(std::ostream & Stream, const tFileList & FileList);
536
537//----------------------------------------------------------------------//
538// Time stamp //
539//----------------------------------------------------------------------//
551{
552private:
553 std::time_t s = 0;
554 U64 ns = 0;
555
556public:
557 static const U64 NS_PER_SEC = 1000000000;
561 CAbsoluteTimestamp(std::time_t Seconds = 0, U64 Nanoseconds = 0);
563 bool operator==(CAbsoluteTimestamp other);
564 bool operator!=(CAbsoluteTimestamp other);
565 std::time_t seconds(void) const;
566 U64 nanoseconds(void) const;
567 void clear(void);
568};
569
572std::ostream & operator<<(std::ostream & Stream, const CAbsoluteTimestamp & Timestamp);
573
575class CTimestampList : public std::vector<U64>
576{
577public:
584 bool GetEstimatedPeriod(F64 & Period);
585};
586std::ostream & operator<<(std::ostream & Stream, const CTimestampList & TimestampList);
587
588//----------------------------------------------------------------------//
589// Measurements //
590//----------------------------------------------------------------------//
593{
594 bool Bx = false;
595 bool By = false;
596 bool Bz = false;
597 bool Temperature = false;
598 bool Timestamp = false;
600
601public:
609 sArbitraryMeasurements(bool Bx = false, bool By = false, bool Bz = false, bool Temp = false, bool Time = false, U32 NMeas = 0)
610 : Bx(Bx), By(By), Bz(Bz), Temperature(Temp), Timestamp(Time), NoMeasurements(NMeas)
611 { }
612 void clear();
613 bool operator==(sArbitraryMeasurements other) const;
614 bool operator!=(sArbitraryMeasurements other) const;
615};
616
619{
622 bool UseCalibration = false;
624
625public:
631 sMeasurementConditions(sAveraging<uParm> AvgParms = { }, sInputTrigger<uParm> TrigParms= { }, bool UseCal = false, tFlux RangeIn = 0.)
632 : AveragingParms(AvgParms), TriggerParms(TrigParms), UseCalibration(UseCal), Range(RangeIn)
633 { }
634 void clear();
635 bool operator==(sMeasurementConditions other) const;
636 bool operator!=(sMeasurementConditions other) const;
637};
638
639std::ostream & operator<<(std::ostream & Stream, const sArbitraryMeasurements & MeasSpec);
640std::ostream & operator<<(std::ostream & Stream, const sMeasurementConditions & MeasCond);
641
642} // namespace THM1176Types
643} // namespace Instrument
644} // namespace MTL
Abstract IEEE488 instrument class: type definitions.
Platform Dependent Definitions.
unsigned long long U64
64-bit unsigned integer.
Definition OSDefines.h:32
unsigned char U8
Unsigned byte.
Definition OSDefines.h:29
float F32
32-bit floating-point number.
Definition OSDefines.h:33
int I32
32-bit signed integer.
Definition OSDefines.h:27
unsigned int U32
32-bit unsigned integer.
Definition OSDefines.h:31
double F64
64-bit floating-point number.
Definition OSDefines.h:34
unsigned short U16
16-bit unsigned integer.
Definition OSDefines.h:30
std::time_t seconds(void) const
Fetch the number of seconds.
bool operator!=(CAbsoluteTimestamp other)
Inequality operator.
bool operator==(CAbsoluteTimestamp other)
Equality operator.
CAbsoluteTimestamp(std::time_t Seconds=0, U64 Nanoseconds=0)
Constructor.
void clear(void)
Clear to default values (zeroes)
CAbsoluteTimestamp & operator=(const CAbsoluteTimestamp &Value)
Assignment operator.
U64 nanoseconds(void) const
Fetch the number of nanoseconds.
List of divisors, one per measurement unit.
List of errors returned by the instrument.
List of flux density values.
bool GetEstimatedPeriod(F64 &Period)
Estimate the measurement period from this timestamp list, by means of a least-squares fit.
List of SCPI status registers.
List of values returned for several SCPI status registers.
eStatusRegisterType
Enumeration of SCPI status register types.
@ kStatusEnable
Enable register.
@ kStatusCondition
Condition register.
@ kStatusEvent
Event register.
CAbsoluteTimestamp operator-(CAbsoluteTimestamp a, CAbsoluteTimestamp b)
Timestamp subtraction operator.
eInstrModel
Enumeration of instrument (THM1176-LF, THM1176-MF, ...) model.
std::ostream & operator<<(std::ostream &Stream, const eStatusRegisterSet &RegSet)
Status register set stream output.
DataType uParm
Parameter template, with only current value.
F32 tFlux
Flux density value, as 32-bit floating-point number.
eCommunicationFormat
Enumeration of possible formats for returned data.
@ kComFormatInteger
Binary (32-bit integers)
@ kComFormatPacked2Byte
Binary packed: first field value as I32, remainder deltas as I16.
@ kComFormatPacked1Byte
Binary packed: first field value as I32, remainder deltas as I8.
@ kComFormatAscii
Human-legible text.
std::vector< sFile > tFileList
List of directory entries.
eModelRevision
THM1176 type A or B.
CAbsoluteTimestamp operator+(CAbsoluteTimestamp a, CAbsoluteTimestamp b)
Timestamp addition operator.
eInputTriggerSource
Enumeration of possible trigger sources.
@ kInputTrigSrcTimer
Timed trigger: start measurement at regular intervals.
@ kInputTrigSrcImmediate
Immediate trigger: start measurement immediately after previous one completes.
@ kInputTrigSrcBus
Bus trigger: start measurement upon USB trigger message.
eUnits
Enumeration of possible measurement units.
@ kMHzp
Equivalent proton NMR resonant frequency, in Mega-Hertz.
eStatusRegisterSet
Enumeration of SCPI status register sets.
@ kStatusQuestionableStatusRegister
Questionable Status Register.
@ kStandardEventStatusRegister
Standard Event Status Register.
@ kStatusOperationStatusRegister
Operation Status Register.
Definition THM1176.h:73
Specify the measurement data to be returned.
bool Bx
Return the flux density X-component.
bool operator==(sArbitraryMeasurements other) const
Equality operator.
bool Temperature
Return the sensor temperature.
bool operator!=(sArbitraryMeasurements other) const
Inequality operator.
bool By
Return the flux density Y-component.
bool Bz
Return the flux density Z-component.
sArbitraryMeasurements(bool Bx=false, bool By=false, bool Bz=false, bool Temp=false, bool Time=false, U32 NMeas=0)
Constructor.
U32 NoMeasurements
Return this number of measurements.
sAveraging(ParmType< U16 > NPts={ })
Constructor.
bool operator!=(sAveraging other) const
Inequality operator.
ParmType< U16 > NoPoints
Number of points in block average.
void clear(void)
Clear to default (zero).
bool operator==(sAveraging other) const
Equality operator.
sBoundedParm(DataType Val=0, DataType Min=0, DataType Max=0, DataType Def=0)
Constructor.
bool operator!=(sBoundedParm other) const
Inequality operator.
sBoundedParm & operator=(const DataType &scalar)
Set value, min, max and default to given value.
void clear(void)
Clear the parameter to default values.
bool operator==(sBoundedParm other) const
Equality operator.
Error returned by the instrument.
bool operator==(sError other) const
Equality operator.
sError(I32 Code=0, std::string Description="", std::string Context="")
Constructor.
std::string Context
SCPI commands being executed at time of error.
bool operator!=(sError other) const
Inequality operator.
std::string Description
Error description.
ParmType< F32 > ExampleF32
Example of an F32 element.
ParmType< F64 > ExampleF64
Example of an F64 element.
bool ExampleState
Example of a boolean element.
Directory entry in the instrument's file system.
void clear()
Clear to default values.
bool operator==(sFile other) const
Equality operator.
bool operator!=(sFile other) const
Inequality operator.
std::string Type
File type ("ASCII" or "BINARY").
sFile(size_t S=0, std::string P="", std::string T="")
Constructor.
size_t Size
File size, in bytes.
Instrument's identification string - parsed version.
struct sVersion FirmwareVersion
Version numbers of firmware.
std::string Manufacturer
Manufacturer name ("Metrolab Technology SA")
struct sVersion ElectronicsVersion
Version numbers of electronics.
bool operator!=(sIdentifier other) const
Inequality operator.
struct sVersion ProbeVersion
Version numbers of probe.
std::string Model
Model name (e.g. "THM1176-MF")
bool operator==(sIdentifier other) const
Equality oeprator.
enum eInstrModel InstrModel
Enumerator of instrument model.
sIdentifier(std::string Mfr="", std::string Mdl="", U32 SN=0, struct sVersion EVsn={ }, struct sVersion PVsn={ }, struct sVersion FVsn={ }, eModelRevision ThmRev=kA, eInstrModel InstrMdl=eInstrModel::kUnknown)
Constructor.
enum eModelRevision ModelRevision
Revision of Model.
ParmType< U16 > Count
Trigger count: take this many measurements before sending results.
eInputTriggerSource Source
Trigger source.
sInputTrigger(eInputTriggerSource Src={ }, ParmType< F64 > Per={ }, ParmType< U16 > Cnt={ })
Constructor.
bool operator==(sInputTrigger other) const
Equality operator.
bool operator!=(sInputTrigger other) const
Inequality operator.
ParmType< F64 > Period_s
Trigger period, for timed trigger.
bool operator!=(sMeasurementConditions other) const
Inequality operator.
sMeasurementConditions(sAveraging< uParm > AvgParms={ }, sInputTrigger< uParm > TrigParms={ }, bool UseCal=false, tFlux RangeIn=0.)
Constructor.
sAveraging< uParm > AveragingParms
Averaging parameters.
sInputTrigger< uParm > TriggerParms
Trigger parameters.
bool operator==(sMeasurementConditions other) const
Equality operator.
void clear(void)
Clear to default values.
bool Auto
Auto-ranging enabled.
bool operator!=(sRange other) const
Inequality operator.
bool operator==(sRange other) const
Equality operator.
sRange(bool A={ }, ParmType< tFlux > R={ })
Constructor.
ParmType< tFlux > Range
Measurement range, if auto-ranging is not enabled.
eStatusRegisterSet Set
SCPI register set.
eStatusRegisterType Type
SCPI register type.
sStatusRegister(eStatusRegisterSet S={ }, eStatusRegisterType T={ })
Constructor.
Major and minor version numbers.
bool operator!=(sVersion other) const
Inequality operator.
void clear(void)
Clear to default (zeroes).
bool operator==(sVersion other) const
Equality operator.
sVersion(U8 Maj=0, U8 Min=0)
Constructor.
Access the Operation Status Register as bit fields.
U16 MEASuring
Measuring magnetic field strength.
Access the Questionable Status Register as bit fields.
U16 Frequency
Acquisition buffer or the timed trigger has been overrun.
Access the Standard Event Status Register as bit fields.
U8 DeviceDependentError
Errors specific to the THM1176, including internal errors.
U8 ExecutionError
Error detected during command execution.
U8 OperationComplete
*OPC has flagged operation complete
Access the Status Byte as bit fields.
U8 EAV
Error Available in Error / Event Queue.
U8 ESB
Standard Event Status Register summary bit.
Union to access the Operation Status Register as integer or bit fields.
struct MTL::Instrument::THM1176Types::uOPERation::sOPERation OPERation
Access the Operation Status Register as bit fields.
U16 RawOPER
Access the Operation Status Register as unsigned integer.
Union to access the Questionable Status Register as integer or bit fields.
U16 RawQUES
Access the Questionable Status Register as unsigned integer.
struct MTL::Instrument::THM1176Types::uQUEStionable::sQUEStionable QUEStionable
Access the Questionable Status Register as bit fields.
Union to access the Standard Event Status Register as integer or bit fields.
struct MTL::Instrument::THM1176Types::uStandardEvent::sStandardEvent StandardEvent
Access the Standard Event Status Register as bit fields.
U16 RawSE
Access the Standard Event Status Register as unsigned integer.
Union to access the Status Byte as integer or bit fields.
struct MTL::Instrument::THM1176Types::uStatusByte::sStatusByte StatusByte
Access the Status Byte as bit fields.
U16 RawSTB
Access the Status Byte as unsigned integer.