Lydia - Printhead
Loading...
Searching...
No Matches
Modbus Function Codes for Discrete Coils/Inputs

Functions

int8_t Modbus::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.
 
int8_t Modbus::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 Modbus::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.
 

Detailed Description

Function Documentation

◆ process_FC1()

int8_t Modbus::process_FC1 ( uint16_t * regs,
uint8_t u8size )
private

This method processes functions 1 & 2 This method reads a bit array and transfers it to the master.

Returns
u8BufferSize Response to master length

Definition at line 1302 of file ModbusRtu.h.

1303{
1307
1308 // get the first and last coil from the message
1311
1312 // put the number of bytes in the outcoming message
1313 u8bytesno = (uint8_t)(u16Coilno / 8);
1314 if (u16Coilno % 8 != 0)
1315 u8bytesno++;
1318
1319 // read each coil from the register map and put its value inside the outcoming message
1320 u8bitsno = 0;
1321
1323 {
1326 u8currentBit = (uint8_t)(u16coil % 16);
1327
1328 bitWrite(
1330 u8bitsno,
1332 u8bitsno++;
1333
1334 if (u8bitsno > 7)
1335 {
1336 u8bitsno = 0;
1337 u8BufferSize++;
1338 }
1339 }
1340
1341 // send outcoming message
1342 if (u16Coilno % 8 != 0)
1343 u8BufferSize++;
1345 sendTxBuffer();
1346 return u8CopyBufferSize;
1347}
@ NB_LO
Number of coils or registers low byte.
Definition ModbusRtu.h:98
@ ADD_LO
Address low byte.
Definition ModbusRtu.h:96
@ NB_HI
Number of coils or registers high byte.
Definition ModbusRtu.h:97
@ ADD_HI
Address high byte.
Definition ModbusRtu.h:95
uint8_t au8Buffer[MAX_BUFFER]
Definition ModbusRtu.h:162
uint8_t u8BufferSize
Definition ModbusRtu.h:163
Definition xtimer.h:21
void sendTxBuffer()
This method transmits au8Buffer to Serial line. Only if u8txenpin != 0, there is a flow handling in o...
Definition ModbusRtu.h:962

◆ process_FC15()

int8_t Modbus::process_FC15 ( uint16_t * regs,
uint8_t u8size )
private

This method processes function 15 This method writes a bit array assigned by the master.

Returns
u8BufferSize Response to master length

Definition at line 1447 of file ModbusRtu.h.

1448{
1452 boolean bTemp;
1453
1454 // get the first and last coil from the message
1457
1458 // read each coil from the register map and put its value inside the outcoming message
1459 u8bitsno = 0;
1460 u8frameByte = 7;
1462 {
1463
1466 u8currentBit = (uint8_t)(u16coil % 16);
1467
1468 bTemp = bitRead(
1470 u8bitsno);
1471
1472 bitWrite(
1475 bTemp);
1476
1477 u8bitsno++;
1478
1479 if (u8bitsno > 7)
1480 {
1481 u8bitsno = 0;
1482 u8frameByte++;
1483 }
1484 }
1485
1486 // send outcoming message
1487 // it's just a copy of the incomping frame until 6th byte
1488 u8BufferSize = 6;
1490 sendTxBuffer();
1491 return u8CopyBufferSize;
1492}

◆ process_FC5()

int8_t Modbus::process_FC5 ( uint16_t * regs,
uint8_t u8size )
private

This method processes function 5 This method writes a value assigned by the master to a single bit.

Returns
u8BufferSize Response to master length

Definition at line 1389 of file ModbusRtu.h.

1390{
1394
1395 // point to the register and its bit
1397 u8currentBit = (uint8_t)(u16coil % 16);
1398
1399 // write to coil
1400 bitWrite(
1403 au8Buffer[NB_HI] == 0xff);
1404
1405 // send answer to master
1406 u8BufferSize = 6;
1408 sendTxBuffer();
1409
1410 return u8CopyBufferSize;
1411}