Echo ESC char to serial port

Microsoft Windows
Post Reply
justjason
Posts: 5
Joined: 2021-Nov-12, 5:22 pm

Echo ESC char to serial port

Post by justjason »

I have trying for the last two days to find a way to echo strings containing ESC chars to a COM port.
This would be what I would like to achieve
Capture.PNG
Capture.PNG (4.35 KiB) Viewed 34363 times
Which would be this string ( I doubt the un-printable ESC char will show up, but they should be there if you copy-paste (maybe?)

Code: Select all

echo .I81;;17:.N;19: > \\.\COM14
and if not, this is written out "long hand"

Code: Select all

echo ESC.I81;;17:ESC.N;19: > \\.\COM14
These are commands to configure XON/XOFF flow control for an old pen plotter
When I try and paste the above string with ESC chars in Windows CMD I end up with this
Capture.PNG
Capture.PNG (4.35 KiB) Viewed 34363 times
Would anyone have some advice on this topic ?
Many thanks
Jason
Attachments
Capture.PNG
Capture.PNG (1.39 KiB) Viewed 34363 times
User avatar
Simon Sheppard
Posts: 190
Joined: 2021-Jul-10, 7:46 pm
Contact:

Re: Echo ESC char to serial port

Post by Simon Sheppard »

I think you will need to use a terminal emulator such as PuTTy to be able to do that.

The latest Windows Terminal, might also be capable but I haven't tried it.
Shadow Thief
Posts: 12
Joined: 2021-Aug-03, 1:45 am

Re: Echo ESC char to serial port

Post by Shadow Thief »

Terminal doesn't support it either, but writing a script to run the commands should preserve the ESC characters.
justjason
Posts: 5
Joined: 2021-Nov-12, 5:22 pm

Re: Echo ESC char to serial port

Post by justjason »

Shadow Thief wrote: 2021-Nov-14, 12:38 am Terminal doesn't support it either, but writing a script to run the commands should preserve the ESC characters.
Do you have any pointers for this , or was this just a general statement ?
justjason
Posts: 5
Joined: 2021-Nov-12, 5:22 pm

Re: Echo ESC char to serial port

Post by justjason »

Luckily, the device on the other end of the COM port does not mind if it receives the above config string multiple times. The solution, for my use case, is to use

Code: Select all

forfiles /c "cmd /c <nul set /p=0x1b0x2e0x490x380x310x3b0x3b0x310x370x3a0x1b0x2e0x4e0x3b0x310x390x3a>COM5" 
which can send an HEX string containing the ESC chars.
This will result in the string being sent once for each file in the current directory, and this could get messy, but as said, the device on the other end does not mind if gets one config string or 100, so although this is far from ideal, it works.
Shadow Thief
Posts: 12
Joined: 2021-Aug-03, 1:45 am

Re: Echo ESC char to serial port

Post by Shadow Thief »

justjason wrote: 2021-Nov-18, 3:02 pm
Shadow Thief wrote: 2021-Nov-14, 12:38 am Terminal doesn't support it either, but writing a script to run the commands should preserve the ESC characters.
Do you have any pointers for this , or was this just a general statement ?
I'm not clear on what you're asking. Do you want to know how to write a script? Just put the commands in a text file and save it with the .bat extension.
justjason
Posts: 5
Joined: 2021-Nov-12, 5:22 pm

Re: Echo ESC char to serial port

Post by justjason »

Shadow Thief wrote: 2021-Nov-20, 5:51 am I'm not clear on what you're asking. Do you want to know how to write a script? Just put the commands in a text file and save it with the .bat extension.
What would such a .bat script look like that is able to echo such a string containing multiple ESC chars ?
Shadow Thief
Posts: 12
Joined: 2021-Aug-03, 1:45 am

Re: Echo ESC char to serial port

Post by Shadow Thief »

justjason wrote: 2021-Nov-20, 5:37 pm
Shadow Thief wrote: 2021-Nov-20, 5:51 am I'm not clear on what you're asking. Do you want to know how to write a script? Just put the commands in a text file and save it with the .bat extension.
What would such a .bat script look like that is able to echo such a string containing multiple ESC chars ?
Literally that very first command in your initial post.

Code: Select all

echo .I81;;17:.N;19: > \\.\COM14
Just put it in a batch script and there's no reason that it shouldn't work.

Batch scripts are nothing more than a list of command prompt commands to run and the order in which to run them.
Post Reply