class bscan: api for read-out and control of a bscan3 b-sensor system

35
Class BsCan: API for read-out and control of a BsCAN3 B-sensor system Version/Issue: 0.0/6 1 Class BsCan: API for read-out and control of a BsCAN3 B-sensor system Document Version: 0.0 Document ID: CERN-PH-DT-DI-2012-xxx Document Date: 7 Feb 2013 Document Status: Draft Abstract This document describes and is a user manual for the BsCan C++ class, which provides users with an API for integrating a BsCAN3 B-field sensor system into their C++ or C application. Institutes and Authors: CERN, Geneva and NIKHEF, Amsterdam: H. Boterenbrood Table 1 Document Change Record Title: Class BsCan: API for read-out and control of a BsCAN3 B-sensor system ID: CERN-PH-DT-DI-2012-xxx Version Issue Date Comment 0.0 1 13 May 2012 First version. 0.0 2 17 May 2012 Some corrections and additions. 0.0 3 25 July 2012 Added mBATCAN trigger input configuration capability, B-sensor ADC calibration with offset/gain averaging with a limit on value spread (sigma), and a blocking wait-for-data function. Updated introduction and requirements sections. 0.0 4 29 August 2012 Updated requirements section. 0.0 5 4 November 2012 Minor changes to text. 0.0 6 7 February 2013 Minor changes to text and requirements section.

Upload: others

Post on 12-Sep-2021

19 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Version/Issue: 0.0/6

1

Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Document Version: 0.0

Document ID: CERN-PH-DT-DI-2012-xxx

Document Date: 7 Feb 2013

Document Status: Draft

Abstract This document describes and is a user manual for the BsCan C++ class, which provides users with an API for integrating a BsCAN3 B-field sensor system into their C++ or C application.

Institutes and Authors:

CERN, Geneva and NIKHEF, Amsterdam: H. Boterenbrood

Table 1 Document Change Record

Title: Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

ID: CERN-PH-DT-DI-2012-xxx

Version Issue Date Comment

0.0 1 13 May 2012 First version.

0.0 2 17 May 2012 Some corrections and additions.

0.0 3 25 July 2012

Added mBATCAN trigger input configuration capability, B-sensor ADC calibration with offset/gain averaging with a limit on value spread (sigma), and a blocking wait-for-data function. Updated introduction and requirements sections.

0.0 4 29 August 2012 Updated requirements section.

0.0 5 4 November 2012 Minor changes to text.

0.0 6 7 February 2013 Minor changes to text and requirements section.

Page 2: Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Version/Issue: 0.0/6

2

Table of Contents 1 INTRODUCTION 5

2 REFERENCES 5

3 HOW TO USE THE LIBRARY 6 3.1 REQUIREMENTS 6 3.2 CONFIGURATION 6 3.3 DATA-ACQUISITION 8

4 SOME TOOLS 9 4.1 BLOCATOR 9 4.2 BSCAN3UI 11

5 BSCAN CLASS MEMBER FUNCTIONS 12 5.1 OVERVIEW 12 5.2 CONFIGURATION RELATED MEMBER FUNCTIONS 15

5.2.1 BsCan 15 5.2.2 setCanPort 15 5.2.3 connected 15 5.2.4 getConfiguration 16 5.2.5 bSensorProbe 16 5.2.6 bSensorProbeInProgress 16 5.2.7 bSensorReset 17 5.2.8 bSensorResetInProgress 17 5.2.9 bSensorProbeAtPowerup 17 5.2.10 setBsensorProbeAtPowerup 18 5.2.11 triggerInputEnabled 18 5.2.12 triggerInputRisingEdge 18 5.2.13 setTriggerInputEnabled 19 5.2.14 nodeCount 19 5.2.15 bSensorCount 19 5.2.16 bSensorStringCount 20 5.2.17 bSensorFirstIndex 20 5.2.18 nodeId 20 5.2.19 nodeFirmwareVersion 21 5.2.20 bSensorNodeId 21 5.2.21 bSensorRemoteIndex 21 5.2.22 bSensorIdHi 21 5.2.23 bSensorIdLo 22

Page 3: Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Version/Issue: 0.0/6

3

5.2.24 bSensorId 22 5.2.25 bSensorIdString 22 5.2.26 bSensorOffsets 22 5.2.27 bSensorGains 23 5.2.28 bSensorErrStatus 23 5.2.29 bSensorError 24 5.2.30 getBsensorErrStatus 24 5.2.31 getBsensorOffsGains 24 5.2.32 configSummaryString 25 5.2.33 setCalibConstFile 25 5.2.34 calibConstFile 25

5.3 DATA-ACQUISITION RELATED MEMBER FUNCTIONS 26 5.3.1 setReadoutTriggerSec 26 5.3.2 setReadoutTriggerMsec 26 5.3.3 readoutTriggerMsec 26 5.3.4 triggerSingleReadout 26 5.3.5 bSensorDataAvailable 27 5.3.6 bSensorWaitDataAvailable 27 5.3.7 bSensorWaitDataAbort 27 5.3.8 bSensorDataRaw 28 5.3.9 bSensorDataCalibrated 28 5.3.10 bSensorDataHallRaw 29 5.3.11 bSensorDataTemperature 29 5.3.12 bSensorDataRelease 29 5.3.13 dataTimeStampString 30 5.3.14 dataTimeStampMsec 30

Page 4: Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Version/Issue: 0.0/6

4

5.4 OTHER MEMBER FUNCTIONS 31 5.4.1 bSensorAdcCalibrate 31 5.4.2 bSensorSelect 32 5.4.3 bSensorDeselect 32 5.4.4 nodeErrStatus 32 5.4.5 errStatus 33 5.4.6 clearErrStatus 33 5.4.7 errString 33 5.4.8 emgCount 34 5.4.9 emgClear 34 5.4.10 emgTimeStampString 34 5.4.11 emgDataString 35 5.4.12 emgDescription 35 5.4.13 version 35

Page 5: Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Version/Issue: 0.0/6

5

1 Introduction A BsCAN3 magnetic-field sensor system [1] consists of multiple B-sensor modules

connected to multiple BATCAN [2] and/or mBATCAN [3] modules connected to a single CAN bus. The CAN bus is connected to a CAN interface in a PC where the user’s application software is running.

The BsCan class is a C++ class developed to support and simplify the integration of such a system into the user’s (C++) application.

The library containing the BsCan class also contains a set of C wrapper-functions matching each of BsCan’s member functions, providing a user with all of the BsCan class functionality for an application written in C. (Internally the C library functions access a single static BsCan class object instance, invisible to the user).

The BsCan class hides all (CAN/CANopen) communication details involved in controlling and reading out a BsCAN3 system (see [2] and [3] for that), but provides the user with full access to the configuration and control over the data-acquisition, as well as feedback about errors in the system such as failing B-sensor modules.

The software comes as a number of (static and shared) libraries, including a Qt (class) library [5] used to simplify porting of the code between different operating systems (For example, a BsCan object is multi-threaded and Qt provides a portable thread class).

