Home : Products : Hach WIMS : Interfaces : Hach WIMS Direct Server-Side Interface to Wonderware InTouch HMI : Documentation : Topics specific to the operation of this interface : Wonderware HistData Example Script to CSV
Q14570 - INFO: Wonderware HistData Example Script to CSV

For users where DDE is not working Wonderware (or DDE is not preferred), a Wonderware Script can be used to create CSV files that can be imported to WIMS. 

 

The following script is included for information only.  Hach is providing this script only as an example.  Hach cannot not verify, support, or guarantee the results or outcomes from using this code.  Use at your own risk. 

Some functions used in the script require The FactorySuite Technical Support script function library (such as the CreateFilenameFromDate).  The script library contains script functions for Wonderware® InTouch™ 6.0 and later for Windows NT 4.0.  If the script library is not already installed, you may need to download wwtech32.zip from the Wonderware Knowledge Base.  Then, unzip the file and move Wwtech32.dll and Wwtech32.wdf into your InTouch installation directory.


Write CSV for WIMS script

HDWDataDir="c:\logfiles\historical"; {directory where Wonderware logfiles reside}

HDWDBDir="c:\apps\factorysuite\intouch\shawano"; {Wonderware application directory}

HDWStartDate=StringFromTimeLocal((($Date*86400)+($Time/1000) - 86400),1); {Wonderware function to calculate the start date of the csv file from the local computer time}

HDWStartTime=$TimeString; {Start time - current time from Wonderware}

HDWDuration="24h"; {Duration of CSV file}

HDWInterval="10m"; {Time interval between data points}

