Port manager: Difference between revisions
No edit summary |
|||
Line 108: | Line 108: | ||
}} | }} | ||
Thus, you can use commmands as defined by [[pyserial | Thus, you can use commmands as defined by [[pyserial|http://pyserial.readthedocs.io/en/latest/pyserial.html]] for COM port communication or pyvisa for GPIB/USB communication. | ||
=== Terminator / End-of-Line character for GPIB === | === Terminator / End-of-Line character for GPIB === |
Revision as of 20:27, 11 July 2018
SweepMe! supports and simplifies communication to devices via RS232 (COM port), GPIB, USB and TCPIP by using the SweepMe! Port manager.
Introduction
The communication with the hardware is usually done in each Device Class. In order to simplify the process of creating the communication channel, i.e. establish a connection, SweepMe! provides the port manager for easy handling.
Supported protocols
- COM: standard PC serial port using RS-232 protocol
- GPIB: an IEEE-488-Bus, a standard communication
- TCPIP: in planning
- USB: plug and play USB test and measurement device as supported by pyvisa
- VB: a National Instrument VirtualBench device
Usage
Configuration
The following variables have to be set within the __init__ function of a Device Class:
In order to get the available ports listed in the GUI of the corresponding Module, choose desired port types by:
self.port_types = ["COM", "GPIB", "USB", "VB"]
A port object is automatically created by
self.port_manager = True
Port properties
You can set port properties during __init__ of the Device Class or before connect() is called by modifying the self.port_properties dictionary. In order to see all keys of the dictionary, use
print self.port_properties
These parameters can be changed through
self.port_properties = {
"baudrate" : 9600,
"EOL": "\n",
...
}
or change a parameter of self.port_properties as done in the the following example
self.port_properties["EOL"] = "\r"
Some important and commonly used parameters are explained here:
Command | Interface | Type | Default value | Explanation |
---|---|---|---|---|
EOL | COM | String | "\n" | "End of line"-character, will be added to each command sent by self.port.write() and defines the end of each message read by self.port.read() |
EOLwrite | COM | String | None | replaces the character which will be added to each command sent by self.port.write() |
EOLread | COM | String | None | replace the character which defines the end of each message read by self.port.read() |
baudrate | COM | Integer | 9600 | The Baudrate defines the speed of the COM port communication, must be identical to the value of the instrument |
bytesize | COM | Integer | 8 | length of one byte, must be identical to value of the instrument |
stopbyte | COM | Integer | 1 | |
parity | COM | String | "N" | |
xonxoff | COM | bool | False | |
rtscts | COM | bool | False | |
dsrdtr | COM | bool | False | |
timeout | COM, USB, GPIB | Float | 1.0 | time in seconds before a timeout error is raised |
delay | COM, GPIB | Float | 0.0 | delay time in seconds after writing a command to allow an instrument to process the current command. |
Communication
If the port manager is activated, the port is automatically available within all functions of the sequencer procedure as the variable:
self.port
A message can be sent byusing:
self.port.write("string of the message without end-of-line/terminator character")
The end-of-line character ("EOL") will be set by changing the port properties
The answer of a device is acquired by:
var = self.port.read()
The returned object is typically a string, so please do not forget to change the type if needed by using e.g. int() or float().
In case you need direct access to the port object created by the port manager, use:
self.port.port
Thus, you can use commmands as defined by http://pyserial.readthedocs.io/en/latest/pyserial.html for COM port communication or pyvisa for GPIB/USB communication.
Terminator / End-of-Line character for GPIB
Typically, communication via GPIB does not require to set an End-of-Line (EOL) character. However, some devices expect and send special characters at the end of each message indicating that the command/message is complete.
At the moment, setting EOL for GPIB is not implemented via self.port_properties. One has to modify the pyvisa GPIBInstrument object, using
self.port.port.write_termination = "\r\n"
self.port.port.read_termination = "\r\n"
# "\r\n" is here one example for using Carriage Return (CR) and Line Feed (LF) as terminator
which can be done e.g. in the connect() function of the DeviceClass