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)
- Get the device list with
MPXOpen. - Determine roles from
Devices[i].Serial(for example, Master/Slave). - Set communication parameters for each device.
- Set log acquisition mode for each device (optional).
- Execute
MPXMonitorStartin Slave -> Master order. - Run a log acquisition loop per device.
- Execute
MPXMonitorStopin Master -> Slave order. - 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
Serialas the identifier instead of array index.
CAN/LIN Quick Difference Table
- Communication parameter setup:
- CAN/CAN FD:
MPXCANSetParam+StMPXCANParam - LIN:
MPXLINSetParam+StMPXLINParam
- CAN/CAN FD:
- Channel specification:
- CAN/CAN FD:
InnerCh=1/2 - LIN: no
InnerChinMPXLINSetParam
- CAN/CAN FD:
- Log acquisition:
- CAN/CAN FD:
MPXCANGetLogEx+StMPXCANLog - LIN:
MPXLINGetLogEx+StMPXLINLog
- CAN/CAN FD:
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.
- CAN/CAN FD (2ch required)
- LIN
#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();
}
#include "MPXCtrlFree.h"
#include <chrono>
#include <thread>
void RunLINExample(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;
}
// LIN: MPXLINSetParam takes two arguments: Serial and Param
StMPXLINParam p = {};
p.Mode = MPX_LIN_MODE_MONITOR;
p.Revision = MPX_LIN_REV_21;
p.Baudrate = 19200;
p.SyncBreak = 13;
p.Delimiter = 1;
p.HeaderSpace = 1;
p.ResponseSpace = 1;
p.ByteSpace = 1;
p.WakeupWidth = 250;
p.WakeupWait = 0;
p.SleepTime = 4000;
for (int i = 0x00; i < 0x40; i++) {
if (i < 0x20) {
p.IDSetting[i].DL = 2;
} else if (i < 0x30) {
p.IDSetting[i].DL = 4;
} else {
p.IDSetting[i].DL = 8;
}
p.IDSetting[i].CheckSumType = MPX_LIN_PARAM_CS_CLASSIC;
}
MPXLINSetParam(serialSlave, &p);
MPXLINSetParam(serialMaster, &p);
// MPXSetGetLogMode is optional
MPXSetGetLogMode(serialSlave, MPX_INNERCH_LIN, MPX_GETLOGMODE_GETLOGAPI);
MPXSetGetLogMode(serialMaster, MPX_INNERCH_LIN, MPX_GETLOGMODE_GETLOGAPI);
MPXMonitorStart(serialSlave, MPX_SYNC_SLAVE);
MPXMonitorStart(serialMaster, MPX_SYNC_MASTER);
StMPXLINLog logMaster[256] = {};
StMPXLINLog 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++) {
MPXLINGetLogEx(serialMaster, logMaster, 256, &cntMaster, &ovMaster);
MPXLINGetLogEx(serialSlave, 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
NuminMPXOpen - Accessing
devices[1]without checkingCount - Reversing start/stop order for multi-device operation
- Not setting both
InnerCh=1/2for CAN - Calling
MPXLINSetParamwith 3 arguments for LIN
Related Pages
- Basic flow: /S810-MX-ADL2L/QuickStart/common_first
- Common API details: /S810-MX-ADL2L/Common/api_detail_common
- CAN API details: /S810-MX-ADL2L/CAN/api_detail_can
- LIN API details: /S810-MX-ADL2L/LIN/api_detail_lin