Skip to main content

Microsoft Visual C++ LIN Slave Simulation Program

Screen Layout

C++ LIN Slave Simulation Program
ItemDescription
Start buttonStarts monitoring and response transmission based on the response ID list.
Send Wakeup buttonSends a wakeup pulse.
Stop buttonStops monitoring and response transmission based on the response ID list.
Log display area
(area ①)
Displays transmitted/received log information.
Up to 100 log entries are retained. If exceeded, older entries are cleared first.
If monitoring is restarted after stopping, all previously displayed logs are cleared.
For display content, see Log Display Details.
DataSwitches response data in the response ID list using radio buttons.
For response details, see Response ID List.

Log Display Details

ItemDescription
msecDisplays timestamp (milliseconds).
usecDisplays timestamp (microseconds).
DirDisplays log direction.
Rx: receive log / Tx: transmit log
TypeDisplays log type or error content.
FormatDisplays the following depending on log type.
Header: SyncBreak width / Wakeup: wakeup pulse width
IDDisplays LIN ID in hexadecimal.
DLDisplays data length (1 to 8).
DataDisplays data (D1 to D8) in hexadecimal, separated by commas.
ChecksumDisplays checksum in hexadecimal.

Response ID List

The response ID list is as follows.

IDDLData (Hex)
D1D2D3D4D5D6D7D8
12H
(*1)
234HBCH
270HF8H
34H
(*1)
880H91HA2HB3HC4HD5HE6HF7H
8FBHEAHD9HC8H73H62H51H40H

*1: If Type A is selected in the Data radio buttons, the upper row is used. If Type B is selected, the lower row is used.

Error Handling

The following cases are treated as errors. An error dialog is shown and the program exits.

  • MicroPeckerX is not detected when the program starts.
  • API calls fail at start/stop of monitoring, or during monitoring.

Implementation Example (Source Code with Comments)

Source: MPXCtrl_LIN_CPP_SlvSample/MPXCtrl_LIN_CPP_SlvSample/Form1.h

// 1) Open
StMPXDeviceInfo devices[1] = {};
unsigned char count = 0;
ER ret = MPXOpen(devices, 1, &count);
if (ret != E_OK || count == 0) return;
unsigned long serial = devices[0].Serial;

// 2) Set parameters for LIN Slave
StMPXLINParam lin = {};
lin.Mode = MPX_LIN_MODE_SLAVE;
lin.Revision = MPX_LIN_REV_21;
lin.Baudrate = 19200;
ret = MPXLINSetParam(serial, &lin);
if (ret != E_OK) return;

// 3) Set response ID list
StMPXLINSlaveSim slave = {};
// Configure response frames for ID=0x12 and ID=0x34
slave.Item[0x12].Enabled = MPX_LIN_SIM_ENA;
slave.Item[0x34].Enabled = MPX_LIN_SIM_ENA;
ret = MPXLINSetSlaveSim(serial, &slave);
if (ret != E_OK) return;

// 4) Configure log mode and start
MPXSetGetLogMode(serial, MPX_INNERCH_LIN, MPX_GETLOGMODE_GETLOGAPI);
ret = MPXMonitorStart(serial, MPX_SYNC_MASTER);
if (ret != E_OK) return;

// 5) Optional operations
// Send wakeup
MPXLINSlaveWakeup(serial);

// Change data for ID=0x12 dynamically
StMPXLINSlaveSimItem item = slave.Item[0x12];
item.Frame.Data[0] = 0x00;
MPXLINChangeSlaveItem(serial, 0x12, &item);

// 6) Stop
unsigned long mSec = 0;
unsigned short uSec = 0;
MPXMonitorStop(serial, &mSec, &uSec);
MPXClose();