There are versions of the library available for both Windows and Linux. The current library supports CAN interfaces from Kvaser [4] under Windows (on request also available for interfaces from National Instruments, SYSTEC and PEAK), and SocketCAN compatible interfaces (from various manufacturers, e.g. PEAK, SYSTEC) under Linux (native Kvaser also supported). The user should have the appropriate driver or drivers for his interface installed on his PC or laptop (this is not part of the software described here).

This document describes the member functions of the class in detail, provides some examples of their use, and also briefly describes some ready-to-use tools developed using this class and library, which may come in handy for the BsCAN3 system user.

2 References [1] F. Bergsma, H. Boterenbrood,

“BsCAN3, A Modular 3D Magnetic-Field Sensor System with CANopen Readout”, CERN / NIKHEF, 13 May 2012, http://www.nikhef.nl/pub/departments/ct/po/html/Bsensor/BsCAN3.pdf

[2] H. Boterenbrood, “BATCAN, module for single B-sensor readout by CAN-bus and CANopen” version 1.3, NIKHEF, 5 Jul 2012, http://www.nikhef.nl/pub/departments/ct/po/html/Bsensor/BATCAN.pdf

[3] H. Boterenbrood, “mBATCAN, module for multiple B-sensor readout by CAN-bus and CANopen” version 1.1, NIKHEF, 6 Jul 2012, http://www.nikhef.nl/pub/departments/ct/po/html/Bsensor/mBATCAN.pdf

[4] http://www.kvaser.com [5] http://qt.digia.com

Page 6: Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Version/Issue: 0.0/6

6

3 How to use the library

3.1 Requirements To develop an application using the BsCan class a number of files are required:

- for WINDOWS these are

• Link libraries: CANopen.lib, BsCAN.lib, QtCore4.lib

• Shared libraries: KvaserInterface.dll, (NiCanInterface.dll), CANopen.dll, BsCAN.dll, QtCore4.dll

• Include files: bscan.h, stdint.h, bscan_c.h (the latter for the ‘C’ API)

• Alternatively CANopen.lib and BsCAN.lib are delivered as static libraries.

- for LINUX these are

• Shared libraries: libSocketCanInterface.so, libKvaserInterface.so, libCANopen.so, libBsCAN.so, libQtCore.so

• Include files: bscan.h, bscan_c.h (the latter for the ‘C’ API)

Drivers (and API) for the CAN interface used, must have been installed too, and the corresponding API library and include files should be added to the user’s development project.

If the tools described in section 4 are used library QtGui4(.lib/.dll/.so) is required as well.

NB: for the library to work properly, BATCAN modules must have firmware version 1.1.1 (“BC11.0001”) or later and mBATCAN modules firmware 3.1.3 (“Bs31.0003”) or later.

NB: if you have the latest version of the B-sensor module (‘v8’) you need at least BATCAN firmware v1.2.0 and/or mBATCAN firmware v3.2.0, respectively.

3.2 Configuration To gain access to a BsCAN3 system instantiate a BsCan class object providing a CAN port number or subseqently call its member setCanPort() (it is in fact possible to call setCanPort() with different port numbers to switch between 2 different BsCAN3 systems).

Example of connecting to a BsCAN3 system on CAN port 1: BsCan bsystem; bsystem.setCanPort(1);

If all goes well the BsCan object now holds an ordered list of connected (m)BATCAN modules (in the order they were found on the CAN bus) and an ordered list of B-sensor modules connected to these (m)BATCAN modules. In this document we call a (m)BATCAN module sometimes ‘CAN node’ or just ‘node’ and a B-sensor module ‘sensor’. Actions are usually done for one node or sensor at a time on the basis of the index in the list held by BsCan or are done for all modules or sensors in the system.

This can be seen in the class member functions overview in section 5.1, where an index (to a node or to a B-sensor) is often a parameter of the function. A reserved value of this parameter (BSCAN_ALL) indicates the action is to be done for all nodes or sensors.

Page 7: Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Version/Issue: 0.0/6

7

Now one can inspect the B-sensor configuration, e.g. the number of connected CAN nodes, the number of connected B-sensor modules, and their 64-bit ID, their current (error) status or the contents of their ADC’s Offset and Gain registers. This can be useful to check for example, if the number of nodes and sensors is according to what is expected.

Here is a simple example: // Display some info about each BsCAN3 CAN module for( uint32_t i=0; i<bsystem.nodeCount(); ++i ) { cout << i << “: CAN addr “ << bsystem.nodeId(i) << “ has “ << bsystem.bSensorCount(i) << “ B-sensors” << endl; } // Display some info about each B-sensor module for( uint32_t i=0; i<bsystem.bSensorCount(); ++i ) { cout << i << “: “ << bsystem.bSensorErrStatus(i) << “, ” << bsystem.bSensorIdString(i) << endl; }

For convenience there is function configSummaryString() which returns a human-readable string containing a complete description of the connected BsCAN3 system. See section 5.2.32 for an example.

In addition one can actively probe for (new) B-sensors in the system, which is especially relevant for the mBATCAN modules in the system connecting to multiple B-sensor modules:

// Initiate probe operation (which may last several seconds) bsystem.bSensorProbe(); // Wait for the probe operation to finish() while( bsystem.bSensorProbeInProgress() ) sleep(1);

A probe operation may be particularly useful when an mBATCAN module has been configured to remember its configuration (using call setBsensorProbeAtPowerup(); this needs to be done only once, this configuration parameter is stored by the module), which means it does not automatically include newly added B-sensor modules at power-up.

By default though an mBATCAN module probes for B-sensors every time it powers up, meaning that if for any reason a connected B-sensor module is malfunctioning at that moment and it is not found in the probe operation, it will simply not be present in the newly found configuration. The BsCan index values of the remaining sensors then may have (partly) shifted by one due to the new ordering of sensors now that one is removed from the configuration.

If however the configuration was retained (stored in non-volatile memory in the mBATCAN module) previously, any lost B-sensor can be detected, if one checks the status of the system by means of a call to bSensorError(), to find out if there is any B-sensor in error, and multiple calls to bSensorErrStatus(), to find out which of the B-sensors is (or are) at fault.

Note that a probe operation only probes on known CAN nodes; if there are new CAN nodes to discover one has to redo the call to setCanPort(). Also note that if new B-sensor CAN nodes are added to a BsCAN3 system these are automatically included at the next start up.

Page 8: Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Version/Issue: 0.0/6

8

3.3 Data-acquisition In order to do data-acquisition of B-sensor data a timer can be set to trigger the B-sensor modules at regular intervals, set in seconds by setReadoutTriggerSec(), or in milliseconds by setReadoutTriggerMsec(), or one can provide a readout trigger oneself by calling triggerSingleReadout().

If there are many B-sensors it make take some time for all data to arrive. One can poll for new data to be available by calling bSensorDataAvailable() or using the blocking call (with configurable time-out) bSensorWaitDataAvailable() to wait until data becomes available.

