Skip to content

Commit 4e39e7a

Browse files
committed
Fix problem with std::min on Windows; eliminate compiler warnings
1 parent a59270f commit 4e39e7a

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

modbusApp/src/drvModbusAsyn.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@
4343
#include "modbus.h"
4444
#include "drvModbusAsyn.h"
4545

46+
// Windows can define macros min() and max() that interfere with std::min() and std::max()
47+
#ifdef _WIN32
48+
#undef min
49+
#undef max
50+
#endif
51+
4652
/* Defined constants */
4753

4854
#define MAX_READ_WORDS 125 /* Modbus limit on number of words to read */
@@ -1110,11 +1116,6 @@ asynStatus drvModbusAsyn::readFloat64Array (asynUser *pasynUser, epicsFloat64 *d
11101116
asynStatus status;
11111117
static const char *functionName="readFloat64Array";
11121118

1113-
for (i=0; i<maxChans && offset<modbusLength_; i++) {
1114-
errlogPrintf("data[%d] = %d\n", offset, data_[offset]);
1115-
offset++;
1116-
}
1117-
11181119
*nactual = 0;
11191120
pasynManager->getAddr(pasynUser, &offset);
11201121
if (function == P_Data) {
@@ -1228,7 +1229,7 @@ asynStatus drvModbusAsyn::writeFloat64Array(asynUser *pasynUser, epicsFloat64 *d
12281229
case MODBUS_WRITE_MULTIPLE_COILS:
12291230
/* Need to copy data to local buffer to convert to epicsUInt16 */
12301231
for (i=0; i<maxChans && outIndex<modbusLength_; i++) {
1231-
data_[outIndex] = data[i];
1232+
data_[outIndex] = (epicsUInt16)data[i];
12321233
outIndex++;
12331234
nwrite++;
12341235
}
@@ -1291,7 +1292,7 @@ asynStatus drvModbusAsyn::readInt32Array (asynUser *pasynUser, epicsInt32 *data,
12911292
/* If absolute addressing then there is no poller running */
12921293
if (checkModbusFunction(&modbusFunction)) return asynError;
12931294
ioStatus_ = doModbusIO(modbusSlave_, modbusFunction,
1294-
offset, data_, std::min(maxChans, static_cast<size_t>(modbusLength_)));
1295+
offset, data_, std::min((int)maxChans, modbusLength_));
12951296
if (ioStatus_ != asynSuccess) return(ioStatus_);
12961297
offset = 0;
12971298
} else {
@@ -1461,7 +1462,7 @@ asynStatus drvModbusAsyn::readOctet(asynUser *pasynUser, char *data, size_t maxC
14611462
/* If absolute addressing then there is no poller running */
14621463
if (checkModbusFunction(&modbusFunction)) return asynError;
14631464
ioStatus_ = doModbusIO(modbusSlave_, modbusFunction,
1464-
offset, data_, std::min(maxChars, static_cast<size_t>(modbusLength_)));
1465+
offset, data_, std::min((int)maxChars, modbusLength_));
14651466
if (ioStatus_ != asynSuccess) return(ioStatus_);
14661467
offset = 0;
14671468
} else {

0 commit comments

Comments
 (0)