Sign in to follow this  
Zerout23

Date time component

Recommended Posts

Hello so i am completely new to Daqfactory and even newer to programming so forgive me if i don't use the right terminology. I have a serial device that uses the modbus protocol. I want to create an interface where a user enters a start date and time to schedule a routine using the date time component. In order to do this on my device i need to set multiple registers (i.e. start date, start time, end date, end time) so how can i go about setting multiple registers using the date time component? Appreciate the help and feedback. Thank you. 

Share this post


Link to post
Share on other sites

Well, the trick is first determining what format your device expects the date and time.  You definitely can't just tell it January 15th 2020.  It won't understand that, and Modbus doesn't support sending that sort of information anyway.  Usually date and time is stored internally in computers as some sort of number referenced to an epoch.  For example, DAQFactory stores date/time information as seconds since Jan 1, 1970 (standard Unix time format), while Excel uses decimal days since 1900.  These are very different, as today we are at about 1.57 billion seconds since 1970,  but only about 44,000 days since 1900.  Anyhow, you'll need to find what your device expects then I can describe how to get there.

Share this post


Link to post
Share on other sites

Yes each would be different registers(unsigned 32 bit).  So for start it would be the first 6 registers and the end would be another 6 registers. 

Share this post


Link to post
Share on other sites

I also forgot to mention that another register is used to enable the schedule so i would like to set a toggle switch of some sort to:

1. toggle enable or disable (00 or 01)

2. When enabled it will send the schedule command to set all registers like 01 2019 11 06 22 30 00 2019 11 08 09 00 00 (i.e. schedule set from Nov 6, 19 10:30pm to Nov 8, 19 9am)

Share this post


Link to post
Share on other sites

OK, are you sure it is 32 bit?  Doesn't matter, but seems excessive since each value is well below the 16 bit limit.  Anyhow, you'll have to create a global variable that contains the start time and one for the end time.  Then have the user interface elements edit those variables.  You'll need a button to trigger some script that updates the schedule times in the PLC.  That script could be done in a number of ways, but probably the easiest is to use formatDateTime() [see section 4.12.11 of user's guide] to get the date/time number into a comma delimited string:

private string x = formatDateTime("%Y,%m,%d,%H,%M,%S", starttimevariable)

then use parse() on that string to get each value:

private out = parse(x, -1, ",")

which will return an array of those 6 values which you can then send to your Modbus device.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this