mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-10-10 00:23:33 +02:00
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:
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user