Command for opening serial port in Windows 7

69,403

Solution 1

Maybe you can use the Powershell? It's included in Win7...

code taken from here http://blogs.msdn.com/b/powershell/archive/2006/08/31/writing-and-reading-info-from-serial-ports.aspx

Writing to a Serial Port

PS> [System.IO.Ports.SerialPort]::getportnames()
COM3
PS> $port= new-Object System.IO.Ports.SerialPort COM3,9600,None,8,one
PS> $port.open()
PS> $port.WriteLine("Hello world")
PS> $port.Close()

Reading from a Serial Port

PS> $port= new-Object System.IO.Ports.SerialPort COM3,9600,None,8,one
PS> $port.Open()
PS> $port.ReadLine()

Solution 2

To send contents of a file to a serial port:

copy file.bin com1 /b

To send a few characters to a serial port:

echo hello > com1
Share:
69,403
Olumide
Author by

Olumide

Updated on March 28, 2020

Comments

  • Olumide
    Olumide about 4 years

    Is there a Windows command for opening serial ports, say COM3 via the command prompt in Windows 7? For example:

    OPEN "COM6" AS #1
    

    I cannot use pyserial or any other utilities that are not distributed with Windows 7.

    Preferred solution Opening a COM port in QBasic on Windows 7

  • Olumide
    Olumide over 11 years
    Thanks. I was hoping to do so using plain old BASIC 'tho.
  • droplet
    droplet about 11 years
    I use this command with PHP and the shell_exec() function. I have an Arduino connected that I use with the Blink sketch (if you're familiar) that I modified and instead of blinking it prints "Led On" and "Led Off".But sometimes when I refresh my php script I get unreadable strings, like empty Or "?? ?On" or just "Led", incomplete. Is there a way to fix this issue? Does it need a buffer or something?
  • Max
    Max about 11 years
    @Petsoukos I'm sorry, but I know nothing about PHP or Arduino. anyway, if the output is garbled, maybe there is something that interfere... maybe it's some other software/process writing to the same COM port? or maybe something terminating the script (in the shell_exec) before it reach it's natural ending? Maybe you can add some debug log/trace code/message to the start/end of your PHP script , and your shell_exec script to trace it them reach the end correctly, or if they get interrupted by something
  • Kiran Kumar Kotari
    Kiran Kumar Kotari over 7 years
    @Max $port.open() Access to the port 'COM16' is denied. Is there a way to fix this issue?
  • Max
    Max over 7 years
    @kirankumarkotari maybe that the COM16 is already in use by another software (or used by another instance of your software/script). So you can try to: close the other software that is using the COM16, or try to reboot the computer, or try to disable/enable the COM port in the device manager, or try to use Sysinternal PortMon to get of a better understanding of what's happening. It may also be that COM port access right are locked down, so you need administrative right to open the port.