Skip to main content
Version: 4.00

Microsoft Visual C++ CAN Monitor Program

Screen Layout​

C++ CAN Monitor Program
ItemDescription
Start buttonClick to start monitoring.
Stop buttonClick to stop monitoring.
Log display area
(Area 1)
Displays received log information.
Up to 100 logs are retained. If exceeded, oldest logs are cleared first.
When monitoring is restarted after stop, previous logs are all cleared.
See Log Display Details.

Log Display Details​

ItemDescription
msecTimestamp (milliseconds).
usecTimestamp (microseconds).
DirLog direction.
Rx: receive log, Tx: transmit log
FormatID format.
Std: standard ID, Ext: extended ID
IDCAN ID in hexadecimal.
DLData length (0 to 64).
DataData (D1 to D64) in hexadecimal, comma-separated.

Error Handling​

Program terminates with an error dialog in the following cases.

  • MicroPeckerX could not be recognized at program startup
  • API call failed at monitoring start/stop or during monitoring

Implementation Example (Commented Source)​

Source: MPXCtrl_CANFD_CPP_MonSample/MPXCtrl_CANFD_CPP_MonSample/Form1.h

// 1) Connect and initialize
StMPXDeviceInfo devices[1] = {};
uint8_t count = 0;
ER ret = MPXOpen(devices, 1, &count);
if (ret != E_OK || count == 0) {
// device not found
return;
}
uint32_t serial = devices[0].Serial;
MPXSetLED(serial, MPX_LED_OFF, MPX_LED_OFF, MPX_LED_OFF, MPX_LED_OFF, MPX_LED_OFF);

// 2) CAN parameter setup (monitor CH1 only, disable CH2)
StMPXCANParam ch1 = {};
ch1.Mode = MPX_CAN_MODE_MONITOR;
ch1.ArbitrationBaudrate = MPX_CAN_PARAM_ABR_500K;
ch1.ArbitrationSamplepoint = MPX_CAN_PARAM_SP_80P;
ch1.DataBaudrate = MPX_CAN_PARAM_DBR_2M;
ch1.DataSamplepoint = MPX_CAN_PARAM_SP_80P;
ch1.EnableTerminate = MPX_CAN_TERMINATE_ENABLE;
ret = MPXCANSetParam(serial, 1, &ch1);
if (ret != E_OK) return;

StMPXCANParam ch2 = ch1;
ch2.Mode = MPX_CAN_MODE_NONE;
ret = MPXCANSetParam(serial, 2, &ch2);
if (ret != E_OK) return;

// 3) Start monitoring
ret = MPXMonitorStart(serial, MPX_SYNC_MASTER);
if (ret != E_OK) return;

// 4) Periodic log acquisition
StMPXCANLog logs[100];
uint16_t got = 0;
uint8_t over = 0;
ret = MPXCANGetLogEx(serial, 1, logs, 100, &got, &over);
// Display got logs. If over==MPX_LOG_BUFOVER_TRUE, some logs were dropped.

// 5) Stop and close
uint32_t mSec = 0;
uint16_t uSec = 0;
MPXMonitorStop(serial, &mSec, &uSec);
MPXClose();