SHWotever / SimHub

Multi sim dashboard, bass shaker driver, ....
http://www.simhubdash.com/
769 stars 97 forks source link

Arduino Leonardo not read custom protocol #1669

Open Betty1909 opened 1 month ago

Betty1909 commented 1 month ago

Arduino Leonardo not read serial from simhub by using custom serial devices.

Simhub version 9.3.4

Arduino sketch

int gear = Serial.readStringUntil(';').toInt(); int hdl = Serial.readStringUntil('\n').toInt();

if((gear) == 'P')
{
setShifterStatus(shifter_status_parking);
Serial.println('OK');
}
if((gear) == 'R')
{
setShifterStatus(shifter_status_reverse);
Serial.println('OK');
}
if((gear) == 'N')
{
setShifterStatus(shifter_status_neutral);
Serial.println('OK');
}
if((gear) == 'D')
{
setShifterStatus(shifter_status_drive);
Serial.println('OK');
}
if(hdl == 1)
{
turnonBacklight();
Serial.println('HDL');
}
else
{
turnoffBacklight();
}

Simhub NCalc format([Gear], 'P') + ';' +isnull([GameRawData.light_LowBeam], 0)

It work only use Serial.read(); Arduino will report serial to simhub.

When change to Serial.readStringUntil(';').toInt(); Nothing send back to simhub.

Sorry for my bad english.

SHWotever commented 4 weeks ago

Hi ! As indicated the command string does not have any default terminator : https://github.com/SHWotever/SimHub/wiki/Custom-serial-devices#protocol-definition

Your code is likely to get stuck indefinitely on the second readstringuntil