You are using an unsupported browser. Please update your browser to the latest version on or before July 31, 2020.
close
You are viewing the article in preview mode. It is not live at the moment.
Support is available Mon-Fri from 0800 to 1700 Central Time @ (833) 820-5172 Option 2
Home > Compute Articles > COM Port Testing
COM Port Testing
print icon

If you feel that one of your COM ports is malfunctioning you can try testing its read/write ability. This will require inserting a loopback tool into your Serial port.

 

This tool will receive the data and then push it back through the COM port to be received by the computer. 

 

Here is the powershell command to use for this test. Change the COM7 in this example to whatever your COM port is for what you're using. 

 

Copy and paste all the below text into powershell.

 

If you had put the correct COM port to replace the 7 for what is assigned and you get failures it could mean you need to send your unit in for repair.

 

$portName = "COM7"
$baudRates = @(4800, 9600, 14400, 38400, 115200)
$attemptsPerBaud = 10
$testMessage = "LoopbackTest"
$allSuccessful = $true

foreach ($baud in $baudRates) {
    Write-Host "`n--- Testing Baud Rate: $baud ---"

    for ($i = 1; $i -le $attemptsPerBaud; $i++) {
        try {
            $port = New-Object System.IO.Ports.SerialPort $portName, $baud, "None", 8, "One"
            $port.ReadTimeout = 2000
            $port.WriteTimeout = 2000
            $port.Open()

            Write-Host "[$baud] Test ${i}: Sending '$testMessage'"
            $port.WriteLine($testMessage)
            Start-Sleep -Milliseconds 200

            $response = $port.ReadLine()
            Write-Host "[$baud] Test ${i}: Received '$response'"

            if ($response.Trim() -ne $testMessage) {
                Write-Host "[$baud] Test ${i}: Mismatch in loopback data."
                $allSuccessful = $false
            }

            $port.Close()
        } catch {
            Write-Host "[$baud] Test ${i}: Timed out or error: $_"
            if ($port -and $port.IsOpen) { $port.Close() }
            $allSuccessful = $false
        }
    }
}

# Final result
if ($allSuccessful) {
    Write-Host "`n✅ COM port '$portName' is functioning correctly on all tested baud rates."
} else {
    Write-Host "`n❌ COM port '$portName' failed one or more tests. Check loopback or port status."
}
 

Feedback
0 out of 0 found this helpful

scroll to top icon