175
153 shares, 175 points


One might be excused for considering typically that the idea of connecting units with different units for automation functions is a reasonably current invention. Yet for all of the (comparatively) current hype of the Internet of Things and the ‘smart home’, laboratories have been wiring up their gear to run difficult measurement and check sequences for a lot of a long time now, together with factories doing a lot the identical for automating manufacturing processes.

Much just like the chaotic universe of IoT units, lab tools from totally different producers characteristic a large variety of incompatible protocol and interface requirements. Ultimately these would coalesce into IEEE-488.1 (GPIB) because the bodily layer and by 1990 the primary Standard Commands for Programmable Instruments (SCPI) normal was launched that constructed on prime of IEEE-488.

SCPI defines (because the identify suggests) normal instructions to work together with devices. It has over the previous a long time gone on to offer distant interplay capabilities to every thing from oscilloscopes and energy provides to unique scientific tools. Many off the shelf units a hobbyist should purchase at present characteristic an SCPI interface through its Ethernet, USB or RS-232C port(s) that mixed with software program can be utilized to automate one’s dwelling lab.

Even higher is that it’s comparatively easy so as to add SCPI performance to at least one’s personal units as nicely, as long as it has at the very least an MCU and a few method to talk with the surface world.

Reinventing the Wheel Is No Fun

As a lot enjoyable as it’s to give you one’s personal communication normal for a customized widget, there’s a lot to be stated for sticking to present requirements, as a substitute of including one other ‘standard’ to the pile. One good cause is the time you’ll spend on developing with a protocol that works, which covers all the edge circumstances and leaves sufficient room for future enlargement when new options are added.

Another cause is that of compatibility with present software program, which additionally touches on why finish customers prone to be enthused about this superior new protocol. When utilizing SCPI, it may be pretty painlessly built-in into present (lab) automation software program, as the entire idea behind SCPI is that every instrument will implement its personal vary of customized instructions along with numerous required ones.

For customers of software program like LabVIEW or Sigrok, the perfect situation is that the system speaks SCPI, and that within the worst-case a customized handler must be written for the customized SCPI instructions when one isn’t obtainable but. What won’t ever change right here is the essential SCPI syntax, permitting for fast bootstrapping of latest units, the prevention of bugs (no parser is ideal) and reusing of code. SCPI’s base command set additionally permits performance like synchronization mechanisms by default.

Despite this, when yours really seems on the present stack of measurement gear and programmable energy provides piled up within the dwelling lab, not all of them converse SCPI. The Rigol DS1104Z oscilloscope does through its Ethernet port. The little brother of the Owon XDM2041 DMM (XDM1041) speaks SCPI through its USB port. So far so good, however then the digital load (Arachnid Labs Reload Pro) speaks a customized protocol through USB that might have been SCPI.

The Manson HCS-3304 programmable energy provide does the identical factor with yet one more customized protocol, with the instructions listed within the guide revisions apparently additionally typically being improper. With solely a few of these units supported by Sigrok at this level, automating checks would contain hacking my very own decoder collectively, relatively than a little bit of high-level fumbling with customized SCPI system instructions.

Using requirements appropriately can save quite a lot of time, sanity and gray hairs. Which results in the subsequent query: simply how simple is it so as to add SCPI to at least one’s personal Awesome Widget?

Enter LibSCPI

Not everybody desires to write down their very own SCPI parser from scratch, which is why the SCPI parser library v2, or just ‘libscpi‘ is a good start. It implements the current SCPI 1999 standard. Since we’d be interested by utilizing SCPI on an embedded system, we’ll check out the supplied FreeRTOS with LwIP (netconn) instance. This exhibits the implementation of an SCPI server which runs in a FreeRTOS thread.

The SCPI server units up a TCP listening port on the usual SCPI port (5025), after which instructions could be despatched to the system through any Telnet shopper or comparable in uncooked mode, i.e. plain textual content. Note that on this server instance, LwIP netconn’s NETCONN_COPY is used as a substitute of NETCONN_NOCOPY. This is crucial to stopping knowledge corruption (use of buffer knowledge after delete) when utilizing chained SCPI instructions.

To use libscpi with a USART or different interface, the very first thing to do is about up the library by calling SCPI_Init. The following strategies should even be applied in your code:

  • SCPI_Write(scpi_t* context, const char* knowledge, size_t len)
  • SCPI_Flush(scpi_t* context)
  • SCPI_Error(scpi_t* context, int_fast16_t err)
  • SCPI_Control(scpi_t* context, scpi_ctrl_name_t ctrl, scpi_reg_val_t val)
  • SCPI_Reset(scpi_t* context)

