Enser45 / nmodbus

Automatically exported from code.google.com/p/nmodbus
0 stars 0 forks source link

NModbus' FTDAdapter is not multi-platform (but can be very easily, and I've done it) #62

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
See the attached code.  I haven't _FULLY_ tested it yet, but this code should 
make the FTDAdapter code work on Windows, Mac, and Linux.  This is possible by 
"detecting" the current platform by catching exceptions thrown by failed 
attempts to find the DLL and then trying a different operating system's FTDI 
library name.  On the first success, the working library name is stored, 
allowing for less-clunky function calls from that point on.

There's probably a much cleaner way to do this, but this at least works.

Original issue reported on code.google.com by toddnand...@gmail.com on 19 Aug 2012 at 9:33

Attachments:

GoogleCodeExporter commented 8 years ago
Also, it would probably be better if it caught the last exception on missing 
the Mac lib and threw a new one with the system's exception text, plus text 
from the function dispatch-y code that noted the three filenames used, so 
people don't wonder why we're always trying to find .dylib files on, say, 
Windows.

Original comment by toddnand...@gmail.com on 21 Aug 2012 at 4:07