In any case, one must always call bSensorDataRelease() to enable a next trigger.

Here is a simple example of timer-triggered data-acquisition: // Set the acquisition trigger interval to 5 seconds bsystem.setReadoutTriggerSec( 5 ); // Reserve space for one set of B-sensor data items int32_t *data = new int32_t[bsystem.bSensorCount()*4] while(1) { // Wait for a new set of data to become available (7 secs) if( !bsystem.bSensorWaitDataAvailable( 7000 ) ) continue; // Read the (raw) data if( bsystem.bSensorDataRaw( data ) ) { // Do something with the acquired data... // …… } // Display the trigger’s timestamp cout << “T=” << bsystem.dataTimeStampString() << endl; // Ready for the next trigger bsystem.bSensorDataRelease(); }

Page 9: Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Version/Issue: 0.0/6

9

If calibrated B-sensor readings are required bSensorDataCalibrated() should be called instead of bSensorDataRaw(). A file containing the calibration constants of the B-sensor modules used must be available. By default BsCan searches for file “caldat.dat” in the current directory, but a filename and path for the file can be set using setCalib-ConstFile().

During data-acquisition it is recommended to check regularly for any errors occurring in the system, which is done by

1. checking the error status of the B-sensors using bSensorError() and then if necessary on a sensor-by-sensor basis using bSensorErrStatus().

2. checking the global error status of the CAN nodes using errStatus() and then if necessary on a node-by-node basis by using nodeErrStatus().

3. checking for socalled Emergency messages on the CAN bus using emgCount(), emgDescription() and possibly emgClear(). Note that reported Emergencies are often related to B-sensor errors and will also be seen in the error status of the B-sensors (see point 1.), but there may be other messages related to the functioning in general of the nodes as CAN nodes.

4 Some tools The software tools described in this chapter have been created using the BsCan class described in this document in combination with the Qt class libraries [5] (version 4.7.2).

4.1 Blocator The Blocator tool displays a summary overview of all the B-sensor modules in a connected BsCAN3 system and allows selecting individual modules, in order to find out where they are located physically, provided one is able to see the selection LED mounted on each B-sensor module! When a module is selected the LED remains permanently on until a next module is selected or the program is exited.

Figure 1 shows a screenshot of Blocator. The B-sensor module high-lighted with a yellow background should be the one currently selected phyiscally. The selection can be changed by a mouse-click on another module, or by using the up- and down-arrow keys.

Page 10: Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Version/Issue: 0.0/6

10

Figure 1. Blocator screenshot.

Page 11: Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Version/Issue: 0.0/6

11

4.2 BsCAN3ui An existing version of the BsCAN3ui tool (version 2.3.1) was completely rewritten to use the BsCan class library, as well as an up-to-date version of the Qt class library (version 4.7.2 instead of 2.3.0) for the user interface, and a more modern version of the (Windows) development system (Visual Studio 2008 instead of version 6).

This program can be used to connect to a BsCAN3 system, and read out the connected B-sensors with a configurable interval, displaying the data. The data is shown in the table seen in the user interface on the left and optionally can be saved to file (in ASCII strings format), in the same units as shown in the display, i.e. raw ADC counts or calibrated values in units of Tesla or Gauss (the sensor temperatures are always shown in degrees Celcius).

To enable display of calibrated values a calibration constants file containing the constants of the B-sensor modules must be available. The default name of the file is caldat.dat, but path and name can be selected using the ‘select calib file’ button.

A green Data ‘LED’ flashes briefly when a (complete) new set of data has arrived, and a yellow Err ‘LED’ switches on if an error has occurred on any of the B-sensor modules.

Figure 2. BsCAN3ui screenshot.

Page 12: Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Version/Issue: 0.0/6

12

5 BsCan Class member functions

5.1 Overview A full list of BsCAN class member functions is seen in the BsCAN class include file bscan.h, shown below. The class contains only a single member variable, i.e. a pointer to a BsCanImpl object, which is the object hiding all implementation-related stuff from the user of the BsCAN class, who only needs to include the bscan.h file (shown below) in his application code. #ifndef BSCAN_H #define BSCAN_H #include <string> #include "stdint.h" class BsCanImpl; const int BSCAN_ALL = 9999; // Error status bit definitions const int BSCAN_ERR_CANINTF = 0x01; const int BSCAN_ERR_COMM = 0x02; const int BSCAN_ERR_SENSOR = 0x04; const int BSCAN_ERR_UNDEF = 0x80; class BsCan { public: // C’tors, d’tor BsCan(); BsCan( int portno ); ~BsCan(); // Configuration bool setCanPort ( int portno ); bool getConfiguration ( bool include_offsgains = false ); bool bSensorProbe ( uint32_t node_i = BSCAN_ALL ); bool bSensorReset ( uint32_t node_i = BSCAN_ALL ); bool bSensorProbeInProgress ( uint32_t node_i = BSCAN_ALL ); bool bSensorResetInProgress ( uint32_t node_i = BSCAN_ALL ); bool bSensorProbeAtPowerup ( uint32_t node_i ); bool triggerInputEnabled ( uint32_t node_i, uint32_t trigger_input ); bool triggerInputRisingEdge ( uint32_t node_i, uint32_t trigger_input ); bool setTriggerInputEnabled ( uint32_t node_i, uint32_t trigger_input, bool enable, bool rising_edge = true ); bool setBsensorProbeAtPowerup ( uint32_t node_i, bool enable ); uint32_t nodeCount (); uint32_t bSensorCount ( uint32_t node_i = BSCAN_ALL ); uint32_t bSensorStringCount ( uint32_t node_i, uint32_t str_no ); int bSensorFirstIndex ( uint32_t node_i ); int nodeId ( uint32_t node_i ); std::string nodeFirmwareVersion ( uint32_t node_i ); int bSensorNodeId ( uint32_t i ); int bSensorRemoteIndex ( uint32_t i ); uint32_t bSensorIdHi ( uint32_t i ); uint32_t bSensorIdLo ( uint32_t i );

Page 13: Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Version/Issue: 0.0/6

13

