Need a second data path save for Wonderware

I am attaching code from my Wonderware script where it prints out the report. The current program saves at different intervals during the program depending on conditions. I actually need to add a second data path DataLogPath2 = \\JLMAIN\C1\LIN_DATA\ACCESSEXPORT\; and save a single text file  to this location when it prints the total report. Currently it saves and average of four files and only one contains the complete report. I know where to place the data path and how to add tags, but I can't get it to save only one time to the second path when it prints. The code below is two part. Part one is the path setup and part 2 is where the report is sent to the printer. Currently all files are saved to Data Log Path. I also added the Temp Log File Declaration at the end of part 2.
Part 1##########
GetNodeName( MyNodeName, 131 );
IF MyNodeName == MainComp THEN
IOSetAccessName( "VIEW", "MainComp", " ", " " );
ENDIF;
 
retval = InfoFile("C:\TAKEUP.TXT", 1, 1);
IF (retval == 1)
THEN
   I_Am_Takeup = 1;
   IOSetAccessName("Isodata1", MainComp, "ISODATA", "ISODATA1" );
   IOSetAccessName("MLAN", MainComp, "MLANDDE", "MLAN3");
   AlarmBase = "\\" + MainComp + "\Intouch!";
   RecipeTemplate = "\\JLMAIN\C1\LIN_Data\Recipe\Recipe.csv";
   DataLogPath = "\\JLMAIN\C1\LIN_DATA\LOGS\";
 
ELSE
  I_Am_Takeup = 0;
  AlarmBase = "\Intouch!";
  DataLogPath = "C:\LIN_DATA\LOGS\";
ENDIF;
 
Part 2##########
FileWriteMessage(z_TempLogFile, -1, z_TStr1, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr2, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr3, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr4, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr5, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr6, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr7, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr8, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr8, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr9, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr10, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr11, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr12, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr13, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr14, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr15, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr16, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr17, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr18, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr19, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr20, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr21, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr22, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr23, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr24, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr25, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr26, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr27, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr28, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr29, 1 );
 
SaveQCFile = 0;
IF (PrinterEnable)
THEN FileCopy(z_TempLogFile, "LPT1:", "RetVal");
       IF (LogFormFeedEnable) 
      THEN rp_TempStr1 = StringChar( 12 );
      FileWriteMessage( "LPT1:", -1, rp_TempStr1, 0 );
      ENDIF;
ENDIF;
MakeQCHeader = 1;
 
########Temp Log File Declared
z_TempLogFile = DataLogPath; 
z_TempLogFile = z_TempLogFile + LogName + "-" + Text( LogSeqNum, "#") + ".LOG";

Open in new window

krd0829Asked:
Who is Participating?
 
GPTJCommented:
krd0892,
I've seen what's going on here.  What's happening is that the FileCopy() function can only run one at a time.  Since they are an Asyncronous function, they run in the background while the rest of your script executes.

Here's what I'd like you to try:
Create a new tag "TimeTrap" of type Memory Real.
Extract the entire 'IF (PrinterEnable)' statement and place it in a new Condition Script of its own with the condition being:  (FileCopyDn > 0) AND ($Time > TimeTrap + 3000)

######  New Condition Script (On True) #########
     
    IF (PrinterEnable)
          THEN FileCopy(z_TempLogFile, "LPT1:", "RetVal");
          IF (LogFormFeedEnable)
               THEN rp_TempStr1 = StringChar( 12 );
               FileWriteMessage( "LPT1:", -1, rp_TempStr1, 0 );
          ENDIF;
     ENDIF;
     TimeTrap = 0;

######### End of Script ############


Add the command to "trap" the time of day in Msec to your original script, so now your original script ends with this:
SaveQCFile = 0;
FileCopy(z_TempLogFile, z_TempLogFile2, "FileCopyDn");
MakeQCHeader = 1;
TimeTrap = $Time;

Important: Ensure you are using "FileCopyDn" for this statement, not "RetVal", as we need a seaparate 'Done' bit than what is used in the print statement.
The importance of breaking out the print script is that 'FileCopyDn' will not change to a value greater than zero, which means it has been successful, in the time that your original script runs only once.  This, along with creating a 3 second delay, will insure that once the FileCopy() statement is, in fact, complete, THEN the printing can resume.
Let me know how that works for you.
-Tim
0
 
