This function calculates the optimal prescale and bitMap combination to achieve
the closest possible baud rate to the target value. The calculation uses the formula:
baudRate = 5_500_000 / (2^(prescale + 1) * bitMap)
Parameters
baudRate: number
The target baud rate (e.g., 19200, 9600)
Optionaldevice: string
The optional device name when multiple devices are connected
Returns Promise<number>
Returns a promise that resolves with the actual baud rate achieved
The function automatically calculates the best combination of:
- lincableCustomBaudRatePrescale (range: 0-7, corresponding to /2, /4, /8, /16, /32, /64, /128, /256)
- lincableCustomBaudRateBitMap (range: 1-32)
to minimize the difference between target and actual baud rate.
Example
// Set baud rate to 19200 constactualBaudRate = awaitlinBaudRateCtrl(19200); console.log(`Actual baud rate: ${actualBaudRate}`);
// Set baud rate on specific device constactualBaudRate = awaitlinBaudRateCtrl(9600, 'Device1');
Control the baud rate of a LIN device
This function calculates the optimal prescale and bitMap combination to achieve the closest possible baud rate to the target value. The calculation uses the formula:
baudRate = 5_500_000 / (2^(prescale + 1) * bitMap)