help with serial comms RRS feed

  • Question

  • Im having an issue where in i need to send commands through the serial comms port and then wait until particular response ins received.

    Currently i have :

    $VerbosePreference = "Continue" $port = New-Object System.IO.Ports.SerialPort "COM8", 115200

    Open the port object:


    Read and write:

    $port.WriteLine("LI") $port.WriteLine("DEBUG AUDIT ON") $port.WriteLine("AR 00")

    Write-Output $value while (($timer.Elapsed.TotalSeconds -lt $Timeout) -and ($value -notcontains "*Audit =")){ Start-Sleep -Seconds 2 Write-Verbose -message "Still waiting for action to complete after [$totalSecs] seconds..."

    } } $timer.Stop() if ($port.IsOpen){ if ($port.BytesToRead -gt 0){ $value = $port.ReadExisting();

    } } Write-Output $value $value =" " $port.Close()

    Basically i need to send down an "AR 00" command, i then need this to wait until the word "Interop" or "instance" are in the input buffer. ( or the 60 second timeout happens)

    Once this has been received i then need to write-output everything that was in the buffer.

    Is this possible, if so can some point me and my puny skill in the right direction on how to do this.

    If is possible to execute more based on the wait result For example where timrout = result 0, "Interop" = result 1, instance= result 2 If result 0 goto ... If result 1 goto .. If result 2 goto ..


    Any help would be really grateful

    Wednesday, December 4, 2019 8:35 PM

All replies

  • You will need to post your code so that it is readable and you need to ask a well formed technical question.

    Read and follow the following forum instructions:

    We cannot answer a question that cannot be read or understood.  Please edit your original post and fix your question and code.

    As little as I can understand this I can only suggest the you want to use "Readline()" in a loop looking for the result of your command.


    Wednesday, December 4, 2019 9:16 PM