bool bSensorId ( uint32_t i, uint8_t *id ); std::string bSensorIdString ( uint32_t i ); bool bSensorOffsets ( uint32_t i, uint32_t *offs ); bool bSensorGains ( uint32_t i, uint32_t *gain ); uint32_t bSensorErrStatus ( uint32_t i ); bool bSensorError ( ); bool getBsensorErrStatus ( uint32_t i = BSCAN_ALL ); bool getBsensorOffsGains ( uint32_t i = BSCAN_ALL ); std::string configSummaryString (); void setCalibConstFile ( std::string filename ); std::string calibConstFile (); // Data-acquisition void setReadoutTriggerSec ( int secs ); void setReadoutTriggerMsec ( int msecs ); int readoutTriggerMsec (); void triggerSingleReadout (); bool bSensorDataAvailable ( uint32_t node_i = BSCAN_ALL ); bool bSensorWaitDataAvailable ( uint32_t timeout_ms = ULONG_MAX ); void bSensorWaitDataAbort (); uint32_t bSensorDataRaw ( int32_t *data, uint32_t i = BSCAN_ALL ); uint32_t bSensorDataCalibrated ( double *data, int32_t *err, uint32_t i = BSCAN_ALL ); uint32_t bSensorDataHallRaw ( int32_t *data ); uint32_t bSensorDataTemperature ( int32_t *data ); void bSensorDataRelease (); std::string dataTimeStampString ( bool include_date = false ); long long dataTimeStampMsec (); // Various: bool bSensorAdcCalibrate ( uint32_t i, uint32_t calib_cnt, double max_sigma, double *sigma = 0, bool include_tsensor = true ); // Explicit B-sensor selection and deselection bool bSensorSelect ( uint32_t i ); bool bSensorDeselect ( uint32_t i = BSCAN_ALL ); // CAN node error status uint32_t nodeErrStatus ( uint32_t node_i ); // System error status uint32_t errStatus (); // Clear system error status void clearErrStatus (); // System error string std::string errString (); // Emergency messages stuff uint32_t emgCount (); bool emgClear ( uint32_t i = BSCAN_ALL ); std::string emgTimeStampString ( uint32_t i, bool include_date ); std::string emgDataString ( uint32_t i ); std::string emgDescription ( uint32_t i ); // Class version string std::string version (); private: BsCanImpl *_bscanImpl; }; #endif // BSCAN_H

Page 14: Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Version/Issue: 0.0/6

14

The C-functions provided have the names of the member functions as shown in bscan.h, preceded by “BsCan“ and their first lowercase letter replaced by uppercase, bool replaced by int and std::string replaced by const char*.

Here are a few examples (compare to the corresponding member functions in bscan.h above): int BsCanSetCanPort ( int portno ); int BsCanGetConfiguration ( int include_offsgains ); uint32_t BsCanBsensorCount ( uint32_t node_i ); const char *BsCanNodeFirmwareVersion( uint32_t node_i );

Note that the C-functions do not provide the default parameters.

Page 15: Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Version/Issue: 0.0/6

15

5.2 Configuration related member functions

5.2.1 BsCan SYNOPSIS

BsCan();

BsCan( int portno );

PARAMETERS

portno Number of the CAN interface port the BsCAN3 system is connected to.

DESCRIPTION

Constructor of a BsCan object instance. Instantiates 2 additional threads: one for the (optional) periodic trigger generation and one for receiving BsCAN3 messages in the background from the CAN bus. If portno is provided immediately calls setCanPort(portno) to connect to and determine the configuration of the BsCAN3 system connected to the CAN bus on that port.

5.2.2 setCanPort SYNOPSIS

bool setCanPort( int portno );

PARAMETERS

portno Number of the CAN interface port the BsCAN3 system is connected to (for the time being only interfaces from Kvaser are supported).

DESCRIPTION

Opens the requested CAN interface port number, scans the CAN bus for (m)BATCAN modules, reads their B-sensor configuration and builds up internal datastructures containing configuration data and space for B-sensor sensor data. Basically compiles a sequential list of modules found and a sequential list of B-sensors served by these modules. Any previously held configuration and/or sensor data is lost.

Returns false when anything failed during the operation; using errStatus() and nodeErrStatus()one can determine which CAN module(s) failed and using errString() a description of the last error that occurred can be obtained.

5.2.3 connected SYNOPSIS

bool connected();

PARAMETERS

None.

DESCRIPTION

Returns true if there is a connection established with a CAN port (which does not necessarily mean there are any B-sensor modules connected).

Page 16: Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Version/Issue: 0.0/6

16

5.2.4 getConfiguration SYNOPSIS

bool getConfiguration( bool include_offsgains = false );

PARAMETERS

include_offsgains Whether the B-sensor ADC offset and gain registers are read out or not. Default = false.

DESCRIPTION

Re-reads the B-sensor configuration from the currently held list of CAN nodes (determined at BsCan instantiation or when setCanPort() was called last). Rebuilds the list of known B-sensor modules. If parameter include_offsgains is set to true, the B-sensor ADC offset and gain registers are read-out as well. Note that the latter adds quite a bit of time to the duration of this call. For example, to read out the configuration from one mBATCAN module with 16 B-sensor modules takes 0.2 s without and 1.5 s with offset/gain register read-out included.

Returns false if the read-out of any item failed.

5.2.5 bSensorProbe SYNOPSIS

bool bSensorProbe( uint32_t node_i = BSCAN_ALL );

PARAMETERS

node_i Index of the CAN node where to probe.

DESCRIPTION

Initiates a socalled probe operation on CAN node with index node_i (this is BsCan’s configuration index of the node, not its CAN address), whereby a B-sensor module discovery procedure is executed.

If parameter node_i is left out the operation is initiated on all connected nodes. Note that a probe operation is only really meaningful on mBATCAN modules, where a probe operation may last several seconds.

Call bSensorProbeInProgress() repeatedly to determine if the operation has finished.

5.2.6 bSensorProbeInProgress SYNOPSIS

bool bSensorProbeInProgress( uint32_t node_i = BSCAN_ALL );

PARAMETERS

node_i Index of the CAN node to check for an ongoing probe operation.

DESCRIPTION

Returns true if there is a probe operation in progress on CAN node index node_i. If parameter node_i is left out all CAN nodes are checked for an ongoing probe operation and only if there is no probe operation ongoing on any of the nodes false is returned. A probe operation may last several seconds.

Page 17: Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Version/Issue: 0.0/6

17

5.2.7 bSensorReset SYNOPSIS

bool bSensorReset( uint32_t node_i = BSCAN_ALL );

PARAMETERS

node_i Index of the CAN node which has to reset its B-sensor(s).

DESCRIPTION

Initiates a reset operation on CAN node with index node_i (this is BsCan’s configuration index of the node, not its CAN address), whereby a reset and calibration procedure is executed on the B-sensor module ADC.

If parameter node_i is left out the operation is initiated on all connected nodes.

Call bSensorResetInProgress() repeatedly to determine if the operation has finished.

5.2.8 bSensorResetInProgress SYNOPSIS

bool bSensorResetInProgress( uint32_t node_i = BSCAN_ALL );

PARAMETERS

node_i Index of the CAN node to check for an ongoing B-sensor reset operation.

DESCRIPTION

Returns true if a B-sensor reset operation is in progress on CAN node index node_i. If parameter node_i is not provided all CAN nodes are checked for an ongoing probe operation. A reset operation can last several seconds on mBATCAN modules depending on the number of connected B-sensors.

5.2.9 bSensorProbeAtPowerup SYNOPSIS

bool bSensorProbeAtPowerup( uint32_t node_i );

PARAMETERS

node_i Index of the (mBATCAN) CAN node.

DESCRIPTION

