Skip to main content
Added insight for why the first answer wouldn't work.
Source Link

Did you try:

[System.IO.Ports.SerialPort]::getportnames()

COM1

$port= new-Object System.IO.Ports.SerialPort COM1,9600,None,8,one
$port.open()
$port.WriteLine("Hello world")
$port.Close()

And reading from a Serial Port

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

Edit:

I found out on this site: https://social.msdn.microsoft.com/Forums/en-US/b9633593-377e-4d6f-b3a9-838de0555371/serialdevicefromidasync-always-returns-null-unless-the-serial-adapter-is-plugged-in-after-boot

Serial port is used by debugger for kernel and is not available to use by other devices. There is a solution described there, but I cant confirm if it is working as I don't have Windows on my PI2, it's just simply too much overhead with that.

Did you try:

[System.IO.Ports.SerialPort]::getportnames()

COM1

$port= new-Object System.IO.Ports.SerialPort COM1,9600,None,8,one
$port.open()
$port.WriteLine("Hello world")
$port.Close()

And reading from a Serial Port

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

Did you try:

[System.IO.Ports.SerialPort]::getportnames()

COM1

$port= new-Object System.IO.Ports.SerialPort COM1,9600,None,8,one
$port.open()
$port.WriteLine("Hello world")
$port.Close()

And reading from a Serial Port

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

Edit:

I found out on this site: https://social.msdn.microsoft.com/Forums/en-US/b9633593-377e-4d6f-b3a9-838de0555371/serialdevicefromidasync-always-returns-null-unless-the-serial-adapter-is-plugged-in-after-boot

Serial port is used by debugger for kernel and is not available to use by other devices. There is a solution described there, but I cant confirm if it is working as I don't have Windows on my PI2, it's just simply too much overhead with that.

Did you try:

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

COM1

$port= new-Object System.IO.Ports.SerialPort COM1,9600,None,8,one
$port.open()
$port.WriteLine("Hello world")
$port.Close()

And reading from a Serial Port

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

Did you try:

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

And reading from a Serial Port

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

Did you try:

[System.IO.Ports.SerialPort]::getportnames()

COM1

$port= new-Object System.IO.Ports.SerialPort COM1,9600,None,8,one
$port.open()
$port.WriteLine("Hello world")
$port.Close()

And reading from a Serial Port

$port= new-Object System.IO.Ports.SerialPort COM1,9600,None,8,one
$port.Open()
$port.ReadLine()
Source Link

Did you try:

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

And reading from a Serial Port

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