Rockwell Automation RSBizWare Administration Guide User Manual
Page 280

Appendix D Application notes for FactoryTalk Transaction Manager
DECLARE @system_time as datetime,
@difference as int,
@tbin0 AS VARBINARY(4),
@tbin1 AS VARBINARY(4),
@tbin2 AS VARBINARY(4),
@tbin3 AS VARBINARY(4),
@tbin4 AS VARBINARY(4),
@tbin5 AS VARBINARY(4)
/* check current time */
SELECT @system_time = GETDATE();
/* Uncomment this section and create the ControllerTimeDiff table
if you
wish to log the difference */
/*
SELECT @difference =
DATEDIFF(second,@control_time_in,@system_time);
INSERT INTO [dbo].[ControllerTimeDiff]
( [ControllerID],[ControllerTime],[SystemTime],[Difference])
VALUES ( @control_id, @control_time_in, @system_time,
@difference);
*/
/* output the current system time to the controller */
SELECT @tbin0 = DATEPART(year,@system_time);
SELECT @tbin1 = DATEPART(month,@system_time);
SELECT @tbin2 = DATEPART(day,@system_time);
SELECT @tbin3 = DATEPART(hour,@system_time);
SELECT @tbin4 = DATEPART(minute,@system_time);
SELECT @tbin5 = DATEPART(second,@system_time);
/* this select statement handles the byte swapping necessary to
output a block of
32 bit integers to the controller. As you can see you must swap
the high and
low bytes in each word, and the high and low word in each 32
bit integer. */
SELECT @control_time_out =
(SUBSTRING(@tbin0,4,1)+SUBSTRING(@tbin0,3,1)+SUBSTRING(@tbin0,
2,1)+SUBSTRING(@tbin0,1,1))+
(SUBSTRING(@tbin1,4,1)+SUBSTRING(@tbin1,3,1)+SUBSTRING(@tbin1,
2,1)+SUBSTRING(@tbin1,1,1))+
(SUBSTRING(@tbin2,4,1)+SUBSTRING(@tbin2,3,1)+SUBSTRING(@tbin2,
2,1)+SUBSTRING(@tbin2,1,1))+
(SUBSTRING(@tbin3,4,1)+SUBSTRING(@tbin3,3,1)+SUBSTRING(@tbin3,
2,1)+SUBSTRING(@tbin3,1,1))+
(SUBSTRING(@tbin4,4,1)+SUBSTRING(@tbin4,3,1)+SUBSTRING(@tbin4,
2,1)+SUBSTRING(@tbin4,1,1))+
(SUBSTRING(@tbin5,4,1)+SUBSTRING(@tbin5,3,1)+SUBSTRING(@tbin5,
2,1)+SUBSTRING(@tbin5,1,1));
280
Rockwell Automation Publication BZWARE-IN001M-EN-P-June 2014