Convert float to bool SQL historian

Ignition 8.0
SQL server express


Due to hardware restrictions, I’m forced to read data from 2 digital proximity switches as analog values (0…1000mV). <~50mV is 0, >~900mV is 1.
I would like to log this data to our SQL database using historian. However I’m wondering what the most elegant solution is to achieve this. Ideally, I would like to avoid having a second set of tags (if possible).

Accquire data, threshold logic, log to MSSQL.

I’m currently logging the data as the analog value but this seems wasteful. I’d like to log this as a boolean on change of value.

Suggestions? Any help would be great.


By “threshold logic” I presume you mean hysteresis? That requires prior state when evaluating new samples. I’m biased towards the objectScript() expression function from my Simulation Aids module for such cases, using its state variable to hold prior output. Something like this:

objectScript("someModule.thresholdFunction(binding.state, args[0])", {[.]AnalogTag})

with a threshold function like this:

def thresholdFunction(state, milliVolts):
    if 'prior' in state:
        if state['prior']:
            result = milliVolts > 50
            result = milliVolts > 900
        result = milliVolts > 475
    state['prior'] = result
    return result

I may be missing something here, but unless it’s the slowest transistor ever, do you ever see any intermediate values?

why not use an expression tag? I know you said you dont want a 2nd set of tags but I cant imagine any other solution being more simple.

Thanks Guys

I think I’ll use a couple of expression tags.