HDWFilename =CreateFilenameFromDate("mdy","C:\logfiles\historical\ops_data\", ".csv", 0); {Wonderware function to create the csv filename from the current date}

{FLOW DATA TRANSFER TO CSV FILE}

HDWTags="$date,$time,CA_SHAWANO_FLOW_VAL,CA_SHAWANO_FLOW_TOT_VAL,AI_3_FM315_FLOW_TOT_VAL,AI_3_FM315_FLOW_MGD_VAL,CA_3_FM315_FLOW_GPM_VAL,+";

HDWTags1="AI_3_FM316_FLOW_MGD_VAL,CA_3_FM316_FLOW_GPM_VAL,AI_3_FM316_FLOW_TOT_VAL,AI_8_FM821_FLOW_VAL,+";

HDWTags2="AI_8_FM821_FLOW_TOT_VAL,CA_8_FM822_FLOW_MGD_VAL,AI_8_FM822_FLOW_GPM_VAL,AI_8_FM822_FLOW_TOT_VAL,+";

HDWTags3="CA_8_FM823_FLOW_MGD_VAL,AI_8_FM823_FLOW_GPM_VAL,AI_8_FM823_FLOW_TOT_VAL,CA_8_FM824_FLOW_MGD_VAL,AI_8_FM824_FLOW_GPM_VAL,+";

HDWTags4="AI_8_FM824_FLOW_TOT_VAL,CA_8_SUM_RAS_FLOW_MGD_VAL,AI_8_SUM_RAS_FLOW_GPM_VAL,AI_8_SUM_RAS_FLOW_TOT_VAL,+";

HDWTags5="AI_8_FM1105_FLOW_VAL,AI_8_FM1105_FLOW_TOT_VAL,AI_11_FM1105_FLOW_VAL,+";

HDWTags6="AI_11_FM1105_FLOW_TOT_VAL,AI_11_FM1106_FLOW_VAL, AI_11_FM1106_FLOW_TOT_VAL,AI_12_FM1201_FLOW_MGD_VAL,CA_12_FM1201_FLOW_GPM_VAL,+";

HDWTags7="AI_12_FM1201_FLOW_TOT_VAL,AI_12_FM1503_FLOW_MGD_VAL,CA_12_FM1503_FLOW_GPM_VAL,AI_12_FM1503_FLOW_TOT_VAL,+";

HDWTags8="AI_12_FM1214_FLOW_VAL,AI_12_FM1214_FLOW_TOT_VAL,AI_12_FM1504_FLOW_MGD_VAL,CA_12_FM1504_FLOW_GPM_VAL,AI_12_FM1504_FLOW_TOT_VAL,+";

 

{RUNTIME DATA TRANSFER TO CSV FILE}

HDWTags9="AI_3_P301_RUNTIME_VAL,AI_3_P302_RUNTIME_VAL,AI_3_P303_RUNTIME_VAL,AI_3_P304_RUNTIME_VAL,AI_3_MPE307_FOR_RUNTIME_VAL,+";

HDWTags10="AI_3_MPE308_FOR_RUNTIME_VAL,AI_3_MPE309_RUNTIME_VAL,AI_3_MPE310_FOR_RUNTIME_VAL,AI_3_MPE310_REV_RUNTIME_VAL,+";

HDWTags11="AI_3_MPE311_RUNTIME_VAL,AI_3_MPE312_FOR_RUNTIME_VAL,AI_3_MPE312_REV_RUNTIME_VAL,AI_3_MPE317_RUNTIME_VAL,AI_3_MPE319_RUNTIME_VAL,+";

HDWTags12="AI_3_P321_RUNTIME_VAL,AI_3_MPE401_RUNTIME_VAL,AI_3_MPE402_RUNTIME_VAL,AI_3_MPE403_RUNTIME_VAL,AI_3_MPE404_RUNTIME_VAL,+";

HDWTags13="AI_3_P405_RUNTIME_VAL,AI_5_B501_RUNTIME_VAL,AI_5_B502_RUNTIME_VAL,AI_5_B503_RUNTIME_VAL,AI_5_B507_RUNTIME_VAL,+";

HDWTags14="AI_5_B508_RUNTIME_VAL,AI_5_B509_RUNTIME_VAL,AI_5_B510_RUNTIME_VAL,AI_8_MPE701_RUNTIME_VAL,AI_8_MPE702_RUNTIME_VAL,+";

HDWTags15="AI_8_P801_RUNTIME_VAL,AI_8_P802_RUNTIME_VAL,AI_8_P803_RUNTIME_VAL,AI_8_P804_RUNTIME_VAL,AI_8_P807_RUNTIME_VAL,+";

HDWTags16="AI_8_P808_RUNTIME_VAL,AI_8_P809_RUNTIME_VAL,AI_8_P812_RUNTIME_VAL,AI_8_P813_RUNTIME_VAL,AI_8_P814_RUNTIME_VAL,+";

HDWTags17="AI_8_P815_RUNTIME_VAL,AI_8_P816_RUNTIME_VAL,AI_11_P1101_RUNTIME_VAL,AI_11_P1102_RUNTIME_VAL,AI_11_MPE1107_RUNTIME_VAL,+";

HDWTags18="AI_11_MPE1108_RUNTIME_VAL,AI_11_P1109_RUNTIME_VAL,AI_12_BIO_LOADING_P1_RUNTIME_VAL,AI_12_BIO_LOADING_P2_RUNTIME_VAL,+";

HDWTags19="AI_12_P1210_RUNTIME_VAL,AI_12_P1211_RUNTIME_VAL,+";

 

{AERATION TANKS DATA TRANSFER TO CSV FILE}

HDWTags20="AI_5_DO601_DO_VAL,AI_5_DO602_DO_VAL,AI_5_DO603_DO_VAL,AI_5_DO601_TEMP_VAL,AI_5_DO602_TEMP_VAL,AI_5_DO603_TEMP_VAL,+";

HDWTags21="CA_5_DO601_TEMP_CELSIUS_VAL,CA_5_DO602_TEMP_CELSIUS_VAL,CA_5_DO603_TEMP_CELSIUS_VAL";

{WRITE DATA TO FILE}

HDWWriteFile=1;

ENDIF;

Wonderware documentation for File Name Creation Functions

CreateFilenameFromDate

Creates a filename based on the computer date.

 

Function:

Result = CreateFilenameFromDate(Format, Prefix, Postfix, DayOffset);

 

Return value:

The function will return a string that contains the formatted filename based on the date.

 

Format:

(Message) Using a ‘y’ to represent year, ‘m’ to represent month, and ‘d’ to represent the day, you can mix and match these letters to format the date to how you want it.

For example: ‘mdy’ will format the filename to read ‘month’, then ‘day’, then ‘year’; ‘ymd’ will format the filename to read ‘year’, then ‘month’, then ‘day’; ‘md’ will format the filename to read only ‘month’ and ‘day’.

 

Prefix:

(Message) This is a value to add to the beginning of the file name (example, the path. ‘C:\MyPath\Logs\’). If you don’t want to add anything, then leave this field blank by entering a set of double quotes ("").

 

Postfix:

(Message) This is a value to append to the end of the file name (example, the extension ‘.log’). If you don’t want to add anything, then leave this field blank by entering a set of double quotes ("").

 

DayOffset:

(Integer) This is the number of days to add or subtract from the current day. For example, to see today’s date, enter a zero (0). For tomorrow’s date, enter a one (1). If you want the date from a week ago, enter a minus seven (-7).

 

Example 1:

This creates a file name to a specific path with yesterday’s date in the month, day, year format.

FilenameMessageTag = CreateFilenameFromDate("mdy","C:\InTouch\DataLogs\",".Log",-1);

If the date is January 1, 2000, then the file name would be C:\InTouch\DataLogs\12311999.Log.

 

 

Example 2:

This creates a file name without a path with today’s date in the year, month, day format:

FilenameMessageTag = CreateFilenameFromDate("ymd","",".Log", 0);

If the date is December 31, 1999, then the file name would be 19991231.Log.

 

Example 3:

This creates a file name with no prefix, no postfix, in month, day format:

FilenameMessageTag = CreateFilenameFromDate( "md", "", "", 0 );

If the date is December 31, 1999, then the file name would be 1231.

Related Articles
No Related Articles Available.

Article Attachments
No Attachments Available.

Related External Links
No Related Links Available.
Help us improve this article...
What did you think of this article?

poor 
1
2
3
4
5
6
7
8
9
10

 excellent
Tell us why you rated the content this way. (optional)
 
Approved Comments...
No user comments available for this article.
Created on 2/13/2020 1:39 PM.
Last Modified on 2/13/2020 1:39 PM.
Last Modified by Scott Dorner.
Article has been viewed 6158 times.
Rated 10 out of 10 based on 3 votes.
Print Article
Email Article