Returns true if the mBATCAN module is configured to probe for B-sensors at every power-up and false if it has a fixed configuration. To redetermine its configuration call bSensorProbe(). Only applies to mBATCAN modules.

Page 18: Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Version/Issue: 0.0/6

18

5.2.10 setBsensorProbeAtPowerup SYNOPSIS

bool setBsensorProbeAtPowerup( uint32_t node_i, bool enable );

PARAMETERS

node_i Index of the (mBATCAN) CAN node.

enable Parameter setting true or false.

DESCRIPTION

Configures the CAN node with index node_i to probe or not probe for B-sensors at power-up. This setting is stored onboard in non-volatile memory and does not have to be repeated. Only applies to mBATCAN modules.

Returns true if the setting and storage of the setting succeeded.

5.2.11 triggerInputEnabled SYNOPSIS

bool triggerInputEnabled( uint32_t node_i, uint32_i trigger_input );

PARAMETERS

node_i Index of the (mBATCAN) CAN node.

trigger_input Index of the mBATCAN’s trigger input [0..3].

DESCRIPTION

Returns true if the mBATCAN module’s indicated trigger input is enabled (i.e. a signal transition triggers read-out of all B-sensors connected to this module), and false if not. Only relevant for mBATCAN-type modules.

5.2.12 triggerInputRisingEdge SYNOPSIS

bool triggerInputRisingEdge( uint32_t node_i, uint32_i trigger_input );

PARAMETERS

node_i Index of the (mBATCAN) CAN node.

trigger_input Index of the mBATCAN’s trigger input [0..3].

DESCRIPTION

Returns true if the mBATCAN module’s indicated trigger input is set to trigger on a rising-edge signal and false if on falling-edge. Only relevant for mBATCAN-type modules.

Page 19: Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Version/Issue: 0.0/6

19

5.2.13 setTriggerInputEnabled SYNOPSIS

bool setTriggerInputEnabled( uint32_t node_i, uint32_i trigger_input, bool enable, bool rising_edge = true );

PARAMETERS

node_i Index of the (mBATCAN) CAN node.

trigger_input Index of the mBATCAN’s trigger input [0..3].

enable Enable or disable this trigger input by true or false.

rising_edge Set rising- or falling-edge signal for this trigger input.

DESCRIPTION

. Configures trigger input trigger_input (valid values 0 to 3) of the CAN node with index node_i, enabling or disabling the input by parameter enable and setting the trigger signal on a rising- or falling-edge signal by parameter rising_edge. This setting is stored onboard in non-volatile memory and does not have to be repeated. Only applies to mBATCAN modules.

Returns true if the setting and storage of the setting succeeded.

5.2.14 nodeCount SYNOPSIS

uint32_t nodeCount();

PARAMETERS

None.

DESCRIPTION

Returns the number of CAN nodes (BATCAN and/or mBATCAN) present in the connected BsCAN3 system.

5.2.15 bSensorCount SYNOPSIS

uint32_t bSensorCount( uint32_t node_i = BSCAN_ALL );

PARAMETERS

node_i Index of the CAN node.

DESCRIPTION

Returns the number of B-sensors connected to the CAN node with index node_i, or the total number of B-sensors in the connected BsCAN3 system, if parameter node_i is left out.

Page 20: Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Version/Issue: 0.0/6

20

5.2.16 bSensorStringCount SYNOPSIS

uint32_t bSensorStringCount( uint32_t node_i, uint32_t str_no );

PARAMETERS

node_i Index of the CAN node.

str_no String number [0..3].

DESCRIPTION

Returns the number of B-sensors connected to string str_no of the CAN node with index node_i. An mBATCAN module has up to 4 strings numbered 0 to 3. A BATCAN module always has 1 B-sensor on string ‘0’ and 0 on the other strings, which in reality do not exist. This is a convenience function.

5.2.17 bSensorFirstIndex SYNOPSIS

int bSensorFirstIndex( uint32_t node_i );

PARAMETERS

node_i Index of the CAN node.

DESCRIPTION

Returns the index in the list of B-sensor modules containing the first B-sensor of the CAN node with index node_i. Starting from this index the next bSensorCount(node_i) B-sensors in the list are connected to this CAN node. Returns -1 if no B-sensor is connected to this node. This is a convenience function.

5.2.18 nodeId SYNOPSIS

int nodeId( uint32_t node_i );

PARAMETERS

node_i Index of the CAN node.

DESCRIPTION

Returns the CAN identifier or CAN address of the CAN node with index node_i. Returns -1 if a node with that index does not exist. This is a convenience function.

Page 21: Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Version/Issue: 0.0/6

21

5.2.19 nodeFirmwareVersion SYNOPSIS

std::string nodeFirmwareVersion( uint32_t node_i );

PARAMETERS

node_i Index of the CAN node.

DESCRIPTION

Returns the version of the firmware in the CAN node with index node_i. Returns an empty string if a node with that index does not exist. This is a convenience function.

The current version string of a BATCAN module is “BC11.0001” and of an mBATCAN module is “Bs31.0004” (also see the example in configSummaryString()).This is a convenience function.

5.2.20 bSensorNodeId SYNOPSIS

int bSensorNodeId( uint32_t i );

PARAMETERS

i Index of the B-sensor module.

DESCRIPTION

Returns the CAN node’s CAN identifier (address) the B-sensor with index i is connected to. This is a convenience function.

5.2.21 bSensorRemoteIndex SYNOPSIS

int bSensorRemoteIndex( uint32_t i );

PARAMETERS

i Index of the B-sensor module.

DESCRIPTION

Returns the socalled remote index of the B-sensor with index i. The remote index is the index this B-sensor has on the CAN node it is connected to (for example: on an mBATCAN module the first module on its 2nd string has (remote) index 32; there is no relation with the index this B-sensor module has in the current BsCAN3 system). This is a convenience function.

5.2.22 bSensorIdHi SYNOPSIS

uint32_t bSensorIdHi( uint32_t i );

PARAMETERS

i Index of the B-sensor module.

DESCRIPTION

Returns the 4 upper bytes of the B-sensor’s 64-bit ID as a 4-byte unsigned integer.

Page 22: Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Version/Issue: 0.0/6

22

5.2.23 bSensorIdLo SYNOPSIS

uint32_t bSensorIdLo( uint32_t i );

PARAMETERS

i Index of the B-sensor module.

DESCRIPTION

Returns the 4 lower bytes of the B-sensor’s 64-bit ID as a 4-byte unsigned integer.

5.2.24 bSensorId SYNOPSIS

bool bSensorId( uint32_t i, uint8_t *id );

PARAMETERS

i Index of the B-sensor module.

id Pointer to location where the ID is to be stored.

DESCRIPTION

Writes the 8-byte ID of the B-sensor into the location pointed to by id.

Returns true if an ID is returned in id (if B-sensor index exists)

5.2.25 bSensorIdString SYNOPSIS

std::string bSensorIdString( uint32_t i );

PARAMETERS

i Index of the B-sensor module.

DESCRIPTION