krd0829Author Commented:
Thanks, I have increased my zones.
0
 
krd0829Author Commented:
I am not sure. Do you know of any zones that may be related to Wonderware scripting?
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
GPTJCommented:
krd0829 -
It's been a while since I've worked on Wonderware scripts, so bear with me.

Just a suggestion, but could you imbed your FileWriteMessage() statements in a For/Next loop that excecutes twice, once with the original DataLogPath, and once with DataLogPath2?
It would save you from having two separate instances of your FileWriteMessage() statements.

TJ
0
 
krd0829Author Commented:
I tried that approach and the problem is that it then prints the report twice, at least parts of it, and still doesn't save as needed. I was thinking of useing file copy when the report prints but am not sure that will work either.
0
 
GPTJCommented:
Can you attach the code for the entire script?

Are there two scripts here, or is Part1 and Part2 all in the same script?  Is this a 'While Running' script?

What version of InTouch are you using?

-Tim
0
 
krd0829Author Commented:
I have all the script in a text file sectioned out by while running conditional, etc. Is there a way to send a text file just to you instead of posting it on the board for everybody to see?
0
 
GPTJCommented:
Sorry krd0829, I guess we can't do that.  (Oops, I should have read ALL the EE guidelines...)

Like Vee_Mod said, perhaps you can parse out any confidential information, and attach it as a text file with your comment.

-Tim
0
 
krd0829Author Commented:
The code for the conditional script below is listed. Anything with a ### is a comment. I wanted to distinguish them easily for you. This is the only place it is calling for the complete file to be sent to the printer. I have already set up the DataLogPath2 in the Application Script on Startup and added the tag. I did not sent each of the string assignement lines however since I didn't want them posted on the forum, but all they contain is string assignments for lines and setup of the report.
Condition Script Save QC File and not i am takeup and log enabled listed below##################################################
{Save QCFile Script, ON TRUE }
 
{Write QC File Footer Script}
IF (PrinterEnable)
THEN 
 
z_TStr = "Order No: " + FString(FON, "%11.11s") + "   QC No: " + FString(QC_NUM, "%11.11s");
 
FileWriteMessage("LPT1:", -1, z_TStr, 1 );
ENDIF;
 
z_TempLogFile = DataLogPath + LogName+ "-" + Text( LogSeqNum, "#") + ".LOG";
z_TempReal1 = CH_SmTr_ActTemp;
z_TempReal2 = CH_LgTr_ActTemp;
 
##############I am not listing all the str data that encompasses the report but I am just giving the string range below#################
z_TStr1 = "" to z_TStr30 = ""
FileWriteMessage(z_TempLogFile, -1, z_TStr1, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr2, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr3, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr4, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr5, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr6, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr7, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr8, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr8, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr9, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr10, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr11, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr12, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr13, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr14, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr15, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr16, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr17, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr18, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr19, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr20, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr21, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr22, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr23, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr24, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr25, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr26, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr27, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr28, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr29, 1 );
 
SaveQCFile = 0;
IF (PrinterEnable)
THEN FileCopy(z_TempLogFile, "LPT1:", "RetVal");
       IF (LogFormFeedEnable) 
      THEN rp_TempStr1 = StringChar( 12 );
      FileWriteMessage( "LPT1:", -1, rp_TempStr1, 0 );
      ENDIF;
ENDIF;
MakeQCHeader = 1;

Open in new window

0
 
GPTJCommented:
krd0829,
I can see two ways of doing what you're wanting to do.

One is to list all your FileWriteMessage() functions twice. First with one file path, then with a second.

The other way is to do it within a loop that executes twice, first with path #1, then with path #2.

I've listed both options in the attached code.  Note: I've added the 'RunOnce' tag simply to allow the script to send z_TempLogFile to the printer once.

Let me know if that works for you.

**********************************************************
***** Method #1 ******
z_TempLogFile = DataLogPath + LogName+ "-" + Text( LogSeqNum, "#") + ".LOG";
 
z_TStr1 = "" to z_TStr30 = ""
FileWriteMessage(z_TempLogFile, -1, z_TStr1, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr2, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr3, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr4, 1 );
....
 
