DonCookie
DonCookie

Reputation: 63

How to send Date/Time to COM-Port via Powershell?

i'm just sitting in front of the windows cmd shell and opened a COM-port via powershell to send some information to an external device. if i type the following code into the shell everything works perfectly:

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

But now i want to send date and time to the port, so i thought i just need to change the 5th line:

    $port.WriteLine(Get-Date)

or

    $port.WriteLine($Get-Date)

but that doesn't work (the shell tells me some weird stuff in red letters) and i have no idea so far how this could be done... can anyone help me?

Upvotes: 0

Views: 551

Answers (1)

Shay Levy
Shay Levy

Reputation: 126932

Does this work? "weird stuff in red letters" is an error. What does it say?

$date = Get-Date
$port.WriteLine($date)

Upvotes: 1

Related Questions