Wonderware System Platform .Net System.Datetime

tranh2

Member
Join Date
Jul 2009
Location
Ontario
Posts
40
Hello Everyone,

I'm new to programming .net in Wonderware System Platform and I'm having difficulty getting a .NET function to work. I'm trying to inialize a .NET structure to get the current date and time of the system that the Automated Object is running on. I can't seem to get it to verify and it keep giving me a error

"Date._ErrorReport:Script Date (Execute). Unknown Property:Today..."

What I'm trying to do is keep a common system date. These values will be written to a PLC clock so that the PLC clock is always sync'd to a common clock.

The code I wrote is below:

'//Start Code

DIM DOB as System.DateTime;
DOB = new System.DateTime;

Me.DateTime = System.DateTime.Today; 'Copy the date time to Me.Datetime

Me.DateTimeHour = System.DateTime.Hour;
Me.DateTimeMin = System.DateTime.Minute;
Me.DateTimeSec = System.DateTime.Second;

'//End Code

It looks like it doesn't like the System.DateTime.Today part of it but from the MSDN site it says the .Today is a property. Don't know what i'm doing wrong.

I'd like to try to keep this to .NET coding. I know within InTouch there is the $Month, $Day, $Year etc. but i'd like to not use those items and try to stick to .NET so I'm not passing values through InTouch and System Platform so much.

Any help would be appreciated...Thanks!
 
Here is how we do it.

Code:
'This script writes the System date and time into a Master Date and Time variable for PLC use.  
'The Master Date and Time is used to synchronise the PLC CPU date and time to the System time.
'Note that synchronisation must also be enabled in the PLC CPU function block in the PLC code.

dim MstrDT as time;
dim strHexVal as string;

'Clear date and time value from the previous scan.
Me.MstrDTWd1 = 0;
Me.MstrDTWd2 = 0;
Me.MstrDTWd3 = 0;
Me.MstrDTWd4 = 0;

If MyPlatform.ScanState == True Then	
	'Set the Master Date and Time to the platform date and time.
	MstrDT = MyPlatform.Scheduler.ScanTime;
	
	If 	IsGood(MyPlatform.Scheduler.ScanTime) THEN
		'Combine date and time values into the structure required for PLC use.
		'Hex format is used in the PLC to represent the datetime, spread across 4 (16 bit) words as follows:
		'Word	|Bits 15-8| Bits 7-0
		'1st 	|    sec  | not used
		'2nd 	|    hours| min
		'3rd 	|    month| day
		'4th	|    year	

		'Word 1
		'Shift seconds to the high byte.
		strHexVal = StringFromIntg(MstrDT.Second * 100, 10);
		'Convert the hex value to decimal.
		Me.MstrDTWd1 = System.Convert.ToInt32(strHexVal, 16);

		'Word 2
		'Shift hours to the high byte, mins to low byte
		strHexVal = StringFromIntg((MstrDT.Hour * 100) + MstrDT.Minute, 10);
		'Convert the hex value to decimal.
		Me.MstrDTWd2 = System.Convert.ToInt32(strHexVal, 16);

		'Word 3
		'Shift Months to the high byte, days to low byte
		strHexVal = StringFromIntg((MstrDT.Month * 100) + MstrDT.Day, 10);
		'Convert the hex value to decimal.
		Me.MstrDTWd3 = System.Convert.ToInt32(strHexVal, 16);

		'Word 4
		strHexVal = StringFromIntg(MstrDT.Year, 10);
		'Convert the hex value to decimal.
		Me.MstrDTWd4 = System.Convert.ToInt32(strHexVal, 16);
	endif;
endif;

As you can see we use the MyPlatform.Scheduler.ScanTime as the reference for the stripping out of Data.

The Data is extracted in this way shifted to the correct position and then used and then converted to decimal to be used in PLCs.

We do a compare daily of the PLC Time and the time generated from this script. If they do not match we sync the PLC.
 
Last edited:
Thank you RheinhardtP!

I see what you did. This would work just as well for me.

