Simplest PowerShell Example

The following script is a very simple example of how one of Adaura Technologies' AD-USB4A can be controlled via Windows PowerShell.

powershell_example


$port = New-Object System.IO.Ports.SerialPort
$port.PortName = "COM36"
$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 -m 100 # wait 100ms seconds until device is ready

try
{
    $port.Write("saa 63 `r`n") #writes command to change all channels to 63dB
    Start-Sleep -m 100
    while($myinput = $port.ReadExisting())
    {
        $myinput
    }
    
    $port.Write("status `r`n") #writes command to display status of all channels
    Start-Sleep -m 100
    while($myinput = $port.ReadExisting())
    {
        $myinput
    }
}

catch [TimeoutException]
{
    # Error handling code here
}

finally
{
    # Any cleanup code goes here
}

$port.Close() #closes serial connection