z_TempLogFile = DataLogPath2 + LogName+ "-" + Text( LogSeqNum, "#") + ".LOG";
 
z_TStr1 = "" to z_TStr30 = ""
FileWriteMessage(z_TempLogFile, -1, z_TStr1, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr2, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr3, 1 );
FileWriteMessage(z_TempLogFile, -1, z_TStr4, 1 );
....
 
**********************************************************
Or you could try this:
**********************************************************
***** Method #2 ******
z_TempLogFile = DataLogPath + LogName+ "-" + Text( LogSeqNum, "#") + ".LOG";
 
FOR Count = 1 TO 2
 
	RunOnce = 1;
 
	z_TStr1 = "" to z_TStr30 = ""
	FileWriteMessage(z_TempLogFile, -1, z_TStr1, 1 );
	FileWriteMessage(z_TempLogFile, -1, z_TStr2, 1 );
	FileWriteMessage(z_TempLogFile, -1, z_TStr3, 1 );
	FileWriteMessage(z_TempLogFile, -1, z_TStr4, 1 );
	....
 
	z_TempLogFile = DataLogPath2 + LogName+ "-" + Text( LogSeqNum, "#") + ".LOG";
 
	IF (RunOnce)
	THEN SaveQCFile = 0;
		IF (PrinterEnable)
		THEN FileCopy(z_TempLogFile, "LPT1:", "RetVal");
		       IF (LogFormFeedEnable) 
		      THEN rp_TempStr1 = StringChar( 12 );
		      FileWriteMessage( "LPT1:", -1, rp_TempStr1, 0 );
		      ENDIF;
		ENDIF;
		MakeQCHeader = 1;
 
		RunOnce = 0;
	ENDIF;
 
NEXT;
**********************************************************

Open in new window

0
 
krd0829Author Commented:
The code I submitted is the bottom body of the report. There is also code that creates the header portion in a different location. The reason this was coded this way was because in the middle of the report an unknown amount of readings occur and we had to account for different space requirements at different times so I would not be able to use the code above. It would only copy the body and footer of the report. The only time the complete file is saved is within the following code from above when it prints the file:
SaveQCFile = 0;
IF (PrinterEnable)
THEN FileCopy(z_TempLogFile, "LPT1:", "RetVal");
       IF (LogFormFeedEnable)
      THEN rp_TempStr1 = StringChar( 12 );
      FileWriteMessage( "LPT1:", -1, rp_TempStr1, 0 );
      ENDIF;
ENDIF;
MakeQCHeader = 1;


As far as I can see since the header is created in a data change conditional script called Make QC Header as shown below
############Condition Script Make QC Header#########################################
{WriteQCHeader Script ON TRUE}

LogFtg = LogInterval;

IF ResetLogSeqNum == 1
   THEN
         LogSeqNum = 0;
         ResetLogSeqNum = 0;
ENDIF;

LogSeqNum = LogSeqNum + 1;

IF LogSeqNum > 2500
      THEN LogSeqNum = 1;
ENDIF;

z_TempLogFile = DataLogPath;
z_TempLogFile = z_TempLogFile + LogName + "-" + Text( LogSeqNum, "#") + ".LOG";
FileDeleteSt = FileDelete( z_TempLogFile );
LogH1_Reset2Total = rr_H1Tot;
LogH2_Reset2Total = rr_H2Tot;
LogH3_Reset2Total = rr_H3Tot;
LogH4_Reset2Total = rr_H4Tot;

LogCtr = 1;

z_TStr1 = ""  to z_TStr7 = " "

FileWriteMessage( z_TempLogFile, -1, z_TStr1, 1 );
FileWriteMessage( z_TempLogFile, -1, z_TStr2, 1 );
FileWriteMessage( z_TempLogFile, -1, z_TStr3, 1 );
FileWriteMessage( z_TempLogFile, -1, z_TStr4, 1 );
FileWriteMessage( z_TempLogFile, -1, z_TStr5, 1 );
FileWriteMessage( z_TempLogFile, -1, z_TStr6, 1 );
FileWriteMessage( z_TempLogFile, -1, z_TStr7, 1 );

MakeQCHeader = 0;

and the Data Condition Save File contains the body and footer creation, and print loop, would I need to copy and write in the print loop where the total file is saved?
0
 