Returns the 8-byte ID of the B-sensor as a string (of size 16 characters) or an empty string if the B-sensor index does not exist.

5.2.26 bSensorOffsets SYNOPSIS

bool bSensorOffsets( uint32_t i, uint32_t *offs );

PARAMETERS

i Index of the B-sensor module.

offs Pointer to location where the ADC offsets are to be stored.

DESCRIPTION

Writes the four (signed 24-bits significant) Offset registers of the ADC of the B-sensor into the location pointed to by offs. If necessary first reads the register values from the B-sensor module ADCs.

NB: may interfere with data-acquisition ! Stop data-acquisition before using.

Page 23: Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Version/Issue: 0.0/6

23

New Offset register values are determined by the node at each reset or power-up but should on average not vary much.

Returns true if values are returned in offs (if B-sensor index exists and proper register values are read from the ADC).

5.2.27 bSensorGains SYNOPSIS

bool bSensorGains( uint32_t i, uint32_t *gain );

PARAMETERS

i Index of the B-sensor module.

gain Pointer to location where the ADC gains are to be stored.

DESCRIPTION

Writes the four (signed 24-bits significant) Gain registers of the ADC of the B-sensor into the location pointed to by gain. If necessary first reads the register values from the B-sensor module ADCs.

NB: may interfere with data-acquisition ! Stop data-acquisition before using.

New Gain register values are determined by the node at each reset or power-up but should on average not vary much.

Returns true if values are returned in gain (if B-sensor index exists and proper register values are read from the ADC).

5.2.28 bSensorErrStatus SYNOPSIS

uint32_t bSensorErrStatus( uint32_t i );

PARAMETERS

i Index of the B-sensor module.

DESCRIPTION

Returns the error status word of the B-sensor (0 if the B-sensor index does not exist). The following error status word values are defined:

0x01 ADC reset error, 0x02 ADC calibration error, 0x04 ADC conversion time-out, 0xFF ADC absent, not used or not in configuration.

Page 24: Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Version/Issue: 0.0/6

24

5.2.29 bSensorError SYNOPSIS

bool bSensorError();

PARAMETERS

None.

DESCRIPTION

Returns true if any of the error statuses word of the connected B-sensor is unequal to zero. To find out which B-sensors have an error status unequal to zero use bSensorErrStatus().

5.2.30 getBsensorErrStatus SYNOPSIS

bool getBsensorErrStatus( uint32_t i = BSCAN_ALL );

PARAMETERS

i Index of the B-sensor module.

DESCRIPTION

Re-reads the error status of the B-sensor from the appropriate CAN node, or the error statuses from all B-sensors from all CAN nodes in the system, if parameter i is left out. During data-acquisition operations this function is called automatically to update the B-sensor statuses whenever an Emergency CAN message is received pertaining to a B-sensor module.

The updated error status word(s) can be inspected by calling bSensorErrStatus().

5.2.31 getBsensorOffsGains SYNOPSIS

bool getBsensorOffsGains( uint32_t i = BSCAN_ALL );

PARAMETERS

i Index of the B-sensor module.

DESCRIPTION

Re-reads the ADC Offset and Gain registers of the B-sensor from the appropriate CAN node, or the Offsets and Gains registers from all B-sensors, if parameter i is left out. This function is called once automatically when the user wants to inspect Offset or Gain register values using bSensorOffsets() and bSensorGains().

Page 25: Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Version/Issue: 0.0/6

25

5.2.32 configSummaryString SYNOPSIS

std::string configSummaryString();

PARAMETERS

None.

DESCRIPTION

Returns a string describing the currently connected BsCAN3 configuration, containing the number of nodes and sensors plus some information about each node and sensor.

Example of the output of such a string: ==> BsCAN system: KVASER Port 0, 3 Nodes, 19 B-sensors Node 33: Firmw=Bs31.0004, 17 B-sensors ( 0, 16, 0, 1) PowerupProbe=0 Node 38: Firmw=BC11.0001, 1 B-sensor ( 1, 0, 0, 0) Node 48: Firmw=BC11.0001, 1 B-sensor ( 1, 0, 0, 0) B #00 at ( 33, 32): ID=C70000000DF22005 Stat=00 B #01 at ( 33, 33): ID=EF0000000DEE6005 Stat=00 B #02 at ( 33, 34): ID=470000000DD96C05 Stat=00 B #03 at ( 33, 35): ID=480000000DF61C05 Stat=00 B #04 at ( 33, 36): ID=240000000DE0D205 Stat=00 B #05 at ( 33, 37): ID=950000000DDA3A05 Stat=00 B #06 at ( 33, 38): ID=FC0000000DD8BA05 Stat=00 B #07 at ( 33, 39): ID=2D0000000DEDAE05 Stat=00 B #08 at ( 33, 40): ID=420000000DD75105 Stat=00 B #09 at ( 33, 41): ID=610000000DDC0D05 Stat=00 B #10 at ( 33, 42): ID=9B0000000DF7FD05 Stat=00 B #11 at ( 33, 43): ID=670000000DEDA305 Stat=00 B #12 at ( 33, 44): ID=700000000DF4D305 Stat=00 B #13 at ( 33, 45): ID=570000000DD21705 Stat=01 B #14 at ( 33, 46): ID=390000000DD8EF05 Stat=00 B #15 at ( 33, 47): ID=B40000000DE93F05 Stat=00 B #16 at ( 33, 96): ID=3D0000002D653105 Stat=00 B #17 at ( 38, 0): ID=910000002D697A05 Stat=00 B #18 at ( 48, 0): ID=740000002D60D705 Stat=00

5.2.33 setCalibConstFile SYNOPSIS

void setCalibConstFile( std::string filename );

PARAMETERS

filename Name of the calibration constants file.

DESCRIPTION

Sets the path and filename of the file containing the B-sensor module calibration constants, used when calibrated B-sensor readings are required. See bSensorDataCalibrated().

5.2.34 calibConstFile SYNOPSIS

std::string calibConstFile();

PARAMETERS

None.

DESCRIPTION

Returns the currently set path and filename for the B-sensor module calibration constants file.

Page 26: Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Version/Issue: 0.0/6

26

5.3 Data-acquisition related member functions

5.3.1 setReadoutTriggerSec SYNOPSIS

void setReadoutTriggerSec( int secs );

PARAMETERS

secs The required number of seconds between B-sensor readout triggers.

DESCRIPTION

Sets the time interval between messages that trigger the readout of all B-sensor modules in the system, in seconds. Note that a next trigger is not generated before bSensorDataRelease() has been called, and then only at the fixed time interval; if the deadline for a next trigger is missed it will simply be skipped.

5.3.2 setReadoutTriggerMsec SYNOPSIS

void setReadoutTriggerMsec( int msecs );

PARAMETERS

msecs The required number of milliseconds between B-sensor readout triggers.

DESCRIPTION

See setReadoutTriggerSec().

5.3.3 readoutTriggerMsec SYNOPSIS

