Recommended Posts

Sorry I could not find an answer in the forum for this but it probably is there.

I am creating a user device which reads a 'sample' string from a device. This device reads its sensors asynchronously say once per minute. It outputs its data as a string (when prompted) as "tttttttt,vvvv,vvvv,vvvv,vvvv...etc" where tttttttt is a time in seconds since 1970 and the vvvv's are up to 10 sensor values at that specific time. I realise my user device code can AddValue() the vvvv's to the channel, but that bypasses Conversion, which I want to keep to adjust calibration over time. So my User Device will return the vvvv for the particular channel #1,#2 etc - however I want the Channel time associated with all those Channels to be tttttttt and not the time the Channel was read by calling my user device. I know I can do this with AddValue() but that bypasses Conversion which I want to keep. Is there a way? Thanks. :unsure:

Link to comment
Share on other sites

It bypasses conversion because you can do the conversion before you do AddValue. So if your conversion is normally Value * 5, just put the * 5 in the AddValue:


private thetime = strToDouble(parse(datain, 0, ","))

private data = strToDouble(parse(datain, 1, ","))

data.time = theTime

myChannel.AddValue(data * 5)


Just do the math for your conversion in your code. If you want to apply the same formula to all the values, either create a sequence function to do it:

function myConversion(val)

return (val * 5)



or, have your script cycle through all the vvvv's in a loop.

Link to comment
Share on other sites

Yep, I realise that I can add time in the AddValue(). I guess what I was trying to say was that the Conversion column sitting in the Channels list is neat. I said I wanted to maintain the Conversion so that as sensors drifted, a user could just go to that snippet of code and change a gain value from 5.001 to 5.002. If I use the Conversion that way I don't have to have a future user prowling through my device code and I don't have to explain to him where to find the conversion factor, it is where it is supposed to be in the Conversion column of the Channels display.

Is there any way I can call the Conversion like MyChannel.Conversion so that the user can alter it and my device driver can pick up those alterations and apply the changed conversion before doing AddValue. I presume I can't return the time along with the value and have the time override the system time when my device driver is read?

I don't think I am being pedantic, I am trying to avoid someone in the future having to delve into the device code with its extra complications and the possibility of screwing it up too.

Link to comment
Share on other sites

If you are just adjusting a constant, why don't you just create a variable for that constant, maybe persist it to the registry, and then give the end user a screen element for changing the value. Then they can make the change without even having to go into Conversions. Also, then you would be able to run your app in Runtime mode.

Link to comment
Share on other sites

Sorry my friend, you are not getting it, I am not just adding a constant, I was using 5.002 as an example. The conversion from raw units to real could be a polynomial of degree 6. Hence is the user can type in Value^3*5.002+Value^2*2.4456+5.9987 and I can use that then OK, but in the general case it is not just a constant. Yes I could set up six variables per input, but that is not the point, DAQF has a defined location for Conversions, it seems silly to tell my customer they can't use it. It is the obvious place to put it.

I realise that I have access to the Conversion string (is it strConversion) and I can probably parse that and use the information from it, but is there a simpler way?

I guess the answer is no.

Would it be a good suggestion to enhance AddValue with a flag in the call which forced it to use Conversion? Or add another function AddValueWithConversion()? Just a thought

Link to comment
Share on other sites

I suppose. You can add it to the request list. In general, Conversions are designed for beginners, not for advanced applications, and typically applications that are distributed from developers like yourself to end users are setup so everything can be done from the custom UI, not from DAQFactory so the end user doesn't have to learn any DAQFactory.

My recommendation is again, to provide a screen element to change the formula. So, the screen element might change a global string variable called "formula". Your customer would use the variable "x" instead of "Value" that they'd use in a conversion, so they might put:


Then in your code, you might have (continuing off my previous example):

private x = data

x = evaluate(formula)

x.time = thetime


The nice part about using this method is that you can actually catch errors. Using your method with conversions, if your customer enters an invalid formula, for example by mispelling "Value", or having a stray operator or unmatched parenthesis, the Conversion won't execute at all and the original value is put in the channel. You have no way of knowing this other than looking at the data. Using my method, if the formula can't evaluate, you'll get an error which you can trap with try/catch and then tell the customer that they have a problem with the formula.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.