Skip navigation
All Places > PI Developers Club > Blog > 2015 > February

A while ago I had to work on a complex PI UFL Configuration.  Because the text stream was issued from a COM port it was very difficult to make a test setup for it, so I had to create a set of files first to be able to prepare my PI-UFL interface's .INI file.

To achieve this, since the machine was Windows 7, it was convenient to use Powershell to extract a sample of the text content generated by the COM port so I could bring the generated files on my test machine and start working on my UFL Configuration.


Here is the powershell script I created that reads data from a COM port for $DelaysSeconds and output the content into a text file.

It is also attached to the post for convenience:


#This script read lines on a com port for X Minutes
# usage:
# - configure the script parameters
# - run it using powershell from the command line
#   to send the results to a text file, redirects the pipeline to a text file like this:
#   type "powershell" + "enter"
#   then type ".\ReadCOMPort.ps1 > c:\temp\COMXPortData.txt" + "enter"
$Parity=[System.IO.Ports.Parity]::None # System.IO.Ports.Parity
$StopBits=[System.IO.Ports.StopBits]::one # System.IO.Ports.StopBits
# END PARAMETERS ---------------------------------

$period = [timespan]::FromSeconds($DelaySeconds)
$port= new-Object System.IO.Ports.SerialPort $PORT,$BAUDRATE,$Parity,$dataBits,$StopBits

# Debug
#Write-Output 'PORT OPENED'
$StartTime = Get-Date

# Gets the data from the com port for the specified interval
while ((Get-Date) - $StartTime -lt $period) { 
  Write-Output $message

#Write-Output 'PORT CLOSED'

Filter Blog

By date: By tag: