ModbusMaster Reference 0.7
ModbusMaster Reference 0.7
0.7
Contents
1 Module Index 1
1.1 Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2 Class Index 2
2.1 Class List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
3 Module Documentation 2
3.1 ModbusMaster Object Instantiation/Initialization . . . . . . . . . . . 2
3.1.1 Function Documentation . . . . . . . . . . . . . . . . . . . . 2
3.2 ModbusMaster Buffer Management . . . . . . . . . . . . . . . . . . 4
3.2.1 Function Documentation . . . . . . . . . . . . . . . . . . . . 5
3.3 Modbus Function Codes for Discrete Coils/Inputs . . . . . . . . . . . 7
3.3.1 Function Documentation . . . . . . . . . . . . . . . . . . . . 7
3.4 Modbus Function Codes for Holding/Input Registers . . . . . . . . . 10
3.4.1 Function Documentation . . . . . . . . . . . . . . . . . . . . 10
3.5 Modbus Function Codes, Exception Codes . . . . . . . . . . . . . . . 14
3.5.1 Variable Documentation . . . . . . . . . . . . . . . . . . . . 15
4 Class Documentation 17
4.1 ModbusMaster Class Reference . . . . . . . . . . . . . . . . . . . . 17
4.1.1 Detailed Description . . . . . . . . . . . . . . . . . . . . . . 21
4.1.2 Member Function Documentation . . . . . . . . . . . . . . . 21
5 Example Documentation 27
5.1 examples/Basic/Basic.pde . . . . . . . . . . . . . . . . . . . . . . . 27
5.2 examples/PhoenixContact_nanoLC/PhoenixContact_nanoLC.pde . . 28
1 Module Index
1.1 Modules
2 Class Index
Here are the classes, structs, unions and interfaces with brief descriptions:
3 Module Documentation
Functions
• ModbusMaster::ModbusMaster ()
Constructor.
• ModbusMaster::ModbusMaster (uint8_t)
• ModbusMaster::ModbusMaster (uint8_t, uint8_t)
• void ModbusMaster::begin ()
Initialize class object.
Constructor. Creates class object using default serial port 0, Modbus slave ID 1.
49 {
50 _u8SerialPort = 0;
51 _u8MBSlave = 1;
52 }
This is an overloaded member function, provided for convenience. It differs from the
above function only in what argument(s) it accepts.
Creates class object using default serial port 0, specified Modbus slave ID.
Parameters:
u8MBSlave Modbus slave ID (1..255)
65 {
66 _u8SerialPort = 0;
67 _u8MBSlave = u8MBSlave;
68 }
This is an overloaded member function, provided for convenience. It differs from the
above function only in what argument(s) it accepts.
Creates class object using specified serial port, Modbus slave ID.
Parameters:
u8SerialPort serial port (0..3)
u8MBSlave Modbus slave ID (1..255)
82 {
83 _u8SerialPort = (u8SerialPort > 3) ? 0 : u8SerialPort;
84 _u8MBSlave = u8MBSlave;
85 }
Initialize class object. Sets up the serial port using default 19200 baud rate. Call once
class has been instantiated, typically within setup().
97 {
98 begin(19200);
99 }
This is an overloaded member function, provided for convenience. It differs from the
above function only in what argument(s) it accepts.
Sets up the serial port using specified baud rate. Call once class has been instantiated,
typically within setup().
Parameters:
u16BaudRate baud rate, in standard increments (300..115200)
113 {
114 switch(_u8SerialPort)
115 {
116 #if defined(__AVR_ATmega1280__)
117 case 1:
118 MBSerial = Serial1;
119 break;
120
121 case 2:
122 MBSerial = Serial2;
123 break;
124
125 case 3:
126 MBSerial = Serial3;
127 break;
128 #endif
129
130 case 0:
131 default:
132 MBSerial = Serial;
133 break;
134 }
135
136 MBSerial.begin(u16BaudRate);
137 #if __MODBUSMASTER_DEBUG__
138 pinMode(4, OUTPUT);
139 pinMode(5, OUTPUT);
140 #endif
141 }
Functions
• void ModbusMaster::clearResponseBuffer ()
Clear Modbus response buffer.
• void ModbusMaster::clearTransmitBuffer ()
Clear Modbus transmit buffer.
See also:
ModbusMaster::clearResponseBuffer()
Parameters:
u8Index index of response buffer array (0x00..0x3F)
Returns:
value in position u8Index of response buffer (0x0000..0xFFFF)
153 {
154 if (u8Index < ku8MaxBufferSize)
155 {
156 return _u16ResponseBuffer[u8Index];
157 }
158 else
159 {
160 return 0xFFFF;
161 }
162 }
See also:
ModbusMaster::getResponseBuffer(uint8_t u8Index)
172 {
173 uint8_t i;
174
175 for (i = 0; i < ku8MaxBufferSize; i++)
176 {
177 _u16ResponseBuffer[i] = 0;
178 }
179 }
See also:
ModbusMaster::clearTransmitBuffer()
Parameters:
u8Index index of transmit buffer array (0x00..0x3F)
u16Value value to place in position u8Index of transmit buffer (0x0000..0xFFFF)
Returns:
0 on success; exception number on failure
192 {
193 if (u8Index < ku8MaxBufferSize)
194 {
195 _u16TransmitBuffer[u8Index] = u16Value;
196 return ku8MBSuccess;
197 }
198 else
199 {
200 return ku8MBIllegalDataAddress;
201 }
202 }
See also:
ModbusMaster::setTransmitBuffer(uint8_t u8Index, uint16_t u16Value)
212 {
213 uint8_t i;
214
215 for (i = 0; i < ku8MaxBufferSize; i++)
216 {
217 _u16TransmitBuffer[i] = 0;
218 }
219 }
Functions
Modbus function 0x01 Read Coils. This function code is used to read from 1 to 2000
contiguous status of coils in a remote device. The request specifies the starting address,
i.e. the address of the first coil specified, and the number of coils. Coils are addressed
starting at zero.
The coils in the response buffer are packed as one coil per bit of the data field. Status
is indicated as 1=ON and 0=OFF. The LSB of the first data word contains the output
addressed in the query. The other coils follow toward the high order end of this word
and from low order to high order in subsequent words.
If the returned quantity is not a multiple of sixteen, the remaining bits in the final data
word will be padded with zeros (toward the high order end of the word).
Parameters:
u16ReadAddress address of first coil (0x0000..0xFFFF)
u16BitQty quantity of coils to read (1..2000, enforced by remote device)
Returns:
0 on success; exception number on failure
246 {
247 _u16ReadAddress = u16ReadAddress;
248 _u16ReadQty = u16BitQty;
249 return ModbusMasterTransaction(ku8MBReadCoils);
250 }
Modbus function 0x02 Read Discrete Inputs. This function code is used to read from
1 to 2000 contiguous status of discrete inputs in a remote device. The request specifies
the starting address, i.e. the address of the first input specified, and the number of
inputs. Discrete inputs are addressed starting at zero.
The discrete inputs in the response buffer are packed as one input per bit of the data
field. Status is indicated as 1=ON; 0=OFF. The LSB of the first data word contains the
input addressed in the query. The other inputs follow toward the high order end of this
word, and from low order to high order in subsequent words.
If the returned quantity is not a multiple of sixteen, the remaining bits in the final data
word will be padded with zeros (toward the high order end of the word).
Parameters:
u16ReadAddress address of first discrete input (0x0000..0xFFFF)
u16BitQty quantity of discrete inputs to read (1..2000, enforced by remote device)
Returns:
0 on success; exception number on failure
278 {
279 _u16ReadAddress = u16ReadAddress;
280 _u16ReadQty = u16BitQty;
281 return ModbusMasterTransaction(ku8MBReadDiscreteInputs);
282 }
Modbus function 0x05 Write Single Coil. This function code is used to write a single
output to either ON or OFF in a remote device. The requested ON/OFF state is speci-
fied by a constant in the state field. A non-zero value requests the output to be ON and
a value of 0 requests it to be OFF. The request specifies the address of the coil to be
forced. Coils are addressed starting at zero.
Parameters:
u16WriteAddress address of the coil (0x0000..0xFFFF)
u8State 0=OFF, non-zero=ON (0x00..0xFF)
Returns:
0 on success; exception number on failure
350 {
351 _u16WriteAddress = u16WriteAddress;
352 _u16WriteQty = (u8State ? 0xFF00 : 0x0000);
353 return ModbusMasterTransaction(ku8MBWriteSingleCoil);
354 }
Modbus function 0x0F Write Multiple Coils. This function code is used to force each
coil in a sequence of coils to either ON or OFF in a remote device. The request specifies
the coil references to be forced. Coils are addressed starting at zero.
The requested ON/OFF states are specified by contents of the transmit buffer. A logical
’1’ in a bit position of the buffer requests the corresponding output to be ON. A logical
’0’ requests it to be OFF.
Parameters:
u16WriteAddress address of the first coil (0x0000..0xFFFF)
u16BitQty quantity of coils to write (1..2000, enforced by remote device)
Returns:
0 on success; exception number on failure
397 {
398 _u16WriteAddress = u16WriteAddress;
399 _u16WriteQty = u16BitQty;
400 return ModbusMasterTransaction(ku8MBWriteMultipleCoils);
401 }
Functions
Modbus function 0x03 Read Holding Registers. This function code is used to read
the contents of a contiguous block of holding registers in a remote device. The re-
quest specifies the starting register address and the number of registers. Registers are
addressed starting at zero.
The register data in the response buffer is packed as one word per register.
Parameters:
u16ReadAddress address of the first holding register (0x0000..0xFFFF)
u16ReadQty quantity of holding registers to read (1..125, enforced by remote de-
vice)
Returns:
0 on success; exception number on failure
303 {
304 _u16ReadAddress = u16ReadAddress;
305 _u16ReadQty = u16ReadQty;
306 return ModbusMasterTransaction(ku8MBReadHoldingRegisters);
307 }
Modbus function 0x04 Read Input Registers. This function code is used to read from 1
to 125 contiguous input registers in a remote device. The request specifies the starting
register address and the number of registers. Registers are addressed starting at zero.
The register data in the response buffer is packed as one word per register.
Parameters:
u16ReadAddress address of the first input register (0x0000..0xFFFF)
u16ReadQty quantity of input registers to read (1..125, enforced by remote de-
vice)
Returns:
0 on success; exception number on failure
328 {
329 _u16ReadAddress = u16ReadAddress;
330 _u16ReadQty = u16ReadQty;
331 return ModbusMasterTransaction(ku8MBReadInputRegisters);
332 }
Modbus function 0x06 Write Single Register. This function code is used to write a
single holding register in a remote device. The request specifies the address of the
register to be written. Registers are addressed starting at zero.
Parameters:
u16WriteAddress address of the holding register (0x0000..0xFFFF)
u16WriteValue value to be written to holding register (0x0000..0xFFFF)
Returns:
0 on success; exception number on failure
371 {
372 _u16WriteAddress = u16WriteAddress;
373 _u16WriteQty = 0;
374 _u16TransmitBuffer[0] = u16WriteValue;
375 return ModbusMasterTransaction(ku8MBWriteSingleRegister);
376 }
Modbus function 0x10 Write Multiple Registers. This function code is used to write a
block of contiguous registers (1 to 123 registers) in a remote device.
The requested written values are specified in the transmit buffer. Data is packed as one
word per register.
Parameters:
u16WriteAddress address of the holding register (0x0000..0xFFFF)
u16WriteQty quantity of holding registers to write (1..123, enforced by remote
device)
Returns:
0 on success; exception number on failure
420 {
421 _u16WriteAddress = u16WriteAddress;
422 _u16WriteQty = u16WriteQty;
423 return ModbusMasterTransaction(ku8MBWriteMultipleRegisters);
424 }
Modbus function 0x16 Mask Write Register. This function code is used to modify
the contents of a specified holding register using a combination of an AND mask, an
OR mask, and the register’s current contents. The function can be used to set or clear
individual bits in the register.
The request specifies the holding register to be written, the data to be used as the AND
mask, and the data to be used as the OR mask. Registers are addressed starting at zero.
The function’s algorithm is:
Result = (Current Contents && And_Mask) || (Or_Mask && (∼And_Mask))
Parameters:
u16WriteAddress address of the holding register (0x0000..0xFFFF)
u16AndMask AND mask (0x0000..0xFFFF)
u16OrMask OR mask (0x0000..0xFFFF)
Returns:
0 on success; exception number on failure
451 {
452 _u16WriteAddress = u16WriteAddress;
453 _u16TransmitBuffer[0] = u16AndMask;
454 _u16TransmitBuffer[1] = u16OrMask;
455 return ModbusMasterTransaction(ku8MBMaskWriteRegister);
456 }
Modbus function 0x17 Read Write Multiple Registers. This function code performs
a combination of one read operation and one write operation in a single MODBUS
transaction. The write operation is performed before the read. Holding registers are
addressed starting at zero.
The request specifies the starting address and number of holding registers to be read as
well as the starting address, and the number of holding registers. The data to be written
is specified in the transmit buffer.
Parameters:
u16ReadAddress address of the first holding register (0x0000..0xFFFF)
u16ReadQty quantity of holding registers to read (1..125, enforced by remote de-
vice)
u16WriteAddress address of the first holding register (0x0000..0xFFFF)
u16WriteQty quantity of holding registers to write (1..121, enforced by remote
device)
Returns:
0 on success; exception number on failure
481 {
482 _u16ReadAddress = u16ReadAddress;
483 _u16ReadQty = u16ReadQty;
484 _u16WriteAddress = u16WriteAddress;
485 _u16WriteQty = u16WriteQty;
486 return ModbusMasterTransaction(ku8MBReadWriteMultipleRegisters);
487 }
Variables
Modbus protocol illegal function exception. The function code received in the query
is not an allowable action for the server (or slave). This may be because the function
code is only applicable to newer devices, and was not implemented in the unit selected.
It could also indicate that the server (or slave) is in the wrong state to process a request
of this type, for example because it is unconfigured and is being asked to return register
values.
Modbus protocol illegal data address exception. The data address received in the query
is not an allowable address for the server (or slave). More specifically, the combination
of reference number and transfer length is invalid. For a controller with 100 registers,
the ADU addresses the first register as 0, and the last one as 99. If a request is submitted
with a starting register address of 96 and a quantity of registers of 4, then this request
will successfully operate (address-wise at least) on registers 96, 97, 98, 99. If a request
is submitted with a starting register address of 96 and a quantity of registers of 5, then
this request will fail with Exception Code 0x02 "Illegal Data Address" since it attempts
to operate on registers 96, 97, 98, 99 and 100, and there is no register with address 100.
Modbus protocol illegal data value exception. A value contained in the query data field
is not an allowable value for server (or slave). This indicates a fault in the structure
of the remainder of a complex request, such as that the implied length is incorrect. It
specifically does NOT mean that a data item submitted for storage in a register has a
value outside the expectation of the application program, since the MODBUS protocol
is unaware of the significance of any particular value of any particular register.
Modbus protocol slave device failure exception. An unrecoverable error occurred while
the server (or slave) was attempting to perform the requested action.
ModbusMaster success. Modbus transaction was successful; the following checks were
valid:
• slave ID
• function code
• response code
• data
• CRC
ModbusMaster invalid response slave ID exception. The slave ID in the response does
not match that of the request.
ModbusMaster invalid response function exception. The function code in the response
does not match that of the request.
ModbusMaster response timed out exception. The entire response was not received
within the timeout period, ModbusMaster::ku8MBResponseTimeout.
ModbusMaster invalid response CRC exception. The CRC in the response does not
match the one calculated.
4 Class Documentation
Arduino class library for communicating with Modbus slaves over RS232/485 (via
RTU protocol).
#include <ModbusMaster.h>
• ModbusMaster ()
Constructor.
• ModbusMaster (uint8_t)
• ModbusMaster (uint8_t, uint8_t)
• void begin ()
Initialize class object.
• void clearResponseBuffer ()
Clear Modbus response buffer.
• void clearTransmitBuffer ()
Clear Modbus transmit buffer.
Private Attributes
• uint8_t _u8SerialPort
serial port (0..3) initialized in constructor
• uint8_t _u8MBSlave
Modbus slave (1..255) initialized in constructor.
• uint16_t _u16BaudRate
baud rate (300..115200) initialized in begin()
• uint16_t _u16ReadAddress
• uint16_t _u16ReadQty
quantity of words to read
• uint16_t _u16WriteAddress
slave register to which to write
• uint16_t _u16WriteQty
quantity of words to write
Arduino class library for communicating with Modbus slaves over RS232/485 (via
RTU protocol).
Examples:
• evaluate/disassemble response
• return status (success/exception)
Parameters:
u8MBFunction Modbus function (0x01..0xFF)
Returns:
0 on success; exception number on failure
505 {
506 uint8_t u8ModbusADU[256];
507 uint8_t u8ModbusADUSize = 0;
508 uint8_t i, u8Qty;
509 uint16_t u16CRC;
510 uint8_t u8TimeLeft = ku8MBResponseTimeout;
511 uint8_t u8BytesLeft = 8;
512 uint8_t u8MBStatus = ku8MBSuccess;
513
514 // assemble Modbus Request Application Data Unit
515 u8ModbusADU[u8ModbusADUSize++] = _u8MBSlave;
516 u8ModbusADU[u8ModbusADUSize++] = u8MBFunction;
517
518 switch(u8MBFunction)
519 {
520 case ku8MBReadCoils:
521 case ku8MBReadDiscreteInputs:
522 case ku8MBReadInputRegisters:
523 case ku8MBReadHoldingRegisters:
524 case ku8MBReadWriteMultipleRegisters:
525 u8ModbusADU[u8ModbusADUSize++] = highByte(_u16ReadAddress);
526 u8ModbusADU[u8ModbusADUSize++] = lowByte(_u16ReadAddress);
527 u8ModbusADU[u8ModbusADUSize++] = highByte(_u16ReadQty);
528 u8ModbusADU[u8ModbusADUSize++] = lowByte(_u16ReadQty);
529 break;
530 }
531
532 switch(u8MBFunction)
533 {
534 case ku8MBWriteSingleCoil:
535 case ku8MBMaskWriteRegister:
536 case ku8MBWriteMultipleCoils:
537 case ku8MBWriteSingleRegister:
538 case ku8MBWriteMultipleRegisters:
539 case ku8MBReadWriteMultipleRegisters:
540 u8ModbusADU[u8ModbusADUSize++] = highByte(_u16WriteAddress);
541 u8ModbusADU[u8ModbusADUSize++] = lowByte(_u16WriteAddress);
542 break;
543 }
544
545 switch(u8MBFunction)
546 {
547 case ku8MBWriteSingleCoil:
548 u8ModbusADU[u8ModbusADUSize++] = highByte(_u16WriteQty);
549 u8ModbusADU[u8ModbusADUSize++] = lowByte(_u16WriteQty);
550 break;
551
552 case ku8MBWriteSingleRegister:
553 u8ModbusADU[u8ModbusADUSize++] = highByte(_u16TransmitBuffer[0]);
568 break;
569
570 case 1: // i is odd
571 u8ModbusADU[u8ModbusADUSize++] = highByte(_u16TransmitBuffer[i >> 1])
;
572 break;
573 }
574 }
575 break;
576
577 case ku8MBWriteMultipleRegisters:
578 case ku8MBReadWriteMultipleRegisters:
579 u8ModbusADU[u8ModbusADUSize++] = highByte(_u16WriteQty);
580 u8ModbusADU[u8ModbusADUSize++] = lowByte(_u16WriteQty);
581 u8ModbusADU[u8ModbusADUSize++] = lowByte(_u16WriteQty << 1);
582
583 for (i = 0; i < lowByte(_u16WriteQty); i++)
584 {
585 u8ModbusADU[u8ModbusADUSize++] = highByte(_u16TransmitBuffer[i]);
586 u8ModbusADU[u8ModbusADUSize++] = lowByte(_u16TransmitBuffer[i]);
587 }
588 break;
589
590 case ku8MBMaskWriteRegister:
591 u8ModbusADU[u8ModbusADUSize++] = highByte(_u16TransmitBuffer[0]);
592 u8ModbusADU[u8ModbusADUSize++] = lowByte(_u16TransmitBuffer[0]);
593 u8ModbusADU[u8ModbusADUSize++] = highByte(_u16TransmitBuffer[1]);
594 u8ModbusADU[u8ModbusADUSize++] = lowByte(_u16TransmitBuffer[1]);
595 break;
596 }
597
598
599 // append CRC
600 u16CRC = 0xFFFF;
601 for (i = 0; i < u8ModbusADUSize; i++)
602 {
603 u16CRC = _crc16_update(u16CRC, u8ModbusADU[i]);
604 }
605 u8ModbusADU[u8ModbusADUSize++] = lowByte(u16CRC);
606 u8ModbusADU[u8ModbusADUSize++] = highByte(u16CRC);
607 u8ModbusADU[u8ModbusADUSize] = 0;
608
609 // transmit request
610 for (i = 0; i < u8ModbusADUSize; i++)
611 {
612 MBSerial.print(u8ModbusADU[i], BYTE);
613 }
614
615 u8ModbusADUSize = 0;
616 MBSerial.flush();
617
618 // loop until we run out of time or bytes, or an error occurs
619 while (u8TimeLeft && u8BytesLeft && !u8MBStatus)
620 {
621 if (MBSerial.available())
622 {
623 #if __MODBUSMASTER_DEBUG__
624 digitalWrite(4, true);
625 #endif
626 u8ModbusADU[u8ModbusADUSize++] = MBSerial.read();
627 u8BytesLeft--;
628 #if __MODBUSMASTER_DEBUG__
629 digitalWrite(4, false);
630 #endif
631 }
632 else
633 {
634 #if __MODBUSMASTER_DEBUG__
635 digitalWrite(5, true);
636 #endif
637 delayMicroseconds(1000);
638 u8TimeLeft--;
639 #if __MODBUSMASTER_DEBUG__
640 digitalWrite(5, false);
641 #endif
642 }
643
644 // evaluate slave ID, function code once enough bytes have been read
645 if (u8ModbusADUSize == 5)
646 {
647 // verify response is for correct Modbus slave
648 if (u8ModbusADU[0] != _u8MBSlave)
649 {
650 u8MBStatus = ku8MBInvalidSlaveID;
651 break;
652 }
653
654 // verify response is for correct Modbus function code (mask exception bit
7)
655 if ((u8ModbusADU[1] & 0x7F) != u8MBFunction)
656 {
657 u8MBStatus = ku8MBInvalidFunction;
658 break;
659 }
660
661 // check whether Modbus exception occurred; return Modbus Exception Code
662 if (bitRead(u8ModbusADU[1], 7))
663 {
721
722 // disassemble ADU into words
723 if (!u8MBStatus)
724 {
725 // evaluate returned Modbus function code
726 switch(u8ModbusADU[1])
727 {
728 case ku8MBReadCoils:
729 case ku8MBReadDiscreteInputs:
730 // load bytes into word; response bytes are ordered L, H, L, H, ...
731 for (i = 0; i < (u8ModbusADU[2] >> 1); i++)
732 {
733 if (i < ku8MaxBufferSize)
734 {
735 _u16ResponseBuffer[i] = word(u8ModbusADU[2 * i + 4], u8ModbusADU[2 *
i + 3]);
736 }
737 }
738
739 // in the event of an odd number of bytes, load last byte into zero-padde
d word
740 if (u8ModbusADU[2] % 2)
741 {
742 if (i < ku8MaxBufferSize)
743 {
744 _u16ResponseBuffer[i] = word(0, u8ModbusADU[2 * i + 3]);
745 }
746 }
747 break;
748
749 case ku8MBReadInputRegisters:
750 case ku8MBReadHoldingRegisters:
751 case ku8MBReadWriteMultipleRegisters:
752 // load bytes into word; response bytes are ordered H, L, H, L, ...
753 for (i = 0; i < (u8ModbusADU[2] >> 1); i++)
754 {
755 if (i < ku8MaxBufferSize)
756 {
757 _u16ResponseBuffer[i] = word(u8ModbusADU[2 * i + 3], u8ModbusADU[2 *
i + 4]);
758 }
759 }
760 break;
761 }
762 }
763
764 return u8MBStatus;
765 }
The documentation for this class was generated from the following files:
• ModbusMaster.h
• ModbusMaster.cpp
5 Example Documentation
5.1 examples/Basic/Basic.pde
/*
You should have received a copy of the GNU General Public License
along with ModbusMaster. If not, see <http://www.gnu.org/licenses/>.
*/
#include <ModbusMaster.h>
void setup()
{
// initialize Modbus communication baud rate
node.begin(19200);
}
void loop()
{
static uint32_t i;
uint8_t j, result;
uint16_t data[6];
i++;
node.setTransmitBuffer(1, highWord(i));
5.2 examples/PhoenixContact_nanoLC/PhoenixContact_-
nanoLC.pde
/*
You should have received a copy of the GNU General Public License
along with ModbusMaster. If not, see <http://www.gnu.org/licenses/>.
*/
#include <ModbusMaster.h>
// discrete coils
#define NANO_DO(n) (0x0000 + n)
#define NANO_FLAG(n) (0x1000 + n)
// discrete inputs
#define NANO_DI(n) (0x0000 + n)
void setup()
{
// initialize Modbus communication baud rate
nanoLC.begin(19200);
}
void loop()
{
static uint32_t u32ShiftRegister;
static uint32_t i;
uint8_t u8Status;
EG(3)
nanoLC.writeSingleRegister(NANO_REG(3), lowWord(u32ShiftRegister));