int readoutTriggerMsec();

PARAMETERS

None.

DESCRIPTION

Return the current setting of the time interval in milliseconds for the trigger for B-sensor readout, as set by setReadoutTriggerSec() or setReadReadoutTriggerMsec().

5.3.4 triggerSingleReadout SYNOPSIS

void triggerSingleReadout();

PARAMETERS

None.

DESCRIPTION

Sends a message to trigger the readout of all B-sensor modules.

Page 27: Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Version/Issue: 0.0/6

27

5.3.5 bSensorDataAvailable SYNOPSIS

bool bSensorDataAvailable( uint32_t node_i = BSCAN_ALL );

PARAMETERS

node_i Index of the CAN node.

DESCRIPTION

Returns true if new data is available from the CAN node with index node_i, or from all B-sensors in the system if parameter node_i is left out. Note that the presence of new data is determined on CAN-node basis, and not per B-sensor module. B-sensor data is considered ‘old’ after a call to bSensorDataRelease() has been made.

5.3.6 bSensorWaitDataAvailable SYNOPSIS

bool bSensorWaitDataAvailable( uint32_t timeout_ms = ULONG_MAX );

PARAMETERS

timeout_ms Time-out in milliseconds.

DESCRIPTION

Blocks for up to timeout_ms milliseconds (if the parameter default is used, the function blocks without time-out) or until a new (full) set of B-sensor data is available. Returns true if new data is available, and false when the time-out occurred or no data is available (e.g. when bSensorWaitDataAbort() was called).

5.3.7 bSensorWaitDataAbort SYNOPSIS

bool bSensorWaitDataAbort();

PARAMETERS

None.

DESCRIPTION

Can be used to abort a blocking call to bSensorWaitDataAvailable(), e.g. when exiting the application. Must be called from another thread, of course.

Page 28: Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Version/Issue: 0.0/6

28

5.3.8 bSensorDataRaw SYNOPSIS

uint32_t bSensorDataRaw( int32_t *data, uint32_i i=BSCAN_ALL );

PARAMETERS

data Pointer to location where the B-sensor data are to be stored.

i Index of the B-sensor module.

DESCRIPTION

Writes the most recently acquired data from the B-sensor with index i or all B-sensors in the system into the location pointed to by data. Returns the number of words written, which is equal to 4, or 4 words per B-sensor module in the system (3 Hall sensor readings in ADC counts plus 1 temperature reading in millidegrees Celcius).

5.3.9 bSensorDataCalibrated SYNOPSIS

uint32_t bSensorDataCalibrated( double *data, int32_t *err, uint32_i i=BSCAN_ALL );

PARAMETERS

data Pointer to location where the calibrated B-sensor data are to be stored.

err Pointer to location where the error status of the conversion is stored.

i Index of the B-sensor module.

DESCRIPTION

Converts the most recently acquired data from the B-sensor with index i or all B-sensors in the system and writes them into the location pointed to by data. Returns the number of words written, which is equal to 4, or 4 words per B-sensor module in the system (3 Hall sensor readings in units of Tesla plus 1 temperature reading in degrees Celcius).

In parameter err the error status of the conversion(s) are returned, whereby a value unequal to zero indicates a problem with one or more conversions. In case the data of a single B-sensor is requested (parameter i is provided and unequal to BSCAN_ALL), the following meanings can be assigned to the value of error status word err (a number of them originate from CERNLIB function DSNLEQ, a version of which is used in the conversion to calibrated B-field values):

4 Number of iterations >= MAXF, 5 Approximate (finite difference) Jacobian matrix is singular, 6 Iterations are not making good progress, 7 Iterations are diverging, 8 Iterations are converging, but either (1) XTOL is too small, or (2) convergence is very slow because the Jacobian is nearly singular near xi*, or because the variables xi are badly scaled, 12 Filename for the calibration constants file is empty / not set, 13 Failed to open the calibration constants file, 14 B-sensor ID not found in the calibration constants file.

Page 29: Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Version/Issue: 0.0/6

29

Note that a file containing the calibration constants of the system’s B-sensor modules must be available to successfully convert B-sensor data to physical B-field values. The default name for this file is caldat.dat located in the current directory, but the file name and path may be set using setCalibConstFile().

5.3.10 bSensorDataHallRaw SYNOPSIS

uint32_t bSensorDataHallRaw( int32_t *data );

PARAMETERS

data Pointer to location where the B-sensor data are to be stored.

DESCRIPTION

Like bSensorDataRaw(), except that the temperature reading of the B-sensors is not written to the location pointed to by parameter data; writes data of all B-sensors and returns the number of words written, i.e. 3 words per B-sensor module.

5.3.11 bSensorDataTemperature SYNOPSIS

uint32_t bSensorDataTemperature( int32_t *data );

PARAMETERS

data Pointer to location where the B-sensor temperature data are to be stored.

DESCRIPTION

Writes the temperature readings, in millidegrees Celcius, of the B-sensors of the system to the location pointed to by parameter data and returns the number of words written, i.e. 1 word per B-sensor module.

5.3.12 bSensorDataRelease SYNOPSIS

void bSensorDataRelease();

PARAMETERS

None.

DESCRIPTION

Indicates to the system that the current B-sensor data has been processed and a new data-acquisition trigger can be generated. A subsequent call to bSensorDataAvailable() will now return true only when new B-sensor data has been received.

Note that this call will set all currently held B-sensor data to zeroes.

Page 30: Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Version/Issue: 0.0/6

30

5.3.13 dataTimeStampString SYNOPSIS

std::string dataTimeStampString( bool include_date = false);

PARAMETERS

include_date Include the date in the returned string.

DESCRIPTION

Returns a string with the timestamp of the last data-acquisition trigger (the time the trigger was issued), with millisecond resolution.

Example without date: 18:13:46:937 Example with date: 2012-05-07 18:19:36:796

5.3.14 dataTimeStampMsec SYNOPSIS

long long dataTimeStampMsec();

PARAMETERS

None.

DESCRIPTION

Returns the timestamp of the last data-acquisition trigger as the number of milliseconds that have passed since 1970-01-01 T00:00:00.000 (Coordinated Universal Time). The return value is a 64-bit integer.

NB: the trigger time-stamp changes as soon as a trigger is sent, which could be long before the corresponding B-sensor data is actually available according to bSensorData-Available(), because the system contains many B-sensors, so the time-stamp change could be used (waiting an appropriate time for B-sensor ADC conversions to finish, which is roughly 0.5 to 1 s) to initiate further operations in a user’s application (e.g. the movement of a B-field mapper device), while the data is being acquired.

Page 31: Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Version/Issue: 0.0/6

31

5.4 Other member functions

5.4.1 bSensorAdcCalibrate SYNOPSIS

bool bSensorAdcCalibrate( uint32_t i, uint32_i calib_cnt, double max_sigma, double *sigma = 0, bool include_tsensor = true );

PARAMETERS

i Index of the B-sensor module.

