This version explicitly mutexes port commmunication across the message handling and polling loops.
Overview
The VISA Controller plugin provides a generalized way to quickly and easily integrate devices connected via serial, TCP, GPIB, and USBTMC. It provides both an interface for manually sending commands (backed by a configurable command library) as well as the ability to send an initialization command sequence and periodically polling command sequence. When initializing or periodically polling, each command sent can optionally handle a response and compute any important data into a VAR container. An error checking configuration allows specifying a command sequence to run after the initialization command sequence completes and after each periodic polling command sequence pass completes, in order to check the device for errors. A boolean error condition in that section allows for specifying whether an error occurred on the device, where notably that error will be handled by the plugin like any other errors, including writing the error to log files and to the user interface.
If polling is enabled, both publishing and data logging are options. If publishing is enabled, a configurable publish object is provided which may contain any data in the VAR container and of course use inline expressions where helpful. If data logging is enabled, a full logger configuration is provided to store any data (ex. in CSV form). Also worth noting is an activity log which tracks the operation of the plugin. This is stored to file if enabled but also updates the user interace with indications of when the UI has been initialized, when the intiailization command sequence has been sent, the enable state of periodic polling, publishing, data logging, and activity logging, and any commands manually issued by the user. Further operational details are discussed in the Uesr Interface section below.
User Interface
Below we see an example of the plugin’s user interface, which is divided into 3 resizable sections.
The top left section is the manual control section. It provides a list of configured commands for the device as helpful documentation for the user, along with a section for sending commands manually and observing any responses. Note that the poll period displayed there applies to the configured poll commands as discussed above.
The top right section shows the current published data. This is configurable as discussed above.
The bottom section shows the activity log. This generally tracks the history of important events which occur in the plugin such as initialization, the enable states of polling, publishing, data logging, and activity logging (i.e. whether the plugin is configured to store the activity log to file), as well as any commands and responses issued manually in by the user. It does not capture the poll commands which occur at the poll period, as that would overload the log with periodically sent commands and ultimately make it harder to read (which defeats the purpose of the activity log). If poll commands are enabled, they are occuring at the specified poll period.
Message Handling
This plugin accepts messages to facilitate sending commands to the connected device. For example, we could use a State Machine plugin instance to send this plugin a message. All messages handled by this plugin are in JSON format and have top level operation and data keys.
The operation is simply the name of the message (telling the plugin what kind of action it should take) and data is any data needed by the operation. Data is often a JSON object but needn’t be in the general case.
Let’s see an example message to help set our mental model (notice the top level operation and data elements below):
Below are the messages or “operations” currently handled by this plugin.
Send Library Command
The Send Library Command message allows sending any command configured in the plugin instance’s commandLibrary. On the one hand, the commandLibrary is intended to ease manually sending commands to the connected device. But those library commands can also be issued remotely (from other plugins) by sending a Send Library Command message to this plugin.
Let’s take another look at the example we showed above where we’ll highlight important values:
Observe that the operation is Send Library Command. Also observe that the data seems to want to send a command named Set Voltage DC with channel and voltage parameters set to 1 and 5.2 repsectively.
The question becomes: how does the plugin know what precise command syntax to send to the device? The answer lies in the commandLibrary configuration, an example of which we show here:
[
{
"name": "Query Identification String",
"template": "*IDN?",
"description": "Queries for the device's identification string.",
"example": "*IDN?",
"sampleResponse": "KORAD KC4305 v2.1"
},
{
"name": <span style="background-color:powderblue;">"Set Voltage DC"</span>,
"description": "Gets the DC voltage of the specified channel.",
"example": "VSET1:1.0",
"sampleResponse": "",
"delayAfter": 0
}
]
Notice the last configured library command seems to allow us to set the DC voltage on the device. Furthermore, notice that the name of the command is Set Voltage DC and the template element has a device command with variables in it, @VAR{channel} and @VAR{voltage}, where the command can be parameterized.
We now see how the message corresponds to a Command Library entry:
The name uniquely identifies the command in the library, and
The template has the command syntax with variables in places where the command can be parameterized.
Said differently, the parameters object specified in the message acts as a little variable container to use with the template. In this case the template is VSET@VAR{channel}:@VAR{voltage} resulting in the command syntax: VSET1:5.2.
Send Raw Command
The Send Raw Command message allows sending any raw command to the device. With that in mind, let’s see how we could send the same command to the device we saw above, but this time assuming this plugin has received a Send Raw Command message:
{
"operation": <span style="background-color:powderblue;">"Send Raw Command"</span>,
Notice that we’ve simply specified the precise command to send to the device. In a sense it’s simpler than the Send Library Command message because we aren’t worried about getting the name and parameters matched up to the Command Library entry. On the other hand, it requires that we encode the precise device command syntax into the message and therefore isn’t as interchangeable (it’s not uncommon to support the same library command “surface area” for multiple devices of the same “kind” so that they can be interchangeable in the system).
What about the hasResponse key we see in message data?
In the above message examples, the hasResponse element is set to false. This is because the device does not return a response to the messages in those examples. If the device had returned a response, we would want to set this to true to ensure that the response is read from the underlying “read buffer”. Failing to do so would cause this response to “hang around” in the read buffer and would then be incorrectly returned as the response to any future command.
Importantly, responses from the connnected device are not currently relayed to the sender of the message. That is, if a State Machine plugin instance had sent a Send Library Command or Send Raw Command message to this plugin with a device command that solicited a response from the connected device, that response would not be returned to the State Machine plugin instance. This feature is coming soon and will be facilitated by a later release of this plugin (along with updates to other plugins).
Configuration Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{
"options": {
"connectionConfiguration": {
"Type": "TCP",
"SimulationMode": true,
"Address": "TCPIP1::192.168.1.1::54321::SOCKET",
"Timeout": 2000,
"TerminationEnable": true,
"TerminationCharacter": "\n",
"TrimResponseWhiteSpace": true,
"BytesToRead": 1000,
"ReadToFileEnable": false,
"ReadToFilePath": "",
"DuplicateSession": false,
"AccessMode": "VISA Defaults"
},
"commandLibrary": [
{
"name": "Query Identification String",
"template": "*IDN?",
"description": "Queries for the device's identification string.",
"example": "*IDN?",
"sampleResponse": "Instrument ABC v1.3"
},
{
"name": "Reset",
"template": "*RST",
"description": "Resets the device but does not necessarily clear out errors.",
"example": "*RST",
1.5.0
Plugin Defaults
0
0
0
Configuration Details
Filter:Search in:
ROOTobject
This top level object holds all configuration information for this plugin.
Required:true
Default:(not specified; see any element defaults within)
optionsobject
Configuration options specific to this plugin. Note that variables and expressions are generally allowed in this section.
Required:true
Default:(not specified; see any element defaults within)
The address of the connection / port (ex. COM1, GPIB1::3::INSTR, TCPIP1::192.168.1.1::54321::SOCKET, USB0::0x2EC7::0x6900::800774011787410049::INSTR, etc.), or an array of such addresses. If an array is specified, the plugin uses the first address in the list to successfully open a connection. If none in the array succeed, an error is generated.
The number of bytes to read when reading responses. Note: read operations will terminate on: 1. a termination character, 2. on timeout, 3. on receiving BytesToRead number of bytes.
The number of bytes to read when reading responses. Note: read operations will terminate on: 1. a termination character, 2. on timeout, 3. on receiving BytesToRead number of bytes.
The baud rate to use for serial communication. The available baud rates depend on the serial interface. Common baud rates include: 300, 600, 1200, 2400, 4800, 9600, 38400, 14400, 19200, 57600, 230400, 115200, 460800. Less common though not terrifically uncommon baud rates include: 100, 28800, 56000, 128000, 153600, 256000, 921600.
An array of commands to load into the dropdown in the user interface.
Required:true
Default:
[
{
"name": "Query Identification String",
"template": "*IDN?",
"description": "Queries for the device's identification string.",
"example": "*IDN?",
"sampleResponse": "Instrument ABC v1.3"
},
{
"name": "Reset",
"template": "*RST",
"description": "Resets the device but does not necessarily clear out errors.",
"example": "*RST",
"sampleResponse": "(no response)"
},
{
"name": "Clear Errors",
"template": "*CLS",
"description": "Clears device errors.",
"example": "*CLS",
"sampleResponse": "(no response)"
},
{
"name": "Get Voltage (DC)",
"template": "MEASure:VOLTage:DC?",
"description": "Gets the DC voltage.",
"example": "MEASure:VOLTage:DC?",
"sampleResponse": "1.5 V"
},
{
"name": "Get Current (DC)",
"template": "MEASure:CURRent:DC?",
"description": "Gets the DC current.",
"example": "MEASure:CURRent:DC?",
"sampleResponse": "0.25 mA"
}
]
options.commandLibrary[n]object
A command to include in the dropdown on the user interface.
Required:false
Default:""
options.commandLibrary[n].namestring
A semantic name for the command to show in the dropdown.
Required:false
Default:""
options.commandLibrary[n].templatestring
A template for the command. For example, a command that sets a voltage on a device might have a template such as `SETVOLT @voltage` where `SETVOLT` is the name of the command which takes a paramter (presumably some number) represented in the template as @voltage.
Required:false
Default:""
options.commandLibrary[n].descriptionstring
The description of the command. This should include information about which parameters are accepted and the expected format of any response.
Required:false
Default:""
options.commandLibrary[n].examplestring
A example of valid syntax using this command.
Required:false
Default:""
options.commandLibrary[n].sampleResponsestring
An example of a response to this command.
Required:false
Default:""
options.initializationobject
An object containing initialization options.
Required:true
Default:(not specified; see any element defaults within)
options.initialization.variablesobject
A computation object where keys are JSON paths and values can be of any type and use expressions and functions, and is computed one time when the plugin launches. For example: { "exmapleVar1": 10, "exampleVar2": "kitty" } would make available variables @VAR{exampleVar1} with value 10 and @VAR{exampleVar2} with value "kitty". Note that `instanceName` and `startTimestamp` are already in the container.
The regular expression to use to parse the response. The group / submatches defined in the regex are then available to computations below as variables such as: @VAR{submatch[n]) where n is an integer index representing the 0-based order in which the submatches occurred in the regex. For example, if we have a regex like (ABC)(.+) then @VAR{submatch[0]} is ABC and @VAR{submatch[1]} is whatever matched the .+ part of the regex. Note that the named regex (?&number) is available for use and matches numbers flexibly in integer, floating point, and scientific notation' formats. For example, (?&number) would match each of the following: 12, 12.5, 1.25E1. Note that this setting also applies to the simluationResponse when in simulation mode.
An array of computation objects to be performed after both the command is sent and (if there is a response) the response is received. Parsed @VAR{submatch[n]} variables are available here. All data is put into a VAR container for subsequent access.
The time in milliseconds to delay after sending the command and processing any response. This can be useful in some applications where, for example, an instrument requires a delay between consecutive commands.
Required:true
Default:0
options.shutdownobject
An object containing shutdown options.
Required:true
Default:(not specified; see any element defaults within)
options.shutdown.commandsarray
An array of shutdown commands to send. These commands are only sent once when the plugin shuts down.
The regular expression to use to parse the response. The group / submatches defined in the regex are then available to computations below as variables such as: @VAR{submatch[n]) where n is an integer index representing the 0-based order in which the submatches occurred in the regex. For example, if we have a regex like (ABC)(.+) then @VAR{submatch[0]} is ABC and @VAR{submatch[1]} is whatever matched the .+ part of the regex. Note that the named regex (?&number) is available for use and matches numbers flexibly in integer, floating point, and scientific notation' formats. For example, (?&number) would match each of the following: 12, 12.5, 1.25E1. Note that this setting also applies to the simluationResponse when in simulation mode.
An array of computation objects to be performed after both the command is sent and (if there is a response) the response is received. Parsed @VAR{submatch[n]} variables are available here. All data is put into a VAR container for subsequent access.
A computation object where keys are JSON paths and values can be of any type and use expressions, functions, and variables.
Required:false
Default:(not specified; see any element defaults within)
options.shutdown.commands[n].responseComputations[n].{Valid JSON Set Path}stringnumberbooleanarrayobject
undefined
Required:false
Default:""
options.shutdown.commands[n].delayAfterinteger
The time in milliseconds to delay after sending the command and processing any response. This can be useful in some applications where, for example, an instrument requires a delay between consecutive commands.
Required:true
Default:0
options.errorCheckingobject
An object containing error checking options.
Required:true
Default:(not specified; see any element defaults within)
The regular expression to use to parse the response. The group / submatches defined in the regex are then available to computations below as variables such as: @VAR{submatch[n]) where n is an integer index representing the 0-based order in which the submatches occurred in the regex. For example, if we have a regex like (ABC)(.+) then @VAR{submatch[0]} is ABC and @VAR{submatch[1]} is whatever matched the .+ part of the regex. Note that the named regex (?&number) is available for use and matches numbers flexibly in integer, floating point, and scientific notation' formats. For example, (?&number) would match each of the following: 12, 12.5, 1.25E1. Note that this setting also applies to the simluationResponse when in simulation mode.
An array of computation objects to be performed after both the command is sent and (if there is a response) the response is received. Parsed @VAR{submatch[n]} variables are available here. All data is put into a VAR container for subsequent access.
The time in milliseconds to delay after sending the command and processing any response. This can be useful in some applications where, for example, an instrument requires a delay between consecutive commands.
Required:true
Default:0
options.errorChecking.conditionstringboolean
An expression which evaluates to true if the device has an error, or false otherwise.
Required:true
Default:"Boolean:( @VAR{errorStatus} )"
options.pollingobject
An object containing polling options.
Required:true
Default:(not specified; see any element defaults within)
options.polling.enableboolean
Whether to poll the device.
Required:false
Default:true
options.polling.periodinteger
The period with which the plugin polls the device with the specified commands. Use -1 here to disable polling.
The regular expression to use to parse the response. The group / submatches defined in the regex are then available to computations below as variables such as: @VAR{submatch[n]) where n is an integer index representing the 0-based order in which the submatches occurred in the regex. For example, if we have a regex like (ABC)(.+) then @VAR{submatch[0]} is ABC and @VAR{submatch[1]} is whatever matched the .+ part of the regex. Note that the named regex (?&number) is available for use and matches numbers flexibly in integer, floating point, and scientific notation' formats. For example, (?&number) would match each of the following: 12, 12.5, 1.25E1. Note that this setting also applies to the simluationResponse when in simulation mode.
An array of computation objects to be performed after both the command is sent and (if there is a response) the response is received. Parsed @VAR{submatch[n]} variables are available here. All data is put into a VAR container for subsequent access.
A computation object where keys are JSON paths and values can be of any type and use expressions, functions, and variables.
Required:false
Default:(not specified; see any element defaults within)
options.polling.commands[n].responseComputations[n].{Valid JSON Set Path}stringnumberbooleanarrayobject
undefined
Required:false
Default:""
options.polling.commands[n].delayAfterinteger
The time in milliseconds to delay after sending the command and processing any response. This can be useful in some applications where, for example, an instrument requires a delay between consecutive commands.
Required:true
Default:0
options.polling.publishingobject
An object containing publishing options.
Required:true
Default:(not specified; see any element defaults within)
options.polling.publishing.enableboolean
Whether to publish data.
Required:true
Default:true
options.polling.publishing.dataFormatobject
This object specifies the format of the published data. Data is only published if polling is enabled and publishing is enabled.
Defines the logging (data and errors) for this plugin. Note that a LOG variable space is provided here, as well as the VAR variable space. Available variables are: @LOG{LOGGERNAME}, @LOG{TIMESTAMP}, @LOG{LOGMESSAGE}, @LOG{ERRORMESSAGE}, @VAR{instanceName}. Note: @LOG{LOGGERNAME} is equal to the @VAR{instanceName} here.
Required:false
Default:(not specified; see any element defaults within)
options.polling.logging.Enableboolean
Whether to enable the logger.
Required:true
Default:true
options.polling.logging.LogFolderstring
The folder in which to write log files.
Required:true
Default:"\\JADE_LOGS\\@VAR{instanceName}"
options.polling.logging.FileNameFormatstring
The filename to use when creating log files. Note: if the filesize limit is reached new files will be created with enumerated suffixes such as: MyLogFile-1.txt, MyLogFile-2.txt, etc.
Required:true
Default:"@VAR{instanceName}-@LOG{TIMESTAMP}.csv"
options.polling.logging.ErrorsOnlyboolean
Whether to log only errors.
Required:true
Default:false
options.polling.logging.DiskThrashPeriodinteger
The period in milliseconds with which to flush the file buffer to ensure it's committed to the hard drive. Note: This is a performance consideration to prevent writing to disk too frequently.
Required:true
Default:1000
options.polling.logging.FileSizeLimitinteger
The file size at which to create new files.
Required:true
Default:1000000
options.polling.logging.StartLogFormatstring
The initial string to put into the log file (and subsequent files) when opened for the first time.
Required:true
Default:"Timestamp,Voltage,Current"
options.polling.logging.LogMessageFormatstring
The message format used to construct non-error log entries. All VAR container data is available here.
The final string to put in the log file when closed.
Required:true
Default:""
options.polling.logging.LogEntryFormatstring
The format to use when writing log entries when errors are not present.
Required:true
Default:"@LOG{LOGMESSAGE}"
options.polling.logging.ErrorLogEntryFormatstring
The message format used to construct error log entries.
Required:true
Default:"\n\n@LOG{ERRORMESSAGE}\n\n"
options.polling.logging.TimestampFormatstring
The format used by the @LOG{TIMESTAMP} variable.
Required:true
Default:"%Y-%m-%d %H-%M-%S%3u"
options.activityLoggerobject
Defines the logging (data and errors) for this plugin. Note that a LOG variable space is provided here, as well as the VAR variable space. Available variables are: @LOG{LOGGERNAME}, @LOG{TIMESTAMP}, @LOG{LOGMESSAGE}, @LOG{ERRORMESSAGE}, @VAR{instanceName}. Note: @LOG{LOGGERNAME} is equal to the @VAR{instanceName} here.
Required:true
Default:(not specified; see any element defaults within)
options.activityLogger.Enableboolean
Whether to enable the logger.
Required:true
Default:true
options.activityLogger.LogFolderstring
The folder in which to write log files.
Required:true
Default:"\\JADE_LOGS\\@VAR{instanceName}"
options.activityLogger.FileNameFormatstring
The filename to use when creating log files. Note: if the filesize limit is reached new files will be created with enumerated suffixes such as: MyLogFile-1.txt, MyLogFile-2.txt, etc.
Required:true
Default:"@VAR{instanceName}-@LOG{TIMESTAMP}.csv"
options.activityLogger.ErrorsOnlyboolean
Whether to log only errors.
Required:true
Default:false
options.activityLogger.DiskThrashPeriodinteger
The period in milliseconds with which to flush the file buffer to ensure it's committed to the hard drive. Note: This is a performance consideration to prevent writing to disk too frequently.
Required:true
Default:1000
options.activityLogger.FileSizeLimitinteger
The file size at which to create new files.
Required:true
Default:1000000
options.activityLogger.StartLogFormatstring
The initial string to put into the log file (and subsequent files) when opened for the first time.
The transparency of the window. 0 = opaque, 100 = invisible.
Required:true
Default:0
panel.titlestring
The title of the plugin window when it runs. Note that the variable 'instanceName' is provided here in a VAR variable container.
Required:true
Default:"@VAR{instanceName}"
panel.titleBarVisibleboolean
Whether the window title bar is visible.
Required:true
Default:true
panel.showMenuBarboolean
Whether the menu bar is visible.
Required:true
Default:false
panel.showToolBarboolean
Whether the toolbar is visible.
Required:true
Default:false
panel.makeActiveboolean
Whether the window becomes active when opened.
Required:true
Default:false
panel.bringToFrontboolean
Whether the window is brought to the front / top of other windows when opened.
Required:true
Default:false
panel.minimizableboolean
Whether the window is minimizable.
Required:true
Default:true
panel.resizableboolean
Whether the window is resizable.
Required:true
Default:true
panel.closeableboolean
Whether the window is closeable.
Required:true
Default:true
panel.closeWhenDoneboolean
Whether to close the window when complete.
Required:true
Default:true
panel.centerboolean
Whether to center the window when opened. Note: this property overrides the 'position' property.
Required:true
Default:false
panel.positionobject
The position of the window when opened the first time.
Required:true
Default:(not specified; see any element defaults within)
panel.position.topinteger
The vertical position of the window in pixels from the top edge of the viewport. Note: this property is overriden by the 'center' property.
Required:true
Default:100
panel.position.leftinteger
The horizontal position of the window in pixels from the left edge of the viewport. Note: this property is overriden by the 'center' property.
Required:true
Default:100
panel.sizeobject
The size of the window when opened the first time.
Required:false
Default:(not specified; see any element defaults within)
panel.size.widthinteger
The width of the window in pixels. -1 means use the default width for the panel. Note that depending on panel features exposed, there may be a limit to how small a panel can become.
Required:true
Default:-1
panel.size.heightinteger
The height of the window in pixels. -1 means use the default height for the panel. Note that depending on panel features exposed, there may be a limit to how small a panel can become.
Required:true
Default:-1
channelobject
The communication channel definition used by this plugin. Note: this section rarely needs modifications. In many cases, the underlying plugin implementation depends on at least some of these settings having the values below. Consult with a JADE expert before making changes to this section if you are unfamiliar with the implications of changes to this section.
Required:true
Default:(not specified; see any element defaults within)
channel.SendBreakTimeoutinteger
The timeout duration in milliseconds to wait for sending messages.
Required:true
Default:1000
channel.WaitOnBreakTimeoutinteger
The timeout duration in milliseconds to wait for receiving messages. Note: -1 means wait indefinitely or until shutdown is signalled.
Required:true
Default:-1
channel.WaitOnShutdownTimeoutinteger
The timeout duration in milliseconds to wait for shutdown acknowledgment.
Required:true
Default:2000
channel.ThrowTimeoutErrorsboolean
Whether to throw timeout errors vs simply returning a boolean indicating whether a timeout occurred.
Required:true
Default:false
channel.ThrowShutdownUnacknowledgedErrorsboolean
Whether to throw 'shutdown unacknowledged' errors.
Required:true
Default:true
channel.QueueSizeinteger
The size of the underlying communication queue in bytes. Note: -1 means unbounded (i.e. grow as needed with available memory).
Required:true
Default:-1
channel.SendBreakEnqueueTypeenum (string)
The enqueue strategy employed on the underlying queue for standard messages.
Whether to flush the queue upon waiting for new messages (i.e. whether to clear the queue and wait for the next 'new' message; this has the effect of removing old messages and waiting for the next message.
Required:true
Default:false
channel.FlushQueueAfterBreakingboolean
Whether to flush the queue after receiving a new message (i.e. whether to handle the next message coming in the queue and then flush; this has the effect of handling the oldest message (if it exsits) or the next message before flushing the queue.