CWBudde/ComPort-Library

Comport and unpluged USB

Opened this issue · 5 comments

Hi, folks.

Do you have an effective way to disconnect the USB cable?

Unfortunately, all solutions from internet do not work.

Regards
Robert

The library was written when USB was not invented, so probably - if there is a way - it would require some extra work on top of this library.

Eventually it also depends on the manufacturer of the USB to serial port bridge. In my experiments with a cable like that (with a build-in converter) the disconnect was not the most critical problem. It was rather the connection itself. Eventually it was caused by an improper disconnection. I solved it by adding some timing delays (it seems to work after some delay).

This said, I would be too interested in further information on this topic.

Thank you for your answer,
I know that this software was developed a long time ago, but it works very well until today (except for this unfortunate USB).
I made a special LCD display based on Arduino and unfortunately sometimes someone takes out the USB plug and there is a problem.
I was making changes in CPort.pas code (exactly in AbortAllAsync procedure) to help, but it still doesn't work as it should.
After generating an exception the application is no longer stable.

If you were looking for a solution, a lot of people who use comport would be grateful.

I patched AbortAllAsync in CPort.pas. I see no other way to get rid of the "Purgecomm Function Failed" error after reconnect. I replaced
raise EComPort.Create(CError_PurgeFailed, GetLastError);
instead of:
CallException(CError_PurgeFailed, GetLastError);
as stated here: https://sourceforge.net/p/comport/discussion/261327/thread/8605e2ac/ back in 2009.

Looks like issue fixed more or less: https://github.com/raccoon-dev/ComPort-Library

I have just merged the changes from raccoon-dev. Yet untested as I currently do not have a project that uses USB for ComPort emulation.

@RobertZawadzki please close if this solves your issue.