I am communicating with a sensor via serial (COM port) connection. The sensor outputs data only when receiving a specific input string. I want to write a script to repeatedly send the input and save the outputs to a text file.
I am using Plink as serial terminal, and PowerShell for scripting.
I have tried the following:
Write-Output $P |
& $plinkpath -batch -serial COM4 -sercfg 38400,8,n,1,N |
Out-File -filepath $outputfile -Append
The serial connection is made successfully, and sensor output is added to the text file once. However the script hangs here and never terminates so I am not able to loop this command and save multiple data points. I believe the problem is the Plink session is still open and waiting for input, so this line never finishes executing. Any way to close Plink and let my PowerShell script continue?