nidas v1.2.3
ModbusRTU.h
Go to the documentation of this file.
1// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4; -*-
2// vim: set shiftwidth=4 softtabstop=4 expandtab:
3/*
4 ********************************************************************
5 ** NIDAS: NCAR In-situ Data Acquistion Software
6 **
7 ** 2021, Copyright University Corporation for Atmospheric Research
8 **
9 ** This program is free software; you can redistribute it and/or modify
10 ** it under the terms of the GNU General Public License as published by
11 ** the Free Software Foundation; either version 2 of the License, or
12 ** (at your option) any later version.
13 **
14 ** This program is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ** GNU General Public License for more details.
18 **
19 ** The LICENSE.txt file accompanying this software contains
20 ** a copy of the GNU General Public License. If it is not found,
21 ** write to the Free Software Foundation, Inc.,
22 ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 **
24 ********************************************************************
25*/
26
27
28#ifndef NIDIS_DYNLD_MODBUSRTU_H
29#define NIDIS_DYNLD_MODBUSRTU_H
30
31#include <nidas/Config.h>
32
33#ifdef HAVE_LIBMODBUS
34#include <modbus/modbus.h>
35#endif
36
37#include <unistd.h> // pipe
38
40#include <nidas/util/Thread.h>
41
42namespace nidas { namespace dynld {
43
44 using namespace nidas::core;
45
85{
86public:
87
88 ModbusRTU();
89
93 void validate();
94
95 void init();
96
97 void open(int flags);
98
99#ifdef HAVE_LIBMODBUS
100
101 void close();
102
104
106
107#endif
108
116 bool process(const Sample* samp,std::list<const Sample*>& results)
117 throw();
118
119
120protected:
155
156#ifdef HAVE_LIBMODBUS
157
158 modbus_t* _modbusrtu;
159
160 int _slaveID;
161
162 int _regaddr;
163
164 int _pipefds[2];
165
166 class ModbusThread: public nidas::util::Thread
167 {
168 public:
169 ModbusThread(const std::string& devname, modbus_t* mb, int regaddr,
170 int nvars, int pipefd, float rate):
171 Thread(devname+ "_modbus_thread", false), _devname(devname), _mb(mb), _regaddr(regaddr),
172 _nvars(nvars), _pipefd(pipefd), _rate(rate)
173 {}
174 int run() throw();
175 private:
176 std::string _devname;
177 modbus_t* _mb;
178 int _regaddr;
179 uint16_t _nvars;
180 int _pipefd;
181 float _rate;
182
183 // no copying
184 ModbusThread(const ModbusThread&);
185 // no assignment
186 ModbusThread& operator=(const ModbusThread&);
187 };
188
189 ModbusThread *_thread;
190
191 class ModbusIODevice: public UnixIODevice {
192 public:
193 ModbusIODevice(): UnixIODevice() {}
194 // pipe is opened by sensor open method.
195 void open(int) {}
196
197 void setFd(int val) { _fd = val; }
198 };
199
200 ModbusIODevice *_iodevice;
201
202#endif
203
204 uint16_t _nvars;
205
207
208private:
209 // no copying
211 // no assignment
213};
214
215}} // namespace nidas namespace dynld
216
217#endif
DSMSensor provides the basic support for reading, processing and distributing samples from a sensor a...
Definition DSMSensor.h:88
An interface to an IO device.
Definition IODevice.h:42
A SampleScanner which supports the set/get of message separation parameters and extracts samples from...
Definition SampleScanner.h:430
A scanner of sample data.
Definition SampleScanner.h:74
Class describing a group of variables that are sampled and handled together.
Definition SampleTag.h:88
Interface to a data sample.
Definition Sample.h:190
Support for a sensor that is sending packets on a TCP socket, a UDP socket, a Bluetooth RF Comm socke...
Definition SerialSensor.h:65
SampleScanner * buildSampleScanner()
Calls CharacterSensor::buildSampleScanner(), and then sets the per-byte transmission delay for that s...
Definition SerialSensor.cc:63
IODevice * buildIODevice()
Creates an IODevice depending on the device name prefix: name prefix type of IODevice inet: TCPSocket...
Definition SerialSensor.cc:71
void close()
close my associated device.
Definition SerialSensor.cc:136
A basic Unix I/O device, such as a named pipe, or a watched file.
Definition UnixIODevice.h:49
A subclass of MessageStreamScanner, with a modified nextSampleSepBOM() method that adjusts the sample...
Definition ModbusRTU.h:144
Sample * nextSampleSepBOM(DSMSensor *sensor)
Method to read input and break it into samples where the message separator occurs at the beginning of...
int _nbytesDiscarded
Definition ModbusRTU.h:153
ModbusMessageStreamScanner()
Definition ModbusRTU.h:146
A class for data from a modbus RTU sensor, connected to a serial port.
Definition ModbusRTU.h:85
bool process(const Sample *samp, std::list< const Sample * > &results)
Virtual method that is called to convert a raw sample containing an ASCII NMEA message to a processed...
Definition ModbusRTU.cc:338
void validate()
Definition ModbusRTU.cc:69
ModbusRTU()
Definition ModbusRTU.cc:60
void init()
Initialize the CharacterSensor instance for post-processing.
Definition ModbusRTU.cc:89
void open(int flags)
Open the sensor device port for real-time sampling.
Definition ModbusRTU.cc:138
uint16_t _nvars
Definition ModbusRTU.h:204
ModbusRTU & operator=(const ModbusRTU &)
ModbusRTU(const ModbusRTU &)
SampleTag * _stag
Definition ModbusRTU.h:206
Definition Thread.h:83
The essential core classes of nidas.
Definition A2DConverter.h:31
Sample * getSample(sampleType type, unsigned int len)
A convienence method for getting a sample of an enumerated type from a pool.
Definition Sample.cc:70
Root namespace for the NCAR In-Situ Data Acquisition Software.
Definition A2DConverter.h:31
static float rate
Definition sing.cc:53