GPTJCommented:
Okay, so in summary:
- File paths are defined in the application script on startup.
- There is an unknown number of log files and lines during the period until:
        - SaveQCFile == 1, where the complete log is saved and printed (if printer enabled) AND
        - A new header is generated for the next file
If I'm correct so far, try the following code:
- We need to have the complete file name and path: thus the creation of z_TempLogFile2
- Using an additional FileCopy() statement, we should be able to copy the complete file once

Let me know how it goes.
-Tim
z_TempLogFile2 = DataLogPath2 + LogName + "-" + Text( LogSeqNum, "#") + ".LOG";
##(or whatever you want for the second file name/path)##
 
SaveQCFile = 0;
FileCopy(z_TempLogFile, z_TempLogFile2, "FileCopyDn");
IF (PrinterEnable)
THEN FileCopy(z_TempLogFile, "LPT1:", "RetVal");
       IF (LogFormFeedEnable) 
      THEN rp_TempStr1 = StringChar( 12 );
      FileWriteMessage( "LPT1:", -1, rp_TempStr1, 0 );
      ENDIF;
ENDIF;
MakeQCHeader = 1;

Open in new window

0
 
krd0829Author Commented:
Looks good. I will try it this afternoon and let you know. Hopefully it will work and I will be able to accept as solution. What a mess. Thanks so much for your help so far though.
0
 
krd0829Author Commented:
Code has no effect on program. The DataLogPath2 location did not recieve a copy of the file.
0
 
GPTJCommented:
krd0829, what version of InTouch are you using?

I don't have Wonderware loaded on this machine yet.  I'll try to install it today so I can do some testing.

-Tim
0
 
GPTJCommented:
krd0829, this should work, however there are a couple things worth noting.

1 - Make sure you use 'z_TempLogFile2' for the destination in the following statement:
           FileCopy(z_TempLogFile, z_TempLogFile2, "FileCopyDn");
     and make sure there are no double quotes around it.
2 - Also, make sure you have the double quotes around the tag 'FileCopyDn' OR use 'FileCopyDn.Name'
      without any quotes.
3 - Finally, make sure 'FileCopyDn' is of a Memory Integer data type

Let me know how you make out.  If there's one thing about Wonderware, it's that every space or double quote or data type has to just right.
Good luck!
0
 
krd0829Author Commented:
I am using Wonderware 7.1
The code works to move to a single file, but it also prevents the report from printing. If I move the code below the print IF statement it doesn't save the file, but it prints. Any suggestions?
0
 
GPTJCommented:
Sorry for the delay.
Try moving the second FileCopy() statement (print script) into it's own script that is triggered when the 'Done' tag, 'FileCopyDn' > 0.
0
 
krd0829Author Commented:
I am using RetVal for the print script.
IF (PrinterEnable)
THEN FileCopy(z_TempLogFile, "LPT1:", "RetVal");
       IF (LogFormFeedEnable)
      THEN rp_TempStr1 = StringChar( 12 );
      FileWriteMessage( "LPT1:", -1, rp_TempStr1, 0 );
      ENDIF;
ENDIF;
Just trying to clarify: Are you saying to replace RetVal with FileCopyDn and add another If Then statement like this?
IF ('FileCopyDn' > 0)
THEN IF (PrinterEnable)
THEN FileCopy(z_TempLogFile, "LPT1:", "RetVal");
       IF (LogFormFeedEnable)
      THEN rp_TempStr1 = StringChar( 12 );
      FileWriteMessage( "LPT1:", -1, rp_TempStr1, 0 );
      ENDIF;
  ENDIF;
ENDIF;
Check my scripting for ' or space errors please if this is what you had in mind.
0
 
krd0829Author Commented:
Is GPTJ still a member? We were working on this problem, but I haven't heard anything lately. I tried the changes but they did not work. It will either let me print the report or save the file but not both. The outcome of which one works depends on where the FileCopy script is placed.
0
 
GPTJCommented:
krd0892,

So sorry for disappearing for a while.  I've been absent without much for internet access, but am back now.  My plan is to review your last comment today to see if we can get this sorted out for you.

Thanks for your patience,
-Tim
0
 
krd0829Author Commented:
Cool Thanks.. I will try it this week, when I can take the computer off line to make the changes.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.