Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hello all,

I'm designing a new machine that include two robots and two controllers.

Both robots come with Windows installed.
Both controllers come with Windows embedded standard installed.

Each controller takes a small amount of time to start.
Robots can vary the amount of time taken to start depending on the programs loaded and the state of the hard disk.

I will use each controller to make a remote connection to it's related robot.

I need to wait for the robot PC to be running before starting the remote connection (RealVNC probably will be the choosen).

How would you do it?

I can't think on a Wake on lan (to make the inverse process) because those controllers can't do that. so my only possibility is to wait until the robot is up...

I've tried this:
@setlocal enableextensions enabledelayedexpansion
@echo off
set ipaddr=%1
:loop
set state=down
for /f "tokens=5,7" %%a in ('ping -n 1 !ipaddr!') do (
    if "x%%a"=="xReceived" if "x%%b"=="x1," set state=up
)
echo.Link is !state!
ping -n 6 127.0.0.1 >nul: 2>nul:
goto :loop
endlocal


Which always shows down state even if the computer is on...

And this:
@echo off
rem batch file to ping a Server until
rem it is available. Then wait 60 seconds
rem and connect using Terminal Services
rem syntax is: REMOTE <name_of_server> 
rem ping host until it responds
:start
ping -n 1 %1
if %errorlevel% == 0 goto remote_desktop 

rem wait for 10 seconds before trying again
@echo Waiting 10 seconds...
ping -n 10 127.0.0.1 > nul 

rem loopback to start
goto start 

rem initiate remote desktop session
:remote_desktop
@echo *****************************************************************
@echo *Server is now available. Waiting 1 minute for services to start*
@echo *****************************************************************

rem wait 60 seconds after server is available to
rem allow services to start
ping -n 60 127.0.0.1 > nul
mstsc /v:%1


Which never fails even when the computer is off...

Any idea on what is wrong on those scripts or a better approach?

Thank you in advance!
Posted
Comments
Sergey Alexandrovich Kryukov 20-Aug-14 16:25pm    
Aha, batch files... I'm regret to say, it looks like fixing a CAT scanner with a hummer and nails :-)
You may even succeed, but the maintainability... :-(.

Your problem, at the core, is simple, but you need to use real programming and decent interface, which, most likely, the robot has. Probably, some process in it starts listening for connection. So some of your client processes should try to connect until successful connection is established. And so on...
(And even this is questionable; at least I almost always managed to find some push-technology solutions.)
For a decent resolution you need 1) use some holistic approach, 2) provide a lot more information...

—SA
Joan M 21-Aug-14 3:05am    
Good morning Sergey, the main idea here is that the remote connection must be started as soon as the robot is ready, this means that there won't be any robot program running, therefore, no possibility to automate anything apart of course to make something any standard windows could do.

One of the controllers has a soft PLC inside and in that case is really easy to see if the fieldbus communication starts working. Once this happens from the soft PLC I can start the remote connection really easily, no special effort, no such a big deal.

The issue here is that the second controller doesn't have this soft PLC installed, then it is exactly like a normal computer, but without Wake On Lan capabilities (which could be a solution if I would do it from the robot at startup).

I don't want to install any special library, neither framework to make this and I was searching for something extremely simple.

Robot and controller will always have XP installed, and I don't have to worry about any change on that as support from Microsoft is not there anymore...

That's why I was looking for something like this.
Bark Ups 20-Aug-14 19:38pm    
HiI need to disagree with you Sergey at some point.
Batch files are quiet good (for windows) scripting environment if you know what can you do and how!

but to the point:

@Joan: 1st script will always show state marked as 'down' cause on every loop state is setup as down on the beginning. Setup state as down before ":loop" or make "exit" for state 'up' like if state==up goto :label

if it goes about 2nd script should work (tested variation of it on my pc)


---------------START---------------
@echo off
echo %errorlevel% ^<------------
ping -n 1 127.0.0.1
echo %errorlevel% ^<------------
ping -n 1 188.8.8.8
echo %errorlevel% ^<------------

if %errorlevel%==0 goto itsok
if %errorlevel%==1 goto notok

:itsok
echo it is ok
goto end

:notok
echo it is not ok

:end
pause

---------------END---------------


You can try:
-get rid off all rem comments. I had some problems with rem comments on my scripts. From time to time windows is getting crazy when see rem. don't know why.

-you can also try to save %errorlevel% in new variable (set var=%errorlevel% or setlocal var%errorlevel%)

-you can try adding "setlocal EnableDelayedExpansion"
and replace all % signs in variables with ! example %var% --> !var!

regards
Joan M 21-Aug-14 3:01am    
It looks like PING call is failing in assign the errorlevel flag on Windows 8.1!!! :O

I mean even the remote computer is off I can see PING returning OK.

And I'm 100% sure that the searched computer is not there... (used NetScan to ensure that).

The output of that is:

ping to 127...
Answer from 127... bytes 32 time<1m TTL=128
<!--1m-->Errorlevel = 0

ping to aaa.bbb.ccc.XXX
Answer from aaa.bbb.ccc.YYY host unreachable
Errorlevel = 0

:O

Of course it is always giving OK...

Tested on XP the batch works...
Sergey Alexandrovich Kryukov 21-Aug-14 3:11am    
I use batch files myself, but never for something serious. There is a delicate boundary between reasonable and insane...
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900