Tuesday, 19 June 2007

Command line (Console) over serial

I'm a big fan of command line access, if you've got a headless device or a device with a custom shell / UI this tweak is really useful...!

To configure the command processor shell on windows CE to run over a serial connection add the following to your registry

[HKEY_LOCAL_MACHINE\Drivers\Console]
OutputTo = REG_DWORD:1 // Redirects CMD to COM1
COMSpeed = REG_DWORD:19200 // Speed of serial connection

This redirects all input and output for all console applications to the serial port, hmm wonder if it'll work with bluetooth as well... :)

6 comments:

Anonymous said...

Hi!

I've got a headless device and want to establish command line access to it.

Performed the following steps:

1). Added to my WinCE 6.0 OS design image command processor shell.
2). Set registry settings in project.reg file as you described above.
3). Connect null modem cable between desktop PC's and my device's serial port.
4). Booted OS on my target device.
5). Launched HyperTerminal on desktop PC with configuration:
-connect to COM1 (in fact I tried all available serial ports)
-19200 bps -8 data bits
-Parity None
-1 Stop bit
-Flow Control Hardware

I expected that when I start HyperTerminal console window will occur
allowing me to operate windows ce command prompt from desktop PC, but nothing happens.

May be this behaviour is right and I missed some necessary steps?

Need your advice on this issue.

Thanks,
Igor

mailto: r_igor_@hotmail.com

P.S. I also tried to attach display to my target device to test command
processor shell functionality.
When I:
1) leave registry settings by default
2) boot Win CE OS
3) launch cmd.exe on my target device
the result is the following:

command processor starts correctly

When I:
1) set registry settings to redirect command processor to operate over serial port
2) boot Win CE OS
3) launch cmd.exe on my target device or any console application
(e.g. simple "Hello, world!" CE-based console application)
the result is the following:

command processor doesn't start showing
the error message - "CMD cannot start. Low on memory or too
many console windows open. Please close
some console applications and try again."

GraemeW said...

I've been running it using the debug port from the kernel, set the com port to -1 (see below) to do this, else make sure that the devices serial port you are using is working:

[HKEY_LOCAL_MACHINE\Drivers\Console]
"OutputTo"=dword:ffffffff
"COMSpeed"=dword:9600 ; 38400

Remember the com speed is in hex, so 9600 is actually 0x9600 = 38400, in the above example the com speed is normally set by the kernel anyhow so this won't affect anything using this channel but it will for com 1->9.

I don't think you need HW flow control on either, set it to flow control off.

Also on my build i had to run cmd.exe from the start menu before i could get a command prompt on the serial interface, but it was a headed build. If this is still the case in your build make sure you run cmd.exe from the registry using a launch command like this:

[HKEY_LOCAL_MACHINE\init]
"Launch50"="cmd.exe"
"Depend50"=hex:14,00

It depends on device.exe, although this maybe a little too soon before the serial port driver is loaded.

Anonymous said...

hello,

I have the same issue.

I have tried what you said then i received the following lines in my terminal:

Pocket CMD v 5.0
\>

but i can't write any things?

thank you for your help.

Anonymous said...

Thanks for response!

I built the headed build for testing purposes also.

When using the debug port from the kernel for the cmd redirection the error message doesn't appear and I can receive output on HyperTerminal running on the desktop PC
(e.g. I created cmd.bat file with the contents

cd \
cd windows
dir


launched cmd.bat on my device and got the following output on the serial port:

Pocket CMD v 6.00
\> cd \
\> cd windows
\windows> dir

Directory of \windows

07/18/07 03:15p DIR StartUp
07/18/07 03:15p DIR Fonts
07/18/07 03:15p DIR Favorites
07/18/07 07:15a DIR Recent
07/18/07 07:15a DIR Programs
07/18/07 07:15a DIR Desktop
07/18/07 07:15a DIR www
07/18/07 01:56a 50688 shell.exe
07/18/07 02:15a 62464 cmd.exe
07/18/07 02:15a 24064 msmqadm.exe
07/18/07 02:15a 14848 control.exe
07/18/07 01:54a 14726 ceconfig.h

Found 12 file(s). Total size 166790 bytes.
1 Dir(s) 9220096 bytes free

\windows>

).

When I run cmd.exe from the start menu I've got the following output on the serial port:

Pocket CMD v 6.00
\>

But I'm not able to do any input from the keyboard on the desktop (seems to be the same issue that adil morroco described) :(

I launched the Process Viewer tool and saw that there was no cmd.exe process running as if the cmd.exe terminated immediately after I launched it on the target device (tried to run cmd.exe several times but the result was the same).

Is it correct?

May be you have some ideas on how to prevent cmd.exe from terminating itself or how to do input from desktop PC to operate command processor on the target device.

I used the Remote Registry Editor tool for setting the default values of the [HKEY_LOCAL_MACHINE\Drivers\Console] key to check if cmd works at all. But in this case cmd.exe starts correctly and displays in the Process Viewer.

Thanks,
Igor

GraemeW said...

Ok, so after a little investigation.

The HKLM\drivers\console is trying to redirect all 'stdio' to a debug port or serial port, so I think it should be working. Maybe the OAL is only supporting OEMWriteDebugByte and not OEMReadDebugByte (i.e. output characters not input characters from the debug serial port).

I've tried it on a eBox (x86) platform now but i can only get output though no input.

If you run cmd /k it will not exit the command prompt after running an app, but this doesn't seem to help.

The source for cmd.exe is under \WINCE600\PRIVATE\WINCEOS\UTILS\CMD2\
so it maybe just easier to edit this to accept com ports directly to read from... how frustrating!

Anonymous said...

I started cmd.exe /k running via
CreateProcess() from an app that
was started using a registry key:

[HKEY_LOCAL_MACHINE\Init]
"Launch5"="startCmdApp.exe"

I set the console registry keys:

[HKEY_LOCAL_MACHINE\Drivers\Console]
"OutputTo"=dword:1 "COMSpeed"=dword:1C200
;value is in hex
;(9600->0x9600->38400,
;1C200->0x1C200->115200)

The cmd.exe does work, but it does
not echo commands! Giving cmd
"echo" produces response "echo is ON", but commands are not echoed! What is wrong?

This is an armv4i target under wince 5.0.