Virtual serial ports emulator project

Python bindings

Python bindings requirements

Requirements for native bindings

Requirements for COM bindings

Python sample (native)

#python

# --------------------------------------
# VSPE python subsystem usage sample
# --------------------------------------

import msvcrt
import VSPE_Python

config_file_path = '1.vspe'
activationKey = ''; # <-----  PUT ACTIVATION KEY HERE

# display VSPE API version information
print VSPE_Python.vspe_getVersionInformation()


# ****************************
# STEP 1 - INITIALIZATION
# ****************************

# activate VSPE API
result = VSPE_Python.vspe_activate(activationKey)
if result == False:
    print 'VSPE API activation error'
    exit(1)

# initialize VSPE python binding subsystem
result = VSPE_Python.vspe_initialize()

if result == False:
    print 'Initialization error'
    exit(1)

# stop current emulation
result = VSPE_Python.vspe_stopEmulation()
if result == False:
    print 'Error: emulation can not be stopped: maybe one of VSPE devices is still used.'
    exit(1)



# *********************************
# Dynamically creating devices
# *********************************
# Create Connector device (COM9, no baud rate emulation)
deviceId = VSPE_Python.vspe_createDevice("Connector", "9;0");
if deviceId == -1:
    print 'Error: can not create device'
    VSPE_Python.vspe_release()
    exit(1)


# *********************************
# Working with configuration files
# *********************************

# save configuration to file
result = VSPE_Python.vspe_saveConfiguration(config_file_path)
if result == False:
    print 'Error: can not save configuration'
    VSPE_Python.vspe_release()
    exit(1)


# load configuration from file
result = VSPE_Python.vspe_loadConfiguration(config_file_path)
if result == False:
    print 'Error: can not load configuration'
    VSPE_Python.vspe_release()
    exit(1)

# ****************************
# STEP 2 - EMULATION LOOP
# ****************************

# start emulation
result = VSPE_Python.vspe_startEmulation()
if result == False:
    print 'Error: can not start emulation'
    VSPE_Python.vspe_release()
    exit(1)

# emulation loop
print 'Press any key to quit'
msvcrt.getch()


# ****************************
# STEP 3 - EXIT
# ****************************

# stop emulation before exit (skip this call to force kernel devices work without this script)
result = VSPE_Python.vspe_stopEmulation()
if result == False:
    print 'Error: emulation can not be stopped: maybe one of VSPE devices is still used.'
    exit(1)


# release VSPE python binding subsystem before exit
VSPE_Python.vspe_release()
exit(0)

Python sample (COM interface)

#python
import win32com.client
import msvcrt

vspe = win32com.client.Dispatch("VSPE.VSPEApi")
activationKey = ''; # <-----  PUT ACTIVATION KEY HERE

# display VSPE API version information
print vspe.vspe_getVersionInformation()

# activate VSPE API
vspe.vspe_activate(activationKey)

# initialize VSPE
vspe.vspe_initialize()

# create Connector (COM9, no baud rate emulation)
vspe.vspe_createDevice('Connector','9;0')

# create Splitter (COM9 => COM10)
vspe.vspe_createDevice('Splitter','10;9;0;19200,0,8,1,0,0;0;0;0')

# create Pair device (COM21 => COM22)
vspe.vspe_createDevice('Pair','21;22;0')

# start emulation
vspe.vspe_startEmulation()

# wait for any key ...
print 'Press any key to quit'
msvcrt.getch()


# stop emulation
vspe.vspe_stopEmulation()

# release VSPE
vspe.vspe_release()


Copyright (C) 2007-2023 Eterlogic.com. All rights reserved.