Error management in C++ on linux for devices

Hello all,

I'm software developer. I'm new on embedded devices and in c++. I've a troble about how to mange error while openning device driver and configuring the devices (hw) for the first time.

That is, in microcontrolers, it's assumed that I/O is done using processor registers, so it's assumed that allways are available, for example to access to a serial port to communicate throw LinBus. If at initialization any error is detected, a value is returned, but nothing is destroied.

In contrast, in linux, to access to a serial port, a device file must be opened (ex /dev/ttyS1), but if no serial port is available, then an error is returned. But if we develop in C++, and if no port is present, an exception is thrown, and the object in construction is destroyed. But the questions are:

- The sensor should open the bus on its constructor? If I want to reconnect to the bus, I need to recreate the sensor object, and the bus?

- It's prefereable to use a initialize function member in the driver to open the bus and configure the sensor? I can communicate with the device without initial configuration.

- So If i can open the bus, but I can't initialize the device in device driver constructor, then the device driver is destroied by the exception.

How do you manage the creation of a device driver and device initialization?

Thanks in advance. Joaquim Duran

Reply to
jduran
Loading thread data ...

Seems to me this is a "should not happen" error, which indicates some fatal flaw in your system - either your user-mode program is being sloppy (not closing the port when done) or you have multiple copies running (seen that happen!), or there's a subtle bug in the kernel/ device driver.

My preference would be to cause some kind of user-visible fatal error, get it reported back to you, and then find and solve it at the source.

If you need high uptime, log/report the error and reboot the system.

Reply to
cs_posting

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.