Skip to content

Commit

Permalink
modbus_master: fix modbus master example
Browse files Browse the repository at this point in the history
  • Loading branch information
JorgeGzm committed Feb 16, 2024
1 parent f9f63dc commit 7c34942
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
8 changes: 6 additions & 2 deletions examples/modbusmaster/mbmaster_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ int main(int argc, FAR char *argv[])

if (ret != OK)
{
fprintf(stderr, "mbmaster_main: ",
fprintf(stderr, "mbmaster_main: "
"ERROR: mbmaster_initialize failed: %d\n", ret);
goto errout;
}
Expand All @@ -292,11 +292,15 @@ int main(int argc, FAR char *argv[])

if (ret != OK)
{
fprintf(stderr, "mbmaster_main: ",
fprintf(stderr, "mbmaster_main: "
"ERROR: mbmaster_pollthread create failed: %d\n", ret);
goto errout_with_initialize;
}

/* Work around to give time to pthread_create run the modbus poller */

usleep(100000);

printf("Sending %d requests to slave %d\n",
MBMASTER_REQUESTS_COUNT, SLAVE_ID);

Expand Down
6 changes: 3 additions & 3 deletions include/modbus/mbport.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ bool xMBPortEventGet(eMBEventType *eEvent);

bool xMBMasterPortEventInit(void);
bool xMBMasterPortEventPost(eMBMasterEventType eEvent);
bool xMBMasterPortEventGet(eMBMasterEventType * eEvent);
bool xMBMasterPortEventGet(eMBMasterEventType *eEvent);
void vMBMasterOsResInit(void);
bool xMBMasterRunResTake(int32_t time);
void vMBMasterRunResRelease(void);
Expand All @@ -138,15 +138,15 @@ bool xMBPortSerialInit(uint8_t ucPort, speed_t ulBaudRate,
void vMBPortClose(void);
void xMBPortSerialClose(void);
void vMBPortSerialEnable(bool xRxEnable, bool xTxEnable);
bool xMBPortSerialGetByte(int8_t * pucByte);
bool xMBPortSerialGetByte(int8_t *pucByte);
bool xMBPortSerialPutByte(int8_t ucByte);

bool xMBMasterPortSerialInit(uint8_t ucPort, speed_t ulBaudRate,
uint8_t ucDataBits, eMBParity eParity);
void vMBMasterPortClose(void);
void xMBMasterPortSerialClose(void);
void vMBMasterPortSerialEnable(bool xRxEnable, bool xTxEnable);
bool xMBMasterPortSerialGetByte(int8_t * pucByte);
bool xMBMasterPortSerialGetByte(int8_t *pucByte);
bool xMBMasterPortSerialPutByte(int8_t ucByte);

/* Timers functions */
Expand Down
7 changes: 7 additions & 0 deletions modbus/mb_m.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,13 @@ eMBErrorCode eMBMasterPoll(void)

vMBMasterRunResRelease();
break;

case EV_MASTER_PROCESS_SUCCESS:
case EV_MASTER_ERROR_RESPOND_TIMEOUT:
case EV_MASTER_ERROR_RECEIVE_DATA:
case EV_MASTER_ERROR_EXECUTE_FUNCTION:
default:
break;
}
}

Expand Down
8 changes: 4 additions & 4 deletions modbus/nuttx/portevent_m.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ bool xMBMasterPortEventPost(eMBMasterEventType eEvent)
return true;
}

bool xMBMasterPortEventGet(eMBMasterEventType * eEvent)
bool xMBMasterPortEventGet(eMBMasterEventType *eEvent)
{
bool xEventHappened = false;

Expand Down Expand Up @@ -227,7 +227,7 @@ void vMBMasterRunResRelease(void)
*/

void vMBMasterErrorCBRespondTimeout(uint8_t ucDestAddress,
const uint8_t * pucPDUData,
const uint8_t *pucPDUData,
uint16_t usPDULength)
{
xMBMasterPortEventPost(EV_MASTER_ERROR_RESPOND_TIMEOUT);
Expand All @@ -243,7 +243,7 @@ void vMBMasterErrorCBRespondTimeout(uint8_t ucDestAddress,
*/

void vMBMasterErrorCBReceiveData(uint8_t ucDestAddress,
const uint8_t * pudPDUData,
const uint8_t *pudPDUData,
uint16_t usPDULength)
{
xMBMasterPortEventPost(EV_MASTER_ERROR_RECEIVE_DATA);
Expand All @@ -259,7 +259,7 @@ void vMBMasterErrorCBReceiveData(uint8_t ucDestAddress,
*/

void vMBMasterErrorCBExecuteFunction(uint8_t ucDestAddress,
const uint8_t * pucPDUData,
const uint8_t *pucPDUData,
uint16_t usPDULength)
{
xMBMasterPortEventPost(EV_MASTER_ERROR_EXECUTE_FUNCTION);
Expand Down
6 changes: 5 additions & 1 deletion modbus/rtu/mbrtu_m.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ bool xMBMasterRTUReceiveFSM(void)

/* Always read the character. */

xMBMasterPortSerialGetByte((uint8_t *) & ucByte);
xMBMasterPortSerialGetByte((int8_t *) & ucByte);

switch (eRcvState)
{
Expand Down Expand Up @@ -397,6 +397,10 @@ bool xMBMasterRTUTransmitFSM(void)
}
}
break;

case STATE_M_TX_XFWR:
default:
break;
}

return xNeedPoll;
Expand Down

0 comments on commit 7c34942

Please sign in to comment.