Lydia - Printhead
◆ getTimeOutState()
boolean Modbus::getTimeOutState
(
)
get communication watch-dog timer state
Return communication Watchdog state. It could be useful to reset outputs if the watchdog is fired.
Returns TRUE if millis() > u32timeOut
Definition at line 506 of file ModbusRtu.h .
◆ poll() [1/2]
cyclic poll for master
*** Only for Modbus Master *** This method checks if there is any incoming answer if pending. If there is no answer, it would change Master state to COM_IDLE. This method must be called only at loop section. Avoid any delay() function.
Any incoming data would be redirected to au16regs pointer, as defined in its modbus_t query telegram.
@params nothing
Returns errors counter
Definition at line 691 of file ModbusRtu.h .
697 u8current =
port ->available();
736 Log.verboseln(
"Add error : %d - RX-Buffer < 7" , i8state);
743 if (u8exception != 0)
745 Log.verboseln(
"ModbusRTU::poll : exception : %d" , u8exception);
753 case MB_FC_READ_COILS:
754 case MB_FC_READ_DISCRETE_INPUT:
758 case MB_FC_READ_INPUT_REGISTER:
759 case MB_FC_READ_REGISTERS:
763 case MB_FC_WRITE_COIL:
764 case MB_FC_WRITE_REGISTER:
765 case MB_FC_WRITE_MULTIPLE_COILS:
766 case MB_FC_WRITE_MULTIPLE_REGISTERS:
◆ poll() [2/2]
int8_t Modbus::poll
(
uint16_t *
regs ,
uint8_t
u8size
)
cyclic poll for slave
*** Only for Modbus Slave *** This method checks if there is any incoming query Afterwards, it would shoot a validation routine plus a register query Avoid any delay() function !!!! After a successful frame between the Master and the Slave, the time-out timer is reset.
Parameters
*regs register table for communication exchange
u8size size of the register table
Returns 0 if no query, 1..4 if communication error, >4 if correct query processed
Definition at line 790 of file ModbusRtu.h .
799 u8current =
port ->available();
832 Serial.println(
"exception : 1" );
845 Log.verboseln(
"mb : process message : %d" ,
FUNC );
850 case MB_FC_READ_COILS:
851 case MB_FC_READ_DISCRETE_INPUT:
854 case MB_FC_READ_INPUT_REGISTER:
855 case MB_FC_READ_REGISTERS:
858 case MB_FC_WRITE_COIL:
861 case MB_FC_WRITE_REGISTER:
864 case MB_FC_WRITE_MULTIPLE_COILS:
867 case MB_FC_WRITE_MULTIPLE_REGISTERS:
◆ query()
int8_t Modbus::query
(
modbus_t
telegram )
only for master
*** Only Modbus Master *** Generate a query to an slave with a modbus_t telegram structure The Master must be in COM_IDLE mode. After it, its state would be COM_WAITING. This method has to be called only in loop() section.
See also modbus_t
Parameters
modbus_t modbus telegram structure (id, fct, ...)
Todo: finish function 15
Definition at line 592 of file ModbusRtu.h .
595 uint8_t u8regsno, u8bytesno;
601 if ((telegram.
u8id == 0) || (telegram.
u8id > 247))
614 switch (telegram.
u8fct )
616 case MB_FC_READ_COILS:
617 case MB_FC_READ_DISCRETE_INPUT:
618 case MB_FC_READ_REGISTERS:
619 case MB_FC_READ_INPUT_REGISTER:
624 case MB_FC_WRITE_COIL:
629 case MB_FC_WRITE_REGISTER:
634 case MB_FC_WRITE_MULTIPLE_COILS:
636 u8bytesno = u8regsno * 2;
648 u8regsno = u8bytesno = 0;
656 case MB_FC_WRITE_MULTIPLE_REGISTERS:
662 for (uint16_t i = 0; i < telegram.
u16CoilsNo ; i++)
uint8_t validateAnswer()
This method validates master incoming messages.
void buildException(uint8_t u8exception)
This method builds an exception message.
@ NB_HI
Number of coils or registers high byte.
int8_t process_FC15(uint16_t *regs, uint8_t u8size)
This method processes function 15 This method writes a bit array assigned by the master.
int8_t process_FC5(uint16_t *regs, uint8_t u8size)
This method processes function 5 This method writes a value assigned by the master to a single bit.
uint8_t validateRequest()
This method validates slave incoming messages.
uint8_t u8serno
serial port: 0-Serial, 1..3-Serial1..Serial3; 4: use software serial
void printHex(uint8_t *data, uint8_t length)
#define ku8MBLinkTestOmronMX2Only
Modbus function 0x08 Test.
uint8_t rxBuffer[MAX_BUFFER]
void sendTxBuffer()
This method transmits au8Buffer to Serial line. Only if u8txenpin != 0, there is a flow handling in o...
int8_t process_FC6(uint16_t *regs, uint8_t u8size)
This method processes function 6 This method writes a value assigned by the master to a single word.
uint8_t au8Buffer[MAX_BUFFER]
@ FUNC
Function code position.
int8_t process_FC1(uint16_t *regs, uint8_t u8size)
This method processes functions 1 & 2 This method reads a bit array and transfers it to the master.
@ ADD_HI
Address high byte.
int8_t process_FC16(uint16_t *regs, uint8_t u8size)
This method processes function 16 This method writes a word array assigned by the master.
int8_t process_FC3(uint16_t *regs, uint8_t u8size)
This method processes functions 3 & 4 This method reads a word array and transfers it to the master.
SoftwareSerial * softPort
Pointer to SoftwareSerial class object.
HardwareSerial * port
Pointer to Serial class object.
uint8_t u8id
0=master, 1..247=slave number
int8_t getRxBuffer()
This method moves Serial buffer data to the Modbus au8Buffer.
@ ADD_LO
Address low byte.
@ NB_LO
Number of coils or registers low byte.