2017-05-18 Fred Gleason <fredg@paravelsystems.com>

* Added a 1/10 second hold-off between input polling calls to the
	Modbus driver in 'ripcd/modbus.cpp' and 'ripcd/modbus.h'.
This commit is contained in:
Fred Gleason 2017-05-18 17:40:36 -04:00
parent 1a94f58fff
commit c296491149
3 changed files with 39 additions and 31 deletions

View File

@ -15791,3 +15791,6 @@
* Added code to create and remove LOG_MODES table records when
adding and removing Host definitions.
* Incremented the database version to 263.
2017-05-18 Fred Gleason <fredg@paravelsystems.com>
* Added a 1/10 second hold-off between input polling calls to the
Modbus driver in 'ripcd/modbus.cpp' and 'ripcd/modbus.h'.

View File

@ -46,6 +46,9 @@ Modbus::Modbus(RDMatrix *matrix,QObject *parent)
connect(modbus_socket,SIGNAL(error(int)),this,SLOT(errorData(int)));
modbus_socket->connectToHost(modbus_ip_address.toString(),modbus_ip_port);
modbus_poll_timer=new QTimer(this);
connect(modbus_poll_timer,SIGNAL(timeout()),this,SLOT(pollInputs()));
modbus_watchdog_timer=new QTimer(this);
connect(modbus_watchdog_timer,SIGNAL(timeout()),this,SLOT(watchdogData()));
}
@ -99,7 +102,7 @@ void Modbus::connectedData()
"connection to Modbus device at %s:%u established",
(const char *)modbus_ip_address.toString(),0xffff&modbus_ip_port);
modbus_watchdog_active=false;
PollInputs();
pollInputs();
}
@ -176,7 +179,7 @@ void Modbus::readyReadData()
base=modbus_input_bytes-count;
ProcessInputByte(byte,base);
if(--count==0) {
PollInputs();
modbus_poll_timer->start(MODBUS_POLL_INTERVAL,true);
modbus_istate=0;
}
break;
@ -192,6 +195,34 @@ void Modbus::errorData(int err)
}
void Modbus::pollInputs()
{
char msg[12];
msg[0]=0x88; // Transaction Identifier
msg[1]=0x88;
msg[2]=0x00; // Protocol Identifier
msg[3]=0x00;
msg[4]=0x00; // Message Length
msg[5]=0x06;
msg[6]=0x01; // Modbus ID
msg[7]=0x02; // Function Code (Read Discrete Input)
msg[8]=0x00; // Starting Address
msg[9]=0x00;
msg[10]=0xff&(modbus_gpis>>8); // Quantity of Inputs
msg[11]=0xff&modbus_gpis;
modbus_socket->writeBlock(msg,12);
modbus_watchdog_timer->stop();
modbus_watchdog_timer->start(MODBUS_WATCHDOG_INTERVAL,true);
}
void Modbus::watchdogData()
{
if(!modbus_watchdog_active) {
@ -218,31 +249,3 @@ void Modbus::ProcessInputByte(char byte,int base)
}
modbus_input_states[base]=byte;
}
void Modbus::PollInputs()
{
char msg[12];
msg[0]=0x88; // Transaction Identifier
msg[1]=0x88;
msg[2]=0x00; // Protocol Identifier
msg[3]=0x00;
msg[4]=0x00; // Message Length
msg[5]=0x06;
msg[6]=0x01; // Modbus ID
msg[7]=0x02; // Function Code (Read Discrete Input)
msg[8]=0x00; // Starting Address
msg[9]=0x00;
msg[10]=0xff&(modbus_gpis>>8); // Quantity of Inputs
msg[11]=0xff&modbus_gpis;
modbus_socket->writeBlock(msg,12);
modbus_watchdog_timer->stop();
modbus_watchdog_timer->start(MODBUS_WATCHDOG_INTERVAL,true);
}

View File

@ -32,6 +32,7 @@
#include <switcher.h>
#define MODBUS_POLL_INTERVAL 100
#define MODBUS_WATCHDOG_INTERVAL 1000
class Modbus : public Switcher
@ -51,15 +52,16 @@ class Modbus : public Switcher
void connectedData();
void readyReadData();
void errorData(int err);
void pollInputs();
void watchdogData();
private:
void ProcessInputByte(char byte,int base);
void PollInputs();
int modbus_istate;
int modbus_input_bytes;
std::vector<char> modbus_input_states;
QSocket *modbus_socket;
QTimer *modbus_poll_timer;
QTimer *modbus_watchdog_timer;
bool modbus_watchdog_active;
QHostAddress modbus_ip_address;