Google Answers Logo
View Question
 
Q: Sending CTRL character in a Windows batch file ( Answered 5 out of 5 stars,   3 Comments )
Question  
Subject: Sending CTRL character in a Windows batch file
Category: Computers > Programming
Asked by: dbcurry-ga
List Price: $2.00
Posted: 21 Apr 2006 11:23 PDT
Expires: 21 May 2006 11:23 PDT
Question ID: 721410
I need to send the command CTRL-G to a serial port in in a .BAT or
.CMD batch file in Windows. I
imagine it's something along the lines of:

ECHO [something] >COM1

where [something] is equivalent to ^G or CTRL-G. What is the escape
character or command that I need to use?
Answer  
Subject: Re: Sending CTRL character in a Windows batch file
Answered By: aht-ga on 21 Apr 2006 23:51 PDT
Rated:5 out of 5 stars
 
dbcurry-ga:

Thanks for your question.

The Ctrl-G character corresponds to the seventh character of the ASCII
character set. That information doesn't do you much good, though, if
you are using a Windows text editor such as Notepad to create your
batch file. Notepad will not let you easily enter control characters
using the standard method of holding down the Alt key, then typing
zero on the number pad, then the decimal value of the ASCII character
you want. This means that you need to use some other editor to
accomplish what you want.

While by no means the only way, perhaps the simplest was to do what
you want, is to use the good ol' DOS EDIT program that is still
available even in Windows XP today:

1. Open up a command prompt window by clicking on the Start button on
your Taskbar, then selecting Run... , and type 'cmd' in the dialog box
that appears followed by the OK button.

2. When the command prompt appears, type EDIT and hit Enter.

3. Your PC should find the EDIT program, and run it. You should
eventually see the blue background familiar to those who lived and
breathed MS-DOS back in the 80's.

4. You can enter special characters in EDIT by first hitting Ctrl-P,
followed by the Ctrl- combo you are seeking... so to enter a Ctrl-G
character, you would enter Ctrl-P Ctrl-G. I'll represent this as
[Ctrl-P Ctrl-G].

5. Using this, go ahead and type '.echo {Ctrl-P Ctrl-G] > COM1'

6. Now, either save this file to your hard drive so that you can
easily open it to copy and paste the line into any other file using
Notepad, or just keep writing the rest of your batch file in EDIT, and
save the finished script as a .BAT file on your hard drive.


I hope that this meets your needs!

Regards,

aht-ga
Google Answers Researcher
dbcurry-ga rated this answer:5 out of 5 stars

Comments  
Subject: Re: Sending CTRL character in a Windows batch file
From: mike_74-ga on 21 Apr 2006 14:40 PDT
 
Have you tried

ECHO ^G >prn

Based on http://www.evergreen.edu/biophysics/technotes/program/batch.htm
Subject: Re: Sending CTRL character in a Windows batch file
From: mike_74-ga on 21 Apr 2006 14:42 PDT
 
Just realized you wanted COM1, not a printer.  Sorry.
Subject: Re: Sending CTRL character in a Windows batch file
From: dbcurry-ga on 23 Apr 2006 19:56 PDT
 
Thanks aht-ga, it worked great.

I have a power strip that can be reset via the serial port, as shown here:
http://www.wti.com/guides/rpb115ug.htm

The 2-line script I am now using to automate reseting the strip is this:

MODE COM3:9600,N,8,1>NUL
ECHO ^B^X^X^B^X^X9^M>COM3

Where CTRL characters are generated using the method you suggested, so
instances of ^B, ^X, and ^M are replaced with symbols.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy