Page 1 of 1

Echo ESC char to serial port

Posted: 2021-Nov-12, 5:38 pm
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 1429 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 1429 times
Would anyone have some advice on this topic ?
Many thanks
Jason

Re: Echo ESC char to serial port

Posted: 2021-Nov-13, 8:46 pm
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.

Re: Echo ESC char to serial port

Posted: 2021-Nov-14, 12:38 am
by Shadow Thief
Terminal doesn't support it either, but writing a script to run the commands should preserve the ESC characters.

Re: Echo ESC char to serial port

Posted: 2021-Nov-18, 3:02 pm
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 ?

Re: Echo ESC char to serial port

Posted: 2021-Nov-18, 3:11 pm
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.

Re: Echo ESC char to serial port

Posted: 2021-Nov-20, 5:51 am
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.

Re: Echo ESC char to serial port

Posted: 2021-Nov-20, 5:37 pm
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 ?

Re: Echo ESC char to serial port

Posted: 2021-Nov-20, 11:16 pm
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.