09-13-2015 12:14 PM
I'm writing a driver for a serial device, and one of the functions is parsing the response of the device to a command. The device can respond with a sample result (cluster type 1), a status string (cluster type 2), or version information (cluster types 3-6). I've got a typedefed enum as my control going into this VI, so there's a case statement that will parse the appropriate information and send it out in a cluster for use. The problem is that I've got 6 different clusters that may come out depending on what command is being parsed. Is it possible to have one indicator that takes on multiple different data types? If not, is there some other way to handle this elegantly?
Code is in the attached zip file, as well as documentation on the serial protocol in question. Section 9 describes the protocol.
Solved! Go to Solution.
09-13-2015 12:58 PM
Hi math,
Is it possible to have one indicator that takes on multiple different data types?
That one is called "variant"…
It will take any datatype you like to stuff into, but that doesn't help you immediatly. You still need to know the datatype you stuffed into the variant.
So one often used approach is to create a cluster of an enum and a variant. The enum describes the datatype stored in the variant. When reading the cluster you first read the enum and use it to select one case in a case structure. That case correctly reads the data from the variant…
Another approach is to create a cluster with an enum (same meaning as before) and several "standard" datatype indicators. You store your information in those indicators. From your description it seems you need to store numbers ("sample result") and several strings ("status", "version information")…
09-13-2015 01:02 PM
Weirdly enough, I did think to do just that! I always heard that variants are much slower than using normal data types, and that needing to use one was indicative of bigger problems in your code. Would you agree with that? Would it instead be better practice to have each cluster-specific group of commands have their own VI?
09-13-2015 01:13 PM
09-13-2015 01:14 PM
Mike, do you have any references for this kind of OOP in LV?
09-13-2015 01:36 PM
09-13-2015 08:03 PM