These capabilities are largely self-explanatory. As could be ascertained from the instance implementation, SCPI_Write permits libscpi to write down to your output of selection, with SCPI_Flush used to flush any output buffers that will exist. SCPI_Error prints error messages from libscpi, SCPI_Reset resets the system, and SCPI_Control is used to write down to the management channel (non-compulsory characteristic, right here on TCP port 5026).

To get libscpi to parse any recent incoming strings (all the time terminated with a newline, n, or rn), your code calls SCPI_Input, or within the case of singular instructions, SCPI_Parse will also be used instantly.

An instance implementation of libscpi on STM32 with the ST HAL alongside FreeRTOS and a easy HTTP server could be present in this GitHub repository. This targets the Nucleo-F746ZG improvement board.

SCPI Digital Multimeter

Also supplied with the libscpi instance is the instance implementation of a digital multimeter system. If we open the command definitions and implementations in scpi-def.c, it offers us a great glimpse at what a customized system implementation would require. This begins with the command desk, referred to as scpi_commands.

This desk defines all instructions within the format of a sample with related callback (all however the core ones applied in the identical file), beginning with the IEEE mandated instructions, e.g. *CLS (CLear Status):

{ .sample = "*CLS", .callback = SCPI_CoreCls,}

The ‘*’ (asterisk) in entrance of a command implies that it’s a required, frequent SCPI command that each system should implement. Important ones are *IDN?, which queries (be aware the query mark) the system about its id, *RST to command the system to reset and *WAI that tells the system to attend with executing any new instructions till the instructions previous this command have been accomplished.

After this block of required instructions, we get the block with the DMM capabilities:


{.sample = "MEASure:VOLTage:DC?", .callback = DMM_MeasureVoltageDcQ,},
{.sample = "CONFigure:VOLTage:DC", .callback = DMM_ConfigureVoltageDc,},
{.sample = "MEASure:VOLTage:DC:RATio?", .callback = SCPI_StubQ,},
{.sample = "MEASure:VOLTage:AC?", .callback = DMM_MeasureVoltageAcQ,},
{.sample = "MEASure:CURRent:DC?", .callback = SCPI_StubQ,},
{.sample = "MEASure:CURRent:AC?", .callback = SCPI_StubQ,},
{.sample = "MEASure:RESistance?", .callback = SCPI_StubQ,},
{.sample = "MEASure:FRESistance?", .callback = SCPI_StubQ,},
{.sample = "MEASure:FREQuency?", .callback = SCPI_StubQ,},
{.sample = "MEASure:PERiod?", .callback = SCPI_StubQ,},

The cause for the blended higher and lowercase use within the instructions has to do with the ‘pattern’ facet: in SCPI solely the uppercase a part of the sample is required, and the lowercase part of a command could be omitted for brevity. As famous earlier, a command adopted by a query mark is a question. The use of colons is to separate the degrees of the tree hierarchy that defines an SCPI interface.

To use this hierarchy to measure voltage and present for DC in a single string, one would use the next command:

MEASure:VOLTage:DC?;:MEASure:CURRent:AC?

The semi-colon separates particular person instructions, and the main colon resets the hierarchy to the foundation of the command tree. This latter characteristic can be utilized to create very transient concatenated command strings for e.g. measuring each AC & DC voltage:

MEASure:VOLTage:DC?;AC?

Since the primary command left us within the VOLTage hierarchy degree, the next command would set off the AC? question. This implies that a well-designed interface for a tool could make controlling it fairly environment friendly even when manually typing in queries by avoiding pointless repetition.

Advanced Features

All of this merely scratches the floor of what SCPI is able to, in fact. In addition to plain textual content output, numeric strings will also be marked as being hexadecimal (#H), as octal (#Q), or as binary (#B). Arguments could be supplied together with instructions separated by an area. With libscpi these arguments can then be retrieved within the callback operate.

Complex sequential and overlapping command sequences will also be arrange utilizing the *OPC and *WAI instructions, together with the *OPC? question. These can be utilized together with the standing register instructions and any device-specific instructions to manage particularly timed sequences.

The better part about SCPI might be that it scales together with the complexity of the system, whether or not it’s a easy voltage meter, or a scientific instrument studying quantum-level perturbations, the underlying protocol doesn’t change. By not having to reinvent the identical fundamentals each single time, the developer and consumer of the system can as a substitute give attention to the issues that matter.

In the case of the end-user, that’s in all probability the expertise of unpacking the system, plugging it in and programming within the SCPI sequences that make it carry out the specified capabilities. Which is the main good thing about following established requirements.

[Heading image: Back of Rigol DS1104Z oscilloscope with the Ethernet and USB ports visible. Credit: Rigol]


Like it? Share with your friends!

175
153 shares, 175 points

What's Your Reaction?

confused confused
0
confused
lol lol
0
lol
hate hate
0
hate
fail fail
0
fail
fun fun
0
fun
geeky geeky
0
geeky
love love
0
love
omg omg
0
omg
win win
0
win