I was just pulling my hair out trying to figure out why I can't communicate with the Arduino through Windows Powershell (which relies on .NET components). Hopefully this will help others. The final code is:
$port = New-Object System.IO.Ports.SerialPort
$port.PortName = "COM6"
$port.BaudRate = "9600"
$port.Parity = "None"
$port.DataBits = 8
$port.StopBits = 1
$port.ReadTimeout = 9000 # 9 seconds
$port.DtrEnable = "true"
$port.open() #opens serial connection
Start-Sleep 2 # wait 2 seconds until Arduino is ready
$port.Write("93c") #writes your content to the serial connection
try
{
while($myinput = $port.ReadLine())
{
$myinput
}
}
catch [TimeoutException]
{
# Error handling code here
}
finally
{
# Any cleanup code goes here
}
$port.Close() #closes serial connection
The line that made all the difference was this:
$port.DtrEnable = "true"
Also, I have my Arduino write back a response after it executes every command, hence the read afterwards.
Hope this helps someone.