The strategy you follow when writing good drivers for LabVIEW is greatly depending on the framework or test application where you want to use that driver.
In my opinion a driver should always be written in a modular scope. This means that the driver is basically not having any dependencies to the test application or framework where it is finally implemented.
In addition you should think about the future scope of your drivers. Do you only want to create an RS232 / VISA driver, or do you also plan to write a TCP/IP or Modbus(TCP) driver in future aswell. If so an object oriented driver might allow you to reuse a lot of code. But in that case programming complexity will rise a lot.
There are many possibilities to start a driver. The colleagues before me already pointed out, that there is a VISA driver that you can use to easily connect via RS232. If you want to create a driver that your customer can implement quite easily in relation to the device some of the following ideas could help you:
- Use lvlibs: Always store each driver in a different library (*.lvlib). That way you can easily wrap them up and move them. In addition you also take advantage of an own namespace. This means that if you have two drivers in the future that have a VI called init.vi, then these can coexist in one project. LabVIEW simply adds the library name as a prefix to the filename, such as driver.lvlib:init.vi
- provide an API: An API is a good way to present the most important VIs of your driver that should be used by the customer. You can even link those VIs in a polymorphic VI where selection is much easier. This API should then contain e.g. a init.vi that allows basic config (like baud-rate and COM-Port) and also starts configuration
- provide an example: Add a VI to the library that demonstrates an easy application
- store connection ref in global or FGV: If your customer only uses one instance of that device it could make application much easier, if the VISA ref is stored in a global after connecting in init.vi that is then read in each command
- provide ready-to-use commands and queries: wrap up all the commands that youre device is able to handle in separate VIs that already contain all the formatting, conversion and the RS232 command
- basic VI structure: As a start I would recommend you to provide the following VIs:
- init.vi (configuration and connection start)
- deinit.vi (disconnect)
- global.vi (stores connection reference and e.g. connection state)
- common VISA read and write vi (bind them into one VI so that you can do some changes e.g. because of timing issues to all commands at once)
- various commands (they use the common VISA read and write vi that you created before)
- documentation: Make sure to write a documentation for each VI that can be read via context help, to make it easier for your customer to use
- think about packedLibs: it could make sense to build a packedLib from that library. This has many benefits like less building time, simple deployment and that the customer cannot make changes to your code. But it also has the downside that it always has to be built with the right labview version.
Hope that helps!