Microsoft Visual C++ LIN Master Simulation Program
Screen Layout
| Item | Description |
|---|---|
| Start button | Starts monitoring and frame transmission based on transmission schedule. |
| Send Sleep button | Sends a sleep command. |
| Send Interrupt button | Sends interrupt transmission frame. For details, see Interrupt Transmission Frame. |
| Stop button | Stops monitoring and frame transmission based on transmission schedule. |
| Log display area (area ①) | Displays transmitted/received logs. Up to 100 logs are retained. If exceeded, old logs are cleared first. If monitoring is restarted after stop, all previous logs are cleared. For displayed fields, see Log Display Details. |
| Status | Switches LIN status by radio button. Wakeup: Run (Awake) state / Sleep: Sleep state |
| Schedule | Switches schedule by radio button. For schedule details, see Transmission Schedule. |
| Data | Switches Tx frame data in each schedule by radio button. For frame details, see Transmission Schedule. |
Log Display Details
| Item | Description |
|---|---|
| msec | Timestamp (milliseconds). |
| usec | Timestamp (microseconds). |
| Dir | Log direction. Rx: receive log / Tx: transmit log |
| Type | Log type or error content. |
| Format | Displays the following by log type. Header: SyncBreak width / Wakeup: wakeup pulse width |
| ID | LIN ID in hexadecimal. |
| DL | Data length (1 to 8). |
| Data | Data (D1 to D8) in hexadecimal, separated by commas. |
| Checksum | Checksum in hexadecimal. |
Transmission Schedule
Details of each transmission schedule are as follows.
| No. | Dir | ID | Delay | DL | Data (Hex) | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| D1 | D2 | D3 | D4 | D5 | D6 | D7 | D8 | |||||
| 0 (*1) | Tx (*2) | 10H | 500ms | 2 | 40H | C8H | ||||||
| 15H | 200ms | 2 | 15H | 9DH | ||||||||
| Rx | 11H | 500ms | - | |||||||||
| 1 (*1) | Tx (*2) | 20H | 500ms | 4 | 20H | 64H | A8H | ECH | ||||
| 25H | 400ms | 4 | 13H | 57H | 9BH | DFH | ||||||
| Rx | 21H | 500ms | - | |||||||||
*1: If #0 is selected in Schedule, No.0 schedule is used. If #1 is selected, No.1 schedule is used.
*2: If Type A is selected in Data, the upper row is used. If Type B is selected, the lower row is used.
Interrupt Transmission Frame
The interrupt transmission frame is as follows.
| Dir | ID | DL | Data (Hex) | |||||||
|---|---|---|---|---|---|---|---|---|---|---|
| D1 | D2 | D3 | D4 | D5 | D6 | D7 | D8 | |||
| Tx | 30H | 8 | 01H | 23H | 45H | 67H | 89H | ABH | CDH | EFH |
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 call fails at monitoring start/stop or during monitoring.
Implementation Example (Source Code with Comments)
Source: MPXCtrl_LIN_CPP_MstSample/MPXCtrl_LIN_CPP_MstSample/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 Master
StMPXLINParam lin = {};
lin.Mode = MPX_LIN_MODE_MASTER;
lin.Revision = MPX_LIN_REV_21;
lin.Baudrate = 19200;
ret = MPXLINSetParam(serial, &lin);
if (ret != E_OK) return;
// 3) Enable schedules
MPXLINSetMasterSchedule(serial, 0, MPX_LIN_SIM_ENA, MPX_LIN_SIM_DIS);
MPXLINSetMasterSchedule(serial, 1, MPX_LIN_SIM_ENA, MPX_LIN_SIM_DIS);
// 4) Set schedule contents
StMPXLINMasterSim sch = {};
// Set Tx/Rx frames in sch.Item[] and register
ret = MPXLINSetMasterSim(serial, 0, &sch, 2);
if (ret != E_OK) return;
ret = MPXLINSetMasterSim(serial, 1, &sch, 2);
if (ret != E_OK) return;
// 5) Set initial state and start
MPXLINChangeMasterSchedule(serial, 0);
MPXLINSetStatus(serial, MPX_LIN_STS_RUN);
MPXSetGetLogMode(serial, MPX_INNERCH_LIN, MPX_GETLOGMODE_GETLOGAPI);
ret = MPXMonitorStart(serial, MPX_SYNC_MASTER);
if (ret != E_OK) return;
// 6) Optional event
// Interrupt transmission
StMPXLINMasterSimItem interruptItem = {};
interruptItem.FrameType = MPX_LIN_FRAME_TYPE_TX;
ret = MPXLINMasterInterrupt(serial, &interruptItem);
// 7) Stop
unsigned long mSec = 0;
unsigned short uSec = 0;
MPXMonitorStop(serial, &mSec, &uSec);
MPXClose();