Try to Fix read errors.

This commit is contained in:
2026-01-04 00:40:53 +01:00
parent 193579e798
commit c36e9053c4
4 changed files with 75 additions and 22 deletions

View File

@@ -185,17 +185,74 @@ void BCDriverTinyCan::resetDriver()
TransmitResult BCDriverTinyCan::readRawByte( uint32_t deviceID, uint8_t registerID ) const
{
qDebug() << " --- CAN Read Byte: Device: "<< deviceID << " register: " << registerID << " TRY! ";
struct TCanMsg msg;
int err, retry = 20;
int timeout = 80;
unsigned char receipient = (unsigned char) deviceID;
unsigned char reg = (unsigned char) registerID;
msg.MsgFlags = 0L;
msg.Id = receipient;
msg.MsgLen = 2;
msg.MsgData[0] = 0x00;
msg.MsgData[1] = reg;
CanTransmit(0, &msg, 1);
while(timeout-- && CanTransmitGetCount(0))
bc::delay_millis( cTIMEOUT_MS );
if (timeout == -1)
qDebug() << "error: could not send value to node ";
retry:
timeout = 80;
while(timeout-- && !CanReceiveGetCount(0))
bc::delay_millis( cTIMEOUT_MS );
if (timeout == -1)
{
qDebug() << "error: no response from node";
return 0;
}
if ((err = CanReceive(0, &msg, 1)) > 0)
{
if (--retry && (msg.Id != BIB || msg.MsgLen != 4 || msg.MsgData[1] != reg))
goto retry;
if (!retry)
{
qDebug() << "XXX error: no response from node";
return 0;
}
qDebug() << " --- CAN Read Byte: Device: "<< deviceID << " register: " << registerID << " BYTE: " << (uint32_t) msg.MsgData[3];
return (unsigned int) msg.MsgData[3];
}
else
{
qDebug() << "Error:" <<err;
}
return 0;
/*
//TransmitResult
qDebug() << " --- BCDriverTinyCan::readRawByte DriverState: " << getDriverState();
if( _driverState <DriverState::Opened )
return std::unexpected(QString("readRawValue error: driver not loaded." ) );
unsigned char receipient = (unsigned char ) deviceID;
::TCanMsg msg;
// msg verpacken
msg.MsgFlags = 0L;
msg.Id = deviceID;
msg.Id = receipient;//deviceID;
msg.MsgLen = 2;
msg.MsgData[0] = 0x00;
msg.MsgData[1] = registerID;
@@ -244,13 +301,14 @@ retry:
if( !timeOuts )
return std::unexpected(QString("CAN response errror: timeout" ));
qDebug() << " --- CAN Read Byte: " << (uint32_t) msg.MsgData[3] << " Device:: "<< deviceID << " register: " << registerID;
return (uint32_t) msg.MsgData[3];
*/
}
// void BCDriverTinyCan::setValue( unsigned char receipient, unsigned char reg, unsigned char value )
TransmitResult BCDriverTinyCan::writeRawByte( uint32_t deviceID, uint8_t registerID ,uint8_t value ) const
TransmitResult BCDriverTinyCan::writeRawByte( uint32_t deviceID, uint8_t registerID, uint8_t value ) const
{
if( _driverState <DriverState::Opened )
@@ -261,6 +319,7 @@ TransmitResult BCDriverTinyCan::writeRawByte( uint32_t deviceID, uint8_t registe
::TCanMsg msg;
int timeout_count = cTIMEOUT_COUNT;
msg.MsgFlags = 0L;
msg.Id = deviceID;
msg.MsgLen = 4;