Saturday, April 24, 2010

How to create a file with special characters from the keyboard

This one is old school and a little weird. For my home automation system I wanted to have a server on my network power-cycle a device. The UPB technology that I use allows you to do that if you inject a special character sequence onto the mains current in the house (See my techno section for more details). Anyhoo, I need to embed the sequence of characters into a little data file that then gets copied to the serial port using 'copy com3 /b'. The tricky thing is that the file needs to include some characters that cannot be typed from the keyboard (ASCII 20h and 13h). Of course I could have used a hex editor, but being an old DOS hack, I did it this way:

1 - Look up an old ASCII chart and discover 20h is Ctrl-T and 13h is Ctrl-M
2 - Issue the following on a CMD prompt

copy con myfile.txt

3 - Hold down the Ctrl key and hit T
4 - Hold down the Ctrl key and hit M
5 - To finish, quit and save hold down the Ctrl key and hit Z

This will then write the required file to disk.

No comments:

Post a Comment