Data Acquisition (DAQ)

There are many methods to acquire and send data for industrial systems with a range of proprietary and community-based standards that facilitate exchange of information between instruments, a programmable logic controller (PLC), a distributed control system (DCS), and other systems that measure, analyze, or optimize the system. Exchange of information is increasingly important, particularly for optimization solutions, as availability of information is the foundation for many automation and optimization methods. Of particular interest to this course are the methods to retrieve data, run parameter estimation or optimization algorithms, and then either display advisory results or implement a solution back into the process.

Common Communication Standards

MODBUS

ASCII or RTU MODBUS is an older standard than OPC and has several limitations that motivated the creation of OPC. Although it is an old standard, several legacy pieces of equipment still support this protocol. There are several serial or network connection possibilities including RS232, RS422, RS485 (serial) or TCP/IP (network).

# Modbus server (TCP)
from pymodbus.server.asynchronous import StartTcpServer
from pymodbus.server.asynchronous import StartUdpServer
from pymodbus.server.asynchronous import StartSerialServer

from pymodbus.device import ModbusDeviceIdentification
from pymodbus.datastore import ModbusSequentialDataBlock
from pymodbus.datastore import ModbusSlaveContext, ModbusServerContext
from pymodbus.transaction import (ModbusRtuFramer,
                                  ModbusAsciiFramer,
                                  ModbusBinaryFramer)

# configure the service logging
import logging
FORMAT = ('%(asctime)-15s %(threadName)-15s'
          ' %(levelname)-8s %(module)-15s:%(lineno)-8s %(message)s')
logging.basicConfig(format=FORMAT)
log = logging.getLogger()
log.setLevel(logging.ERROR) # logging.DEBUG

def run_async_server():
    nreg = 200
    # initialize data store
    store = ModbusSlaveContext(
        di=ModbusSequentialDataBlock(0, [15]*nreg),
        co=ModbusSequentialDataBlock(0, [16]*nreg),
        hr=ModbusSequentialDataBlock(0, [17]*nreg),
        ir=ModbusSequentialDataBlock(0, [18]*nreg))
    context = ModbusServerContext(slaves=store, single=True)

    # initialize the server information
    identity = ModbusDeviceIdentification()
    identity.VendorName = 'APMonitor'
    identity.ProductCode = 'APM'
    identity.VendorUrl = 'https://apmonitor.com'
    identity.ProductName = 'Modbus Server'
    identity.ModelName = 'Modbus Server'
    identity.MajorMinorRevision = '2.3.0'

    # TCP Server
    StartTcpServer(context, identity=identity, address=("127.0.0.1", 502))

if __name__ == "__main__":
    run_async_server()

# Modbus client
from pymodbus.client.sync import ModbusTcpClient as ModbusClient
from pymodbus.constants import Endian
from pymodbus.payload import BinaryPayloadBuilder
from pymodbus.client.sync import ModbusTcpClient as ModbusClient
from pymodbus.payload import BinaryPayloadDecoder
import numpy as np
import time

print('Start Modbus Client after Modbus Server is Running')

# initiate client
client = ModbusClient(host='127.0.0.1', port=502)
slave_address = 0

# initialize watchdog
wtd = 0

#builder.add_string('abcdefgh')
#builder.add_bits([0, 1, 0, 1, 1, 0, 1, 0])
#builder.add_8bit_int(-0x12)
#builder.add_8bit_uint(0x12)
#builder.add_16bit_int(-0x5678)
#builder.add_16bit_uint(0x1234)
#builder.add_32bit_int(-0x1234)
#builder.add_32bit_uint(0x12345678)
#builder.add_16bit_float(12.34)
#builder.add_16bit_float(-12.34)
#builder.add_32bit_float(22.34)
#builder.add_32bit_float(-22.34)
#builder.add_64bit_int(-0xDEADBEEF)
#builder.add_64bit_uint(0x12345678DEADBEEF)
#builder.add_64bit_uint(0x12345678DEADBEEF)
#builder.add_64bit_float(123.45)
#builder.add_64bit_float(-123.45)

tf = 0
while True:
   time.sleep(0.1)
   v = np.linspace(0,115,116)+0.1

   # increment watchdog
   wtd += 1
   v[0] = wtd
   reg = 0

   ts = time.time()

   builder = BinaryPayloadBuilder()
   for i in range(len(v)):
      builder.add_16bit_int(int(v[i]))
   payload = builder.build()
   # write multiple registers at once
   # limited to 256 registers
   result  = client.write_registers(int(reg), payload,\
              skip_encode=True, unit=int(slave_address))

   tf += time.time()-ts
   if wtd%10==0:
      print('Average Write Time: ' + str(tf/wtd) + ' sec')
client.close()

OPC

OLE (Object Linking and Embedding) for Process Control (OPC), was developed in 1996 by an industrial automation group based on the need for a common platform for exchanging data. The OPC standard details the communication of real-time or historical plant data between control devices and computers. OPC is sometimes referred to as "Oh, Please Connect" with frequent difficulty in connecting to various computers with incorrect DCOM settings. A recent effort termed OPC-UA or Unified Architecture, is a new implementation of the software that allows communication to devices other than the Windows OS platform. In November 2011, the OPC Foundation (body primarily responsible for the OPC standard) officially renamed OPC to mean "Open Platform Communications".

SQL Client/Server

SQL (Structured Query Language) is a programming language popular with enterprise and web applications that requirement storage and access to historical or real-time data. It is not commonly used for process control or automation like MODBUS or OPC but the large user base of SQL programmers and requirements for big-data suggests that SQL may become a more popular platform in the future.

Data Acquisition and Communication

There are several hardware platforms that allow data acquisition and software platforms that facilitate communication.

Robot Operating System (ROS)

ROS is a C++ or Python library that allows inter-process communication. It can be run on anything from a desktop computer to an Arduino (at least in part). Its strength comes from the many different types of ROS packages that already exist and allow for sensors and actuators to communicate.

Micro-processors

Several micro-processors, such as the Raspberry PI and the Beagle Bone Black, have been developed to allow on-board data acquisition and processing. These credit-card sized platforms run a full version of Linux with ARM processors several digital and analog inputs and outputs.

Micro-controllers

The Arduino is a popular micro-controller that allows data acquisition, limited on-board processing, and output capabilities. With a large developer community and supported sensors, this platform is a popular choice for data acquisition and automation applications. The Temperature Control Lab uses an Arduino Uno for data acquisition. The signal is sent to a PC over a serial USB connection.

Assignment

See Sensor Design

💬