

If Windows think the device is already in use, it won’t ordinarily allow another program to open or otherwise change the state of the device. I’m not sure how straightforward it would be to write such a program. However, I just forgot about doing it because the problem basically just stopped happening to me. Writing a program to check which ports are open and clear them is something I thought about trying a long time ago when I used to have this kind of problem. Also, what kind of serial port device is it you’re using? None of my machines have a built-in serial port anymore, so I’m generally using a USB-to-serial converter which could simply be plugged out and plugged back in again if it really hung. As a matter of interest, what version of Windows are you running? In recent years, I just haven’t had these kind of problems because Windows seems to have got much better at cleaning up properly when a program that’s using a hardware device crashes. That’s interesting – I haven’t run into that problem myself.

Here’s a complete example as it appeared in my console window: For example, to set COM22 to 38,400 baud with 8 data bits and no parity checking: Input redirection is performed using the “\\.\COM22įinally, to configure the baudrate before sending a string to the serial port, the mode command can be used.

This means that the command finishes immediately rather than waiting for something to be typed in. no input at all, rather than input from the console which would normally be the case). We don’t want the set command to sit around waiting for the user to enter a value for x, so the input to the set command is redirected from “nul” (i.e.

All we really want is a way of outputting the string “hello” without any carriage return and line feed characters, and the set command just happens to provide a convenient way of doing it. Of course, we’re actually not interested in setting the value of x at all – it’s just a means to a different end. The prompt displayed on screen is the string provided in the command. When used with the “/p” switch, the set command prompts the user to enter a value for the environment variable. For example, the following command could be used to set an environment variable called x equal to the string “sunshine”: The set command is normally used to set the value of an environment variable. This probably looks a bit confusing, so let’s break it down. The following example is a more robust version of the command shown above:
