diff --git a/src/modbusSlave.h b/src/modbusSlave.h index 3308b16..f760e1d 100644 --- a/src/modbusSlave.h +++ b/src/modbusSlave.h @@ -46,6 +46,7 @@ class slave { return C.at(_coilAddress); } else { ofLogError("ofxModbusTCP Slave:"+ofToString(idNumber)+" on "+masterIP)<<"Get Slave Coil Exceeds Size"; + return 0; } } int getRegister (int _registerAddress) { @@ -53,6 +54,7 @@ class slave { return R.at(_registerAddress); } else { ofLogError("ofxModbusTCP Slave:"+ofToString(idNumber)+" on "+masterIP)<<"Get Slave Register Exceeds Size"; + return 0; } } diff --git a/src/ofxModbusTcpClient.cpp b/src/ofxModbusTcpClient.cpp index f740839..f46729c 100644 --- a/src/ofxModbusTcpClient.cpp +++ b/src/ofxModbusTcpClient.cpp @@ -70,12 +70,21 @@ void ofxModbusTcpClient::setup(string _ip, int _numberOfSlaves) { ofLogVerbose("ofxModbusTCP IP:"+ip)<<"Setup with "< 247) { numberOfSlaves = 1; } + ofLogVerbose("ofxModbusTCP IP:"+ip)<<"Setup with "<0 && _id < slaves.size() && _startAddress < numOfCoils) { return slaves.at(_id-1)->getCoil(_startAddress); + } else { + return false; } } else { return false; @@ -371,6 +382,8 @@ int ofxModbusTcpClient::getRegister(int _id, int _startAddress) { if (enabled ) { if (_id>0 && _id < slaves.size() && _startAddress < numOfRegisters) { return slaves.at(_id-1)->getRegister(_startAddress); + } else { + return 0; } } else { return 0; diff --git a/src/ofxModbusTcpClient.h b/src/ofxModbusTcpClient.h index 25b67c6..dbf046b 100644 --- a/src/ofxModbusTcpClient.h +++ b/src/ofxModbusTcpClient.h @@ -49,6 +49,7 @@ class ofxModbusTcpClient : public ofThread { void setup(string _ip, int _numberOfSlaves); void setup(string _ip); + void setup(string _ip, int _numberOfSlaves, int _port); void connect(); void disconnect();