Skip to main content

Multi-Device Control Start Guide

This page is an implementation guide for controlling multiple MicroPeckerX units (two or more) at the same time.
The key points are to pass the Serial values obtained by MPXOpen correctly to each API and to keep the start/stop order consistent.

Scope and Prerequisites​

  • Use MPXOpen(Devices, Num, Count) for device detection.
  • Each API operates a specific device by specifying Serial.
  • For log acquisition, use MPXSetGetLogMode (optional) + MPXGetLog / MPXCANGetLogEx / MPXLINGetLogEx.
  • Up to 4 devices can be recognized simultaneously by MPXOpen.

Implementation Flow (Common)​

  1. Get the device list with MPXOpen.
  2. Determine roles from Devices[i].Serial (for example, Master/Slave).
  3. Set communication parameters for each device.
  4. Set log acquisition mode for each device (optional).
  5. Execute MPXMonitorStart in Slave -> Master order.
  6. Run a log acquisition loop per device.
  7. Execute MPXMonitorStop in Master -> Slave order.
  8. Finish with MPXClose.

Important Rules (Multi-Device)​

  • Start order: start the slave side first, then the master side last.
  • Stop order: stop the master side first, then the slave side last.
  • Role management: use Serial as the identifier instead of array index.

CAN/LIN Quick Difference Table​

  • Communication parameter setup:
    • CAN/CAN FD: MPXCANSetParam + StMPXCANParam
    • LIN: MPXLINSetParam + StMPXLINParam
  • Channel specification:
    • CAN/CAN FD: InnerCh=1/2
    • LIN: no InnerCh in MPXLINSetParam
  • Log acquisition:
    • CAN/CAN FD: MPXCANGetLogEx + StMPXCANLog
    • LIN: MPXLINGetLogEx + StMPXLINLog

C/C++ Implementation Examples (Key Points)​

Pass the serial numbers of the physical devices to use as Master and Slave in masterSerialToUse and slaveSerialToUse, respectively. The roles are assigned by matching them against the device information returned by MPXOpen.

#include "MPXCtrlFree.h"
#include <chrono>
#include <thread>

void RunCANExample(uint32_t masterSerialToUse, uint32_t slaveSerialToUse) {
StMPXDeviceInfo devices[4] = {};
uint8_t count = 0;
MPXOpen(devices, 4, &count);

uint32_t serialMaster = 0;
uint32_t serialSlave = 0;
bool masterFound = false;
bool slaveFound = false;

for (uint8_t i = 0; i < count; i++) {
if (devices[i].Serial == masterSerialToUse) {
serialMaster = devices[i].Serial;
masterFound = true;
} else if (devices[i].Serial == slaveSerialToUse) {
serialSlave = devices[i].Serial;
slaveFound = true;
}
}

// Continue only after both the specified Master and Slave devices are found
if (!masterFound || !slaveFound) {
MPXClose();
return;
}

// CAN/CAN FD: Configure both CH1 and CH2
StMPXCANParam p1 = {};
StMPXCANParam p2 = {};
p1.EnableTerminate = MPX_CAN_TERMINATE_ENABLE;
p1.Mode = MPX_CAN_MODE_MONITOR; // Operate CH1 in monitor mode
p1.ArbitrationBaudrate = MPX_CAN_PARAM_ABR_500K;
p1.ArbitrationSamplepoint = MPX_CAN_PARAM_SP_80P;
p1.DataBaudrate = MPX_CAN_PARAM_DBR_2M;
p1.DataSamplepoint = MPX_CAN_PARAM_SP_80P;
p2 = p1;
p2.Mode = MPX_CAN_MODE_NONE; // Disable CH2

MPXCANSetParam(serialSlave, 1, &p1);
MPXCANSetParam(serialSlave, 2, &p2);
MPXCANSetParam(serialMaster, 1, &p1);
MPXCANSetParam(serialMaster, 2, &p2);

// MPXSetGetLogMode is optional
MPXSetGetLogMode(serialSlave, 1, MPX_GETLOGMODE_GETLOGAPI);
MPXSetGetLogMode(serialMaster, 1, MPX_GETLOGMODE_GETLOGAPI);

MPXMonitorStart(serialSlave, MPX_SYNC_SLAVE);
MPXMonitorStart(serialMaster, MPX_SYNC_MASTER);

StMPXCANLog logMaster[256] = {};
StMPXCANLog logSlave[256] = {};
uint16_t cntMaster = 0;
uint16_t cntSlave = 0;
uint8_t ovMaster = 0;
uint8_t ovSlave = 0;

for (int i = 0; i < 200; i++) {
MPXCANGetLogEx(serialMaster, 1, logMaster, 256, &cntMaster, &ovMaster);
MPXCANGetLogEx(serialSlave, 1, logSlave, 256, &cntSlave, &ovSlave);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}

uint32_t ms = 0;
uint16_t us = 0;
MPXMonitorStop(serialMaster, &ms, &us);
MPXMonitorStop(serialSlave, &ms, &us);
MPXClose();
}

Common Mistakes​

  • Treating devices[0] as Master unconditionally (detection order is not fixed)
  • Not passing the array size to Num in MPXOpen
  • Accessing devices[1] without checking Count
  • Reversing start/stop order for multi-device operation
  • Not setting both InnerCh=1/2 for CAN
  • Calling MPXLINSetParam with 3 arguments for LIN