You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

PLC training tools sale

Reply
 
Thread Tools Display Modes
Old May 12th, 2017, 06:22 AM   #1
gardarog
Member
Iceland

gardarog is offline
 
Join Date: Jul 2015
Location: Egilsstadir
Posts: 23
Batch script executed from InTouch doesn't generate output

I've developed a simple batch script to test communications with a couple of ethernet devices one of our clients has out in the field.

The script pings a static IP address and prints the result to a text file.
I've tested the script thoroughly, and it works like a charm.
The script (e.g. ping14.bat) generates a text file (ping14result.txt) in it's containing directory, with a value to indicate if the ping was successful or not.

I've made a network diagram in the client's Wonderware InTouch 10.6 SCADA application, which displays the various field devices, and has a button to check comms for each one.

The button runs an action script, calling the batch script:

StartApp "c:\bat\ping14.bat";

The button has a green indicator if the device responded to the ping, and a red blinking indicator if the device was unresponsive.
I'm using a continuous FileReadMessage() built-in function in the window script to read the value contained in the text file generated by the .bat script to a Memory Message tag.

FileReadMessage ("c:\bat\ping14result.txt",0,ping14result, 0);

The indicator works fine, and returns the correct value from the text file to the message tag.

HOWEVER:

When the InTouch button is used to trigger the script, the script doesn't generate output.

Let's say I delete the text file, ping14result.txt.

I then go to the running InTouch application and use the button to run the .bat script.
I get a flashing CMD prompt on my screen, so everything looks OK.
I then go to the directory to check the .txt file, and there's nothing there.
I've also tried adding "pauses" in the batch script before and after the result is printed to the text file, to make sure the problem is not due to the script not completing it's execution.

pause
@echo %result%> ping14result.txt
pause


And the result was the same.

Now, if I double click the .bat file from windows explorer, everything works fine.
The .txt file is generated if needed, and it's values overwritten if it's already in place.

I've also tried running the .bat script by calling it from the command prompt and it runs fine.

Now I'm wondering what could be causing this?
I've tried removing the FileReadMessage() code from the window script, to make sure that WindowViewer isn't reserving the .txt files and preventing them from being overwritten, with no luck...
Has anyone seen this kind of behaviour before?

Last edited by gardarog; May 12th, 2017 at 06:47 AM.
  Reply With Quote
Old May 12th, 2017, 01:41 PM   #2
xzen
Lifetime Supporting Member
Norway

xzen is offline
 
xzen's Avatar
 
Join Date: Jun 2006
Location: Oslo
Posts: 82
You may try the WWDosCommand function instead of StartApp. The script function WWDosCommand, can be found in Wonderware Tech Support Script Function Library online or on the Knowledgebase CD.
Else I would rather use some network monitoring software. By experience constantly writing, reading and deleting files within InTouch scripts sooner or later cause problems.
__________________
http://www.slauto.no
  Reply With Quote
Old May 12th, 2017, 02:38 PM   #3
gardarog
Member
Iceland

gardarog is offline
 
Join Date: Jul 2015
Location: Egilsstadir
Posts: 23
Thanks xzen, I gave that ago earlier today, using the WWDosCommand to run the .bat script.
I even tried using the WWDosCommand instead of the .bat script to perform the ping and output to a text file, with little luck.
There's something fishy going I here...
Do you have experience working with outputs in this manner, and have you had better results?
  Reply With Quote
Old May 12th, 2017, 09:14 PM   #4
JaxGTO
Member
United States

JaxGTO is offline
 
Join Date: Apr 2009
Location: Kalieefornia
Posts: 639
I use the WWDosCommand to get the PC's IP address using a batch file. Basically:
ipconfig /all > ip.txt
But then I have found that that file wont show up instantly and I had to use some condition scripting to poll for that file, then get the IP address out of it.
  Reply With Quote
Old May 12th, 2017, 09:51 PM   #5
Pete.S.
Member
United States

Pete.S. is offline
 
Join Date: Mar 2016
Location: Fl
Posts: 464
A couple of things to check for.

A .bat (batch) file isn't executionable by itself. It needs the command interpreter to interpret and execute the batch file. That happens by itself when you execute it from a dos prompt (because a dos prompt IS cmd.exe, the actual command interpreter in Windows).

It might not happen from within InTouch. It depends on what the developers did. So to explicitly execute a batch file you can use cmd.exe /c batfile.bat. You can also explicitly specify the path to cmd.exe.


Second thing to check is that the Intouch application is running under a specific user account. For your bat file to be able to actually write to the disc the Intouch user must have the rights to write to that directory.

Third thing to check is to check that you are using absolute paths to the files. If you create a file make sure it's specified otherwise the file will end up in different directories depending on the working directory. That would be different when run from the command prompt or from within Intouch.

Last edited by Pete.S.; May 12th, 2017 at 09:55 PM.
  Reply With Quote
Old May 13th, 2017, 07:09 AM   #6
gardarog
Member
Iceland

gardarog is offline
 
Join Date: Jul 2015
Location: Egilsstadir
Posts: 23
Quote:
Originally Posted by Pete.S. View Post
A couple of things to check for.
Third thing to check is to check that you are using absolute paths to the files. If you create a file make sure it's specified otherwise the file will end up in different directories depending on the working directory. That would be different when run from the command prompt or from within Intouch.
Oh my god... Absolute paths...
I changed my .bat script so that it would output the ping result like so:

@echo %result%> c:\bat\ping14result.txt

instead of:

@echo %result%> ping14result.txt

And that did the trick.
Thank you all for your input, and you Pete for easing my headache!
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
RSview SE and Visual Basic SCAN.PLC LIVE PLC Questions And Answers 9 May 29th, 2015 03:20 PM
Generate Emails / Run Batch Files Based on WW Tag Values five LIVE PLC Questions And Answers 2 March 24th, 2014 08:37 AM
UNIDRIVE 1405 Analog output help_AB pf 70 MJC LIVE PLC Questions And Answers 45 July 11th, 2012 07:37 PM
Can any one write script / batch commands ?? Sparki LIVE PLC Questions And Answers 2 October 31st, 2008 04:48 PM
InTouch Application Script Query jaichains LIVE PLC Questions And Answers 7 July 19th, 2006 08:37 AM


All times are GMT -5. The time now is 04:22 PM.


.