Eterlogic virtual serial ports emulator

PowerShell (COM interface)

$ErrorActionPreference = "Stop"
Set-StrictMode -Version 2

# Check if VSPE service is running.
# If it is, the API will not work.
$vspeService = Get-Service -Name EterlogicVspeDeviceManagerService -ErrorAction SilentlyContinue
if ($null -ne $vspeService -and $vspeService.Status -eq "Running")
{
    throw "EterlogicVspeDeviceManagerService is running. Please stop it before trying to use VSPE API"
}


$activationKey = "<Put VSPE API activation key here>"

$vspe = New-Object -ComObject "VSPE.VSPEApi"
if ($null -eq $vspe)
{
    throw "VSPE object is null"
}

# Print out VSPE API information
$info = $vspe.vspe_getVersionInformation()
Write-Host $info

# Activate VSPE with activation key
$result = $vspe.vspe_activate($activationKey)
if ($result -eq 0)
{
    throw "Failed to activate VSPE"
}

Write-Host "VSPE API was successfully activated" -ForegroundColor Green


# Initialization will fail if EterlogicVspeDeviceManagerService service is running
$result = $vspe.vspe_initialize()
if ($result -eq 0)
{
    throw "Failed to initialize VSPE"
}

Write-Host "VSPE API was successfully initialized" -ForegroundColor Green

# Create connector device COM9
$deviceId = $vspe.vspe_createDevice("Connector", "9;0")
if ($deviceId -eq -1)
{
    throw "Failed to create device"
}

Write-Host "COM9 was successfully created" -ForegroundColor Green

Write-Host "Press any key to close script"
Read-Host


# Delete COM9. If COM9 is in use, the release call will fail.
$result = $vspe.vspe_destroyDevice($deviceId)
if ($result -eq 0)
{
    throw "Failed to release COM9, probably device is in use"
}

# Release VSPE object. This will also try to delete all devices.
$vspe.vspe_release()


2007-2025 Eterlogic Software