Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opening serial port feedback #37

Open
SaeedAID opened this issue Mar 13, 2023 · 3 comments
Open

Opening serial port feedback #37

SaeedAID opened this issue Mar 13, 2023 · 3 comments

Comments

@SaeedAID
Copy link

Dear Geoffrey

Before getting to the issue I would like to thank you for your well-written code and your effort.

Well I would like you to help me to have a better understanding of a scenario that could happen, imagine the port we are trying to open is not available or disconnected, there is no feedback on the opening port so the code would crash and stop.

Can we catch the error or does the code returns an integer or boolean on the port opening so we can check it? This could help us with diagnostic errors so we put it on the while loop until the port became available.

Best regards

Saeed

@gbmhunter
Copy link
Owner

Hi @SaeedAID , I believe it throws an exception if it can't open the /dev/ttyXXX "file" for read/write access as per this screenshot of the code.

image

The exception is of the following type:

image

You should be cable to try/catch the exception to do appropriate error handling. Let me know if this does not suit your needs.

@SaeedAID
Copy link
Author

Dear Geoffrey

Thank you for your quick reply, yes I have seen that and unfortunately, I couldn't add it to my code. Can you please advise Mr on how to implement on my code or provide me an example code please

@gbmhunter
Copy link
Owner

gbmhunter commented Mar 14, 2023

Hi @SaeedAID , I think you want something like this (haven't been able to test it sorry!):

#include <CppLinuxSerial/Exception.hpp>

int main() {
  // Setup goes here
  try {
    mySerialPort.Read(data);
  } catch (mn::CppLinuxSerial::Exception e) {
    std::cout << "Error occurred while reading!" << std::endl;
  }
  // ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants