Ntp 64bits format in datetime

Hi,

How can I convert “with expression” a ntp time format (64 bits format) in human readable format with expression ?
In python, there is no problem with time.ctime(utc_seconds), but can’t find a simple way to make it in expression.

Thanks,

I don’t think you can right now. However, you can run a script in an expression. So if you make a global script function that will return the time you can call it in an expression:runScript("app.time.convert()", 0)The second argument is for polling if you want to turn it on.

Travis,

I think there is something to obvious to be seen…

My global function is defined as follow in app.conv :

[quote]def utc2date(utc_hex):
import time
return (time.ctime(int(utc_hex,16)))[/quote]
and a call in script playgroung or behind a button is working well.
If I put it in an expression tag, I have an evaluation error and can’t see any log for this error.

Any clue :scratch:

Can you paste the exact expression? The problem probably lies with how you pass in variables into your function.

Yes sure.

The SQLtag is a string, as ctime return a string and the expression is

The parameter 'FFD3E345' is a static and arbritary one for my test, but in reality it comes from an opc tag in a string format.

A print runScript("app.conv.utc2date('FFD3E345')",0) in the playground is ok.


Oh I see. I thought the expression was on the window. You can’t call app functions from SQLTags. SQLTags are not part of a project so they don’t know about the script module functions. However, there is a way to run the script directly in the expression without calling a global script function. Here is an example:runScript("0\nimport time\n__RESULT=(time.ctime(int('FFD3E345',16)))", 0)

Ah nice ! just tested and it just works !

Thank you :prayer: