Date time component


Zerout23

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. 

Link to comment
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.

Link to comment
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)

Link to comment
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.

Link to comment
Share on other sites

That's what the global variables are for.  Create a sequence marked Auto - Start that declares and initializes those variables:

global startTime = systime()

global endTime = systime()

Then have the date/time controls edit those two variables.  Finally, add a button that parses the values and sends to the device as I described.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.