Zerout23 Posted November 6, 2019 Share Posted November 6, 2019 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. Quote Link to comment Share on other sites More sharing options...
AzeoTech Posted November 6, 2019 Share Posted November 6, 2019 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. Quote Link to comment Share on other sites More sharing options...
Zerout23 Posted November 7, 2019 Author Share Posted November 7, 2019 The expected format is year, month, day, hour(24), min, sec. Example: 2019 11 06 22 30 00 Quote Link to comment Share on other sites More sharing options...
AzeoTech Posted November 7, 2019 Share Posted November 7, 2019 In 6 different registers? Quote Link to comment Share on other sites More sharing options...
Zerout23 Posted November 7, 2019 Author Share Posted November 7, 2019 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. Quote Link to comment Share on other sites More sharing options...
Zerout23 Posted November 8, 2019 Author Share Posted November 8, 2019 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) Quote Link to comment Share on other sites More sharing options...
AzeoTech Posted November 12, 2019 Share Posted November 12, 2019 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. Quote Link to comment Share on other sites More sharing options...
Zerout23 Posted November 12, 2019 Author Share Posted November 12, 2019 Forgive me, I'm still a bit lost. How would i use this with the date time component? The one that appears as a calendar with the time? One component for start date/time and another for end date/time Quote Link to comment Share on other sites More sharing options...
AzeoTech Posted November 12, 2019 Share Posted November 12, 2019 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.