I guess for clarification would anyone know why I get the "Unknown Property..." error with the .NET code written above?

ie.

'//Start Code

DIM DOB as System.DateTime;
DOB = new System.DateTime;

Me.DateTime = System.DateTime.Today; <-- Why doesn't this work??????
 
Actually been having a look. This code was done a while back i think this is a better way.

I defined a UDA called DateTime type Time, to be able to use the me.DateTime in the script

i used the following and it worked in Time format UDA. You could also add UDA extensions and change HourT to me.HourT.

Code:
Dim HourT as INT;
Dim MinT as INT


Me.DateTime = System.DateTime.Now; '
HourT = System.DateTime.Now.Hour ;
MinT = System.DateTime.Now.Minute ; 'This works

Did not look into the datetime.today but you wont need it if you use the above.

A lot shorter than our other code.
 
Thanks RheinhardtP.

I ended writing it like this.

DIM SystemDate AS System.DateTime;

SystemDate = Platform.Scheduler.ScanTime;

Me.Year = SystemDate.Year;
Me.Month = SystemDate.Month;
Me.Day = SystemDate.Day;
Me.Hour = SystemDate.Hour;
Me.Min = SystemDate.Minute;
Me.Sec = SystemDate.Second;

Would you know what type of .NET programming convention system platform uses? Seems like its VB.NET but also doesn't look like it.

Thanks.
 
As far as i know they run scripts in objects in .NET Framework 4.0. Well this is when you have 2012 R2 installed.
 
Hello Everyone,

I'm new to programming .net in Wonderware System Platform and I'm having difficulty getting a .NET function to work. I'm trying to inialize a .NET structure to get the current date and time of the system that the Automated Object is running on. I can't seem to get it to verify and it keep giving me a error

"Date._ErrorReport:Script Date (Execute). Unknown Property:Today..."

What I'm trying to do is keep a common system date. These values will be written to a PLC clock so that the PLC clock is always sync'd to a common clock.

The code I wrote is below:

'//Start Code

DIM DOB as System.DateTime;
DOB = new System.DateTime;

Me.DateTime = System.DateTime.Today; 'Copy the date time to Me.Datetime

Me.DateTimeHour = System.DateTime.Hour;
Me.DateTimeMin = System.DateTime.Minute;
Me.DateTimeSec = System.DateTime.Second;

'//End Code

It looks like it doesn't like the System.DateTime.Today part of it but from the MSDN site it says the .Today is a property. Don't know what i'm doing wrong.

I'd like to try to keep this to .NET coding. I know within InTouch there is the $Month, $Day, $Year etc. but i'd like to not use those items and try to stick to .NET so I'm not passing values through InTouch and System Platform so much.

Any help would be appreciated...Thanks!
As far as i know they run scripts in objects in .NET Framework 4.0. Well this is when you have 2012 R2 installed.
I have used the following with success:

dim system_month as integer;
dim system_day as integer;
dim system_year as integer;
dim system_hour as integer;
dim system_minute as integer;
dim system_second as integer;

System_hour = System.DateTime.Now.Hour;
System_minute = System.DateTime.Now.Minute;
System_second = System.DateTime.Now.Second;

System_year = System.DateTime.Now.Year;
System_Month = System.DateTime.Now.Month;
System_Day = System.DateTime.Now.Day;
 

Similar Topics

Seems odd that you can make a symbol and place many of them but if the text on a button and or elsewhere in the symbol comes from a Custom...
Replies
0
Views
1,663
I was given some example code but I can not get the function to show up in the System Platform script. The dll import is successful but I'm...
Replies
1
Views
2,060
Hello Everyone! Need help with this... I have a controllogix plc 5571 which has just a USB port on it. I wish to read the data from this plc...
Replies
2
Views
2,404
Need your Advice. Scenario: I have got two SCADA computers at different locations which are having independent working plants at each site (But...
Replies
7
Views
2,969
Hi all, This is my first System Platform 2017 install. Have done plenty of mods to existing 2014 R2 installs and know what I'm doing in terms of...
Replies
3
Views
5,118
Back
Top Bottom