Emulating an SDI-12 sensor

Emulating an SDI-12 sensor

When we designed the Yocto-SDI12, we intended it to collect data from SDI-12 sensors, either by interrogating them explicitly, or by monitoring the activity of an existing recorder. So this module was not originally intended to behave like an SDI-12 sensor. But acting upon a request by a customer, we have now added this new capability to the Yocto-SDI12.

To be frank, using a USB interface to build a sensor that communicates in SDI-12 is not a priori the most efficient way to proceed, especially in terms of power consumption. On the other hand, if you need to build a system to test an SDI-12 infrastructure, it becomes interesting to have a USB-controllable SDI-12 interface that can behave like a sensor.

Problems and solutions

The SDI-12 protocol is based on state machines with fairly precise timings, as it has to manage the coexistence of several sensors and bidirectional communication on a single data wire. This is precisely why the basic behavior of the Yocto-SDI12 does not allow it to respond like a client: it is programmed to avoid sending messages that would collide with a sensor responding to the master. The Yocto-SDI12 also checks that any command sent receives a response, and retransmits it if necessary. However, if you need to send a response as a sensor, you are not allowed to retransmit before the master requests it.

The solution is therefore to explicitly indicate to the Yocto-SDI12, using a special character, that a message must be transmitted as is, as if sent from a sensor node. This character, which must prefix any client message, is the circumflex (^). We have chosen this character because it is not a part of valid address codes in SDI-12, and can therefore never be found at the beginning of a message sent by the master.

Example

Suppose you wish to emulate an SDI-12 sensor which responds at address 3 and gives its identification.

When you receive the

3I!


request, simply use the following code to send a valid response:

sdi12port.writeLine("^3I14Acme_incPseudo777")


The ^ character is not sent, but ensures that the response is sent as is on the SDI-12 bus. The device will enforce a small latency of at least 9ms after the latest received message before the message is sent, to ensure that the master has had time to deactivate its transmission circuit.

Autonomous emulation

It's even possible to set up a job directly on the Yocto-SDI12 to emulate an SDI-12 sensor without having to drive it with a software. Simply create a job containing one or more tasks, each one to handle one message. For example:

  1. Task "address query":

    expect "?!"
    writeLine "^3"

  2. Task "acknowledge active":

    expect "3!"
    writeLine "^3"

  3. Task "send identification":

    expect "3I!"
    writeLine "^3I14Acme_incPseudo777"

  4. Task "send measurement":

    expect "3M!"
    writeLine "^30012"

  5. Task "send data":

    expect "3D0!"
    writeLine "^3+3.14-2.71"

And that's it!

To use this new feature, don't forget to start by updating your Yocto-SDI12 to firmware 63221 or higher.

Add a comment No comment yet Back to blog












Yoctopuce, get your stuff connected.