Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. QCanDbcFileParse load error

QCanDbcFileParse load error

Scheduled Pinned Locked Moved Solved Language Bindings
19 Posts 4 Posters 837 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dhagrow
    wrote on last edited by
    #1

    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.

    jsulmJ 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      You're using it wrong. That method expects a file path. Maybe you meant to use parseData ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      jsulmJ 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi and welcome to devnet,

        You're using it wrong. That method expects a file path. Maybe you meant to use parseData ?

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @SGaist As far as I can see OP is passing a path to the file

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        SGaistS 1 Reply Last reply
        0
        • D dhagrow

          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.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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."

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          JonBJ 1 Reply Last reply
          0
          • jsulmJ jsulm

            @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."

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by
            #5

            @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" from parser.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 from QCanDbcFileParser.parse().

            jsulmJ 1 Reply Last reply
            0
            • JonBJ JonB

              @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" from parser.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 from QCanDbcFileParser.parse().

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @JonB said in QCanDbcFileParse load error:

              OP already does!

              You're right, did not see that in the string formatting :-)

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • jsulmJ jsulm

                @SGaist As far as I can see OP is passing a path to the file

                SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @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 ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                JonBJ 1 Reply Last reply
                0
                • SGaistS SGaist

                  @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 ?

                  JonBJ Online
                  JonBJ Online
                  JonB
                  wrote on last edited by
                  #8

                  @SGaist said in QCanDbcFileParse load error:

                  @dhagrow, @JonB has a point with regard to UTF-8.

                  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.

                  SGaistS 1 Reply Last reply
                  0
                  • JonBJ JonB

                    @SGaist said in QCanDbcFileParse load error:

                    @dhagrow, @JonB has a point with regard to UTF-8.

                    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.

                    SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @JonB said in QCanDbcFileParse load error:

                    @SGaist said in QCanDbcFileParse load error:

                    @dhagrow, @JonB has a point with regard to UTF-8.

                    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.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      dhagrow
                      wrote on last edited by
                      #10

                      QCanDbcFileParser.parseData() does indeed work! Thanks for pointing that out, I hadn't noticed that method. I'm not sure why the encoding would matter. The contents are ASCII, which should be decoded by UTF-8 with no problem.

                      Nothing obvious strikes me from the source here, but I guess QString is not included in PySide, so I can't easily check.

                      It does seem like there should be a better error there, but this solves my immediate problem, and hopefully helps anyone else that runs into it. For the record, I'm on Linux. Thanks again!

                      JonBJ 1 Reply Last reply
                      0
                      • D dhagrow has marked this topic as solved on
                      • D dhagrow

                        QCanDbcFileParser.parseData() does indeed work! Thanks for pointing that out, I hadn't noticed that method. I'm not sure why the encoding would matter. The contents are ASCII, which should be decoded by UTF-8 with no problem.

                        Nothing obvious strikes me from the source here, but I guess QString is not included in PySide, so I can't easily check.

                        It does seem like there should be a better error there, but this solves my immediate problem, and hopefully helps anyone else that runs into it. For the record, I'm on Linux. Thanks again!

                        JonBJ Online
                        JonBJ Online
                        JonB
                        wrote on last edited by
                        #11

                        @dhagrow
                        Yes, parseData() will work, the question is why parser.parse(dbc_file) does not seem to open the file from its name. Just try making dbc_file be the correct full path to the file (not just plain "dbc_file") and check whether that makes a difference?

                        1 Reply Last reply
                        0
                        • D Offline
                          D Offline
                          dhagrow
                          wrote on last edited by dhagrow
                          #12

                          I get this error instead when I pass in a full path, or even when I use any slash, e.g. ./test.dbc.

                          QCanDbcFileParser.parse: file to open is a directory
                          
                          JonBJ 1 Reply Last reply
                          0
                          • D dhagrow

                            I get this error instead when I pass in a full path, or even when I use any slash, e.g. ./test.dbc.

                            QCanDbcFileParser.parse: file to open is a directory
                            
                            JonBJ Online
                            JonBJ Online
                            JonB
                            wrote on last edited by
                            #13

                            @dhagrow
                            Well that's very odd if it's a file and is reported as an open directory failure.
                            And also odd but maybe significant if the path alters message from "No such file or directory" to "file to open is a directory".

                            1 Reply Last reply
                            0
                            • D Offline
                              D Offline
                              dhagrow
                              wrote on last edited by
                              #14

                              I think I found the problem. I noticed that there's an overload for QCanDbcFileParser.parse that takes a QStringList. It turns out that it works if I pass in ['test.dbc']! I then tried ['t'] and ['.'] and get the same errors I was getting above. It seems PySide is wrapping the overloaded method.

                              JonBJ 1 Reply Last reply
                              0
                              • D dhagrow

                                I think I found the problem. I noticed that there's an overload for QCanDbcFileParser.parse that takes a QStringList. It turns out that it works if I pass in ['test.dbc']! I then tried ['t'] and ['.'] and get the same errors I was getting above. It seems PySide is wrapping the overloaded method.

                                JonBJ Online
                                JonBJ Online
                                JonB
                                wrote on last edited by
                                #15

                                @dhagrow
                                But I thought you started from passing a sting, like "dbc_file". That should match parse(fileName) where fileName – str. I don't know exactly what you tried? Where did you get dbc_file varibale value from? Be careful of you prompted the user for it with QFileDialog.getOpenFileName(), that returns a list, not just the filename.

                                I don't know whether you are now saying you are sorted or not.

                                1 Reply Last reply
                                0
                                • D Offline
                                  D Offline
                                  dhagrow
                                  wrote on last edited by
                                  #16

                                  Yes, I am sorted. The QCanDbcFileParser.parseData option was all I needed, but I see that I can also use QCanDbcFileParser.parse if I pass in the file name in a list.

                                  "dbc_file" came from a command-line argument, so effectively I was making the call like: parser.parse("test.dbc"). That appears to treat the string like a list, so with test.dbc it would try to open t, and with ./test.dbc it would try ., both of which align with the errors I was seeing. I now see that I can make the call like: parser.parse(["test.dbc"]), which works.

                                  Basically, what I am saying is that PySide is not calling QCanDbcFileParser::parse(QString). It is actually calling QCanDbcFileParser::parse(QStringList).

                                  JonBJ 1 Reply Last reply
                                  0
                                  • D dhagrow

                                    Yes, I am sorted. The QCanDbcFileParser.parseData option was all I needed, but I see that I can also use QCanDbcFileParser.parse if I pass in the file name in a list.

                                    "dbc_file" came from a command-line argument, so effectively I was making the call like: parser.parse("test.dbc"). That appears to treat the string like a list, so with test.dbc it would try to open t, and with ./test.dbc it would try ., both of which align with the errors I was seeing. I now see that I can make the call like: parser.parse(["test.dbc"]), which works.

                                    Basically, what I am saying is that PySide is not calling QCanDbcFileParser::parse(QString). It is actually calling QCanDbcFileParser::parse(QStringList).

                                    JonBJ Online
                                    JonBJ Online
                                    JonB
                                    wrote on last edited by
                                    #17

                                    @dhagrow Fine for a workaround, but if what you say is true that would apparently be a bug in PySide.

                                    1 Reply Last reply
                                    0
                                    • SGaistS Offline
                                      SGaistS Offline
                                      SGaist
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #18

                                      I agree with @JonB. A Python string shares some interfaces with the list class however it should not trigger that issue. Something is wrong with the binding. You should open a ticket on the bug report system.

                                      Interested in AI ? www.idiap.ch
                                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                      1 Reply Last reply
                                      0
                                      • D Offline
                                        D Offline
                                        dhagrow
                                        wrote on last edited by
                                        #19

                                        Issue created: https://bugreports.qt.io/browse/PYSIDE-3017

                                        1 Reply Last reply
                                        2

                                        • Login

                                        • Login or register to search.
                                        • First post
                                          Last post
                                        0
                                        • Categories
                                        • Recent
                                        • Tags
                                        • Popular
                                        • Users
                                        • Groups
                                        • Search
                                        • Get Qt Extensions
                                        • Unsolved