calib_cnt The number of reset/calibrate sequences to execute.

max_sigma The maximum sigma allowed on any of the series of offset and gain values obtained of the 3 or 4 channels being reset/calibrated.

sigma If unequal to 0, is a pointer to a location where the sigmas of up to 4 pairs of offsets and gains will be stored, for inspection by the user.

include_tsensor Whether or not the temperature sensor channel is also included in the reset/calibrate sequences.

DESCRIPTION

. When a BsCAN system is powered the BATCAN and mBATCAN modules reset and calibrate the ADC(s) on the connected B-sensor module(s), resulting in values for ADC channel offset and gain registers, which are applied to all subseqent ADC conversions to compensate for the electronics’ offset and gain. If required, these offset and gain values can be read from the modules using bSensorOffsets() and bSensorGains().

If a user wants to be absolutely certain that the obtained offsets and gains are correct and/or wants to determine averages for these values rather than rely on a single measurement (perhaps in an electronically noisy environment), he can call this function to repeat the reset/calibrate sequence on a B-sensor module ADC a selectable number of times (calib_cnt), determine the averages of gains and offsets and –if the values fall within the maximum standard deviation (max_sigma) indicated– store these values into the appropriate B-sensor module ADC registers.

It has been found that a value of max_sigma equal to 100 is a reasonable value.

If pointer sigma is unequal to zero the standard deviations for the ADC’s 4 (or 3) channels calculated by the function will be stored in the location pointed to by it for inspection by the user. There must be enough space for an array of 8 doubles or 6 doubles (if include_tsensor is false). The values are stored in the array in the order offset 1st channel, gain 1st channel, offset 2nd channel, gain 2nd channel, etc. Note that the gain value of channels 1 to 3 (corresponding to the 3 Hall sensor inputs) are identical due the way the electronics works and the way the value is determined.

By setting include_tsensor to false, the temperature sensor channel is not included in the calibration sequences.

Note that this function takes time to complete: with calib_cnt = 5 just under 4 seconds, with calib_cnt = 3 about 2.4 seconds.

Page 32: Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Version/Issue: 0.0/6

32

5.4.2 bSensorSelect SYNOPSIS

bool bSensorSelect( uint32_t i );

PARAMETERS

i Index of the B-sensor module.

DESCRIPTION

Physically selects a particular B-sensor module; its selection LED will switch on. It serves no other purpose than to check for example the location of the module. It is used for example by the Blocator application, described in section 4.1.

Returns true if the B-sensor index exists and the communication succeeded.

5.4.3 bSensorDeselect SYNOPSIS

bool bSensorDeselect( uint32_t i = BSCAN_ALL );

PARAMETERS

i Index of the B-sensor module.

DESCRIPTION

Physically deselects B-sensor modules selected on the CAN node the B-sensor with index i is connected to, or all B-sensor modules in the system if parameter i is left out. There is normally no need to use this function, except in combination with bSensorSelect().

Returns true if the B-sensor index exists and the communication succeeded.

5.4.4 nodeErrStatus SYNOPSIS

uint32_t nodeErrStatus( uint32_t node_i );

PARAMETERS

node_i Index of the CAN node.

DESCRIPTION

Returns a bitmask indicating the error status of the CAN node. The following bits are defined:

0x02 CAN communication error occurred, 0x04 CAN communication time-out (on reply) occurred, 0x08 Failed to get configuration info from at least one B-sensor of this node, 0x80 Undefined node (i.e. invalid parameter node_i).

Call errString() to find out more about the last error that occurred.

Page 33: Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Version/Issue: 0.0/6

33

5.4.5 errStatus SYNOPSIS

uint32_t errStatus();

PARAMETERS

None.

DESCRIPTION

Returns an ‘OR’ of error status words of all CAN nodes, as returned by nodeErrStatus(), in the system. In addition to the bits there the following bit is defined:

0x01 CAN interface error

Call errString() to find out more about the last error that occurred.

5.4.6 clearErrStatus SYNOPSIS

void clearErrStatus();

PARAMETERS

None.

DESCRIPTION

Clears the error status words of all CAN nodes; does not clear B-sensor error statuses.

5.4.7 errString SYNOPSIS

std::string errString();

PARAMETERS

None.

DESCRIPTION

Returns a string with a description of the last error that occurred, which may be useful for finding problems in the system.

Some examples: canOpenChannel: Specified device not found canOpenChannel: No channels available

Page 34: Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Version/Issue: 0.0/6

34

5.4.8 emgCount SYNOPSIS

uint32_t emgCount();

PARAMETERS

None.

DESCRIPTION

Returns the number of socalled CANopen Emergency messages received and buffered. Note that up to a maximum of 100 such messages are buffered. These messages can be cleared (one-by-one or all at once) by calling emgClear() (see below) and individually inspected by calling emgDescription(), emgDataString() and emgTimeStampString().

5.4.9 emgClear SYNOPSIS

bool emgClear( uint32_t i = BSCAN_ALL );

PARAMETERS

i Index of the Emergency message.

DESCRIPTION

Clears the buffered Emergency message with index i or all Emergencies in the buffer if the parameter is left out. The messages are buffered in order of arrival, with index 0 the oldest.

NB: do not call emgClear() in the same loop inspecting the Emergencies, since emgClear() changes message buffer size and message indices.

5.4.10 emgTimeStampString SYNOPSIS

std::string emgTimeStampString( uint32_t i, bool include_date = false );

PARAMETERS

i Index of the Emergency message.

include_date Include the date in the returned string.

DESCRIPTION

Returns the arrival timestamp of Emergency message with index i as a string. For an example see section 5.3.13 on member function dataTimeStampString().

Page 35: Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Class BsCan: API for read-out and control of a BsCAN3 B-sensor system

Version/Issue: 0.0/6

35

5.4.11 emgDataString SYNOPSIS

std::string emgDataString( uint32_t i );

PARAMETERS

i Index of the Emergency message.

DESCRIPTION

Returns the contents of Emergency message with index i as a string. Refer to documents [2] and [3] for more details about Emergency messages from B-sensor CAN nodes.

Example: ID= 23 ErrCod=5000, 51 04 01 00 80

5.4.12 emgDescription SYNOPSIS

std::string emgDescription( uint32_t i );

PARAMETERS

i Index of the Emergency message.

DESCRIPTION

Returns a description of the Emergency message with index i as a string. Refer to documents [2] and [3] for more details about Emergency messages from B-sensor CAN nodes.

Example (same one as given under emgDataString()):

Node=23 B-index 4, ADC chan 1, conversion time-out

(Note that ‘B-index’ given here is the socalled ‘remote index’, the index of the B-sensor module on the CAN node in question, which is different from the index this B-sensor got from the BsCan object; see 5.2.21 on member function bSensorRemoteIndex()).

5.4.13 version SYNOPSIS

std::string version();

PARAMETERS

None.

DESCRIPTION

Returns the version of this class as a string.

Example: BsCan v1.0.0 2012-05-11