QCanDbcFileParse load error
-
I'm trying to use QCanDbcFileParser from PySide6, but I can't seem to load anything. Below is some sample code which loads the DBC with QFile first with no problem.
import argparse import sys from PySide6.QtCore import QFile from PySide6.QtSerialBus import QCanDbcFileParser def main(): parser = argparse.ArgumentParser() parser.add_argument("dbc_file") args = parser.parse_args() parse(args.dbc_file) def parse(dbc_file): f = QFile(dbc_file) if not f.open(QFile.OpenModeFlag.ReadOnly): sys.exit(f"QFile.open: {f.errorString()}") print("DBC File:") print(bytes(f.readAll()).decode()) parser = QCanDbcFileParser() if not parser.parse(dbc_file): sys.exit(f"QCanDbcFileParser.parse: {parser.errorString()}") if __name__ == "__main__": main()
And here is the output:
DBC File: BO_ 399 STEER_STATUS: 7 EPS SG_ STEER_TORQUE_SENSOR : 7|16@0- (-1,0) [-31000|31000] "tbd" EON SG_ STEER_ANGLE_RATE : 23|16@0- (-0.1,0) [-31000|31000] "deg/s" EON SG_ STEER_STATUS : 39|4@0+ (1,0) [0|15] "" EON SG_ STEER_CONTROL_ACTIVE : 35|1@0+ (1,0) [0|1] "" EON SG_ STEER_CONFIG_INDEX : 43|4@0+ (1,0) [0|15] "" EON SG_ COUNTER : 53|2@0+ (1,0) [0|3] "" EON SG_ CHECKSUM : 51|4@0+ (1,0) [0|15] "" EON BO_ 420 VSA_STATUS: 8 VSA SG_ ESP_DISABLED : 28|1@0+ (1,0) [0|1] "" EON SG_ USER_BRAKE : 7|16@0+ (0.015625,-1.609375) [0|1000] "" EON SG_ BRAKE_HOLD_ACTIVE : 46|1@0+ (1,0) [0|1] "" EON SG_ BRAKE_HOLD_ENABLED : 45|1@0+ (1,0) [0|1] "" EON SG_ COUNTER : 61|2@0+ (1,0) [0|3] "" EON SG_ CHECKSUM : 59|4@0+ (1,0) [0|15] "" EON BO_ 464 WHEEL_SPEEDS: 8 VSA SG_ WHEEL_SPEED_FL : 7|15@0+ (0.01,0) [0|250] "kph" EON SG_ WHEEL_SPEED_FR : 8|15@0+ (0.01,0) [0|250] "kph" EON SG_ WHEEL_SPEED_RL : 25|15@0+ (0.01,0) [0|250] "kph" EON SG_ WHEEL_SPEED_RR : 42|15@0+ (0.01,0) [0|250] "kph" EON SG_ CHECKSUM : 59|4@0+ (1,0) [0|3] "" EON QCanDbcFileParser.parse: No such file or directory
The error doesn't help much to determine the problem. Posting here first in case this is an issue with the PySide6 bindings.
-
@dhagrow Why don't you do what the documentation suggests?
https://doc.qt.io/qt-6/qcandbcfileparser.html#parse
"If the parsing failed, call the error() and errorString() methods to get the information about the error." -
@jsulm said in QCanDbcFileParse load error:
"If the parsing failed, call the error() and errorString() methods to get the information about the error."
OP already does!
if not parser.parse(dbc_file): sys.exit(f"QCanDbcFileParser.parse: {parser.errorString()}") // Output: QCanDbcFileParser.parse: No such file or directory
I think OP is asking: He shows
QFile::open()
ing the file correctly and shows its contents, so why does he get a "no such file or directory" fromparser.parse(dbc_file)
on same file path? I don't know.@dhagrow
FWIW, bool QCanDbcFileParser::parse(const QString &fileName)Note: This method expects the file contents to be encoded in UTF-8. If the file has a different encoding, decode it first, and use parseData() to extract the DBC information.
You might try passing your
f.readAll()).decode()
to bool QCanDbcFileParser::parseData(QStringView data) to see whether that succeeds? I do not know how that relates to a "no such file" failure fromQCanDbcFileParser.parse()
. -
@JonB said in QCanDbcFileParse load error:
OP already does!
You're right, did not see that in the string formatting :-)
-
@jsulm said in QCanDbcFileParse load error:
@SGaist As far as I can see OP is passing a path to the file
Indeed, I misread the reading/printing and parse call !
@dhagrow, @JonB has a point with regard to UTF-8.
Also, on which OS are you seeing this issue ?
-
@JonB said in QCanDbcFileParse load error:
@SGaist said in QCanDbcFileParse load error:
Except that error "no such file or directory" does not sound like that, does sound like it's not finding the file. Or a strange message.
Indeed, I was just adding more weight with regard to using parseData which was related to my original question about it although it was mainly because I misread the code sample.