From be18a1d0e7a571a6a8a728551512f5acb630cf38 Mon Sep 17 00:00:00 2001 From: armink Date: Tue, 11 Apr 2017 11:16:23 +0800 Subject: [PATCH] [Modbus] Update the code to the latest version. --- .../net/freemodbus/modbus/functions/mbfunccoils_m.c | 2 +- .../net/freemodbus/modbus/functions/mbfuncholding.c | 2 +- components/net/freemodbus/port/portserial.c | 7 +++---- components/net/freemodbus/port/portserial_m.c | 11 +++++------ components/net/freemodbus/port/porttimer.c | 2 +- components/net/freemodbus/port/porttimer_m.c | 2 +- 6 files changed, 12 insertions(+), 14 deletions(-) diff --git a/components/net/freemodbus/modbus/functions/mbfunccoils_m.c b/components/net/freemodbus/modbus/functions/mbfunccoils_m.c index f6bb51cdf6..93801de06f 100644 --- a/components/net/freemodbus/modbus/functions/mbfunccoils_m.c +++ b/components/net/freemodbus/modbus/functions/mbfunccoils_m.c @@ -196,7 +196,7 @@ eMBMasterReqWriteCoil( UCHAR ucSndAddr, USHORT usCoilAddr, USHORT usCoilData, LO UCHAR *ucMBFrame; eMBMasterReqErrCode eErrStatus = MB_MRE_NO_ERR; - if ( usCoilAddr > MB_MASTER_TOTAL_SLAVE_NUM ) eErrStatus = MB_MRE_ILL_ARG; + if ( ucSndAddr > MB_MASTER_TOTAL_SLAVE_NUM ) eErrStatus = MB_MRE_ILL_ARG; else if ( ( usCoilData != 0xFF00 ) && ( usCoilData != 0x0000 ) ) eErrStatus = MB_MRE_ILL_ARG; else if ( xMBMasterRunResTake( lTimeOut ) == FALSE ) eErrStatus = MB_MRE_MASTER_BUSY; else diff --git a/components/net/freemodbus/modbus/functions/mbfuncholding.c b/components/net/freemodbus/modbus/functions/mbfuncholding.c index e74a0624dc..7921302f96 100644 --- a/components/net/freemodbus/modbus/functions/mbfuncholding.c +++ b/components/net/freemodbus/modbus/functions/mbfuncholding.c @@ -183,7 +183,7 @@ eMBFuncReadHoldingRegister( UCHAR * pucFrame, USHORT * usLen ) usRegAddress++; usRegCount = ( USHORT )( pucFrame[MB_PDU_FUNC_READ_REGCNT_OFF] << 8 ); - usRegCount = ( USHORT )( pucFrame[MB_PDU_FUNC_READ_REGCNT_OFF + 1] ); + usRegCount |= ( USHORT )( pucFrame[MB_PDU_FUNC_READ_REGCNT_OFF + 1] ); /* Check if the number of registers to read is valid. If not * return Modbus illegal data value exception. diff --git a/components/net/freemodbus/port/portserial.c b/components/net/freemodbus/port/portserial.c index 317c7f4605..11173579ad 100644 --- a/components/net/freemodbus/port/portserial.c +++ b/components/net/freemodbus/port/portserial.c @@ -99,14 +99,14 @@ BOOL xMBPortSerialInit(UCHAR ucPORT, ULONG ulBaudRate, UCHAR ucDataBits, serial->ops->configure(serial, &(serial->config)); /* open serial device */ - if (!serial->parent.open(&serial->parent, - RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX )) { - serial->parent.rx_indicate = serial_rx_ind; + if (!rt_device_open(&serial->parent, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX)) { + rt_device_set_rx_indicate(&serial->parent, serial_rx_ind); } else { return FALSE; } /* software initialize */ + rt_event_init(&event_serial, "slave event", RT_IPC_FLAG_PRIO); rt_thread_init(&thread_serial_soft_trans_irq, "slave trans", serial_soft_trans_irq, @@ -115,7 +115,6 @@ BOOL xMBPortSerialInit(UCHAR ucPORT, ULONG ulBaudRate, UCHAR ucDataBits, sizeof(serial_soft_trans_irq_stack), 10, 5); rt_thread_startup(&thread_serial_soft_trans_irq); - rt_event_init(&event_serial, "slave event", RT_IPC_FLAG_PRIO); return TRUE; } diff --git a/components/net/freemodbus/port/portserial_m.c b/components/net/freemodbus/port/portserial_m.c index 8ec0d081f1..366dc79983 100644 --- a/components/net/freemodbus/port/portserial_m.c +++ b/components/net/freemodbus/port/portserial_m.c @@ -36,7 +36,7 @@ static rt_uint8_t serial_soft_trans_irq_stack[512]; static struct rt_thread thread_serial_soft_trans_irq; /* serial event */ static struct rt_event event_serial; -/* modbus slave serial device */ +/* modbus master serial device */ static rt_serial_t *serial; /* ----------------------- Defines ------------------------------------------*/ @@ -100,23 +100,22 @@ BOOL xMBMasterPortSerialInit(UCHAR ucPORT, ULONG ulBaudRate, UCHAR ucDataBits, serial->ops->configure(serial, &(serial->config)); /* open serial device */ - if (!serial->parent.open(&serial->parent, - RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX )) { - serial->parent.rx_indicate = serial_rx_ind; + if (!rt_device_open(&serial->parent, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX)) { + rt_device_set_rx_indicate(&serial->parent, serial_rx_ind); } else { return FALSE; } /* software initialize */ + rt_event_init(&event_serial, "master event", RT_IPC_FLAG_PRIO); rt_thread_init(&thread_serial_soft_trans_irq, - "slave trans", + "master trans", serial_soft_trans_irq, RT_NULL, serial_soft_trans_irq_stack, sizeof(serial_soft_trans_irq_stack), 10, 5); rt_thread_startup(&thread_serial_soft_trans_irq); - rt_event_init(&event_serial, "slave event", RT_IPC_FLAG_PRIO); return TRUE; } diff --git a/components/net/freemodbus/port/porttimer.c b/components/net/freemodbus/port/porttimer.c index 6f017d8759..8c51ad06d5 100644 --- a/components/net/freemodbus/port/porttimer.c +++ b/components/net/freemodbus/port/porttimer.c @@ -37,7 +37,7 @@ BOOL xMBPortTimersInit(USHORT usTim1Timerout50us) rt_timer_init(&timer, "slave timer", timer_timeout_ind, /* bind timeout callback function */ RT_NULL, - (50*usTim1Timerout50us)/(1000*1000/RT_TICK_PER_SECOND), + (50 * usTim1Timerout50us) / (1000 * 1000 / RT_TICK_PER_SECOND) + 1, RT_TIMER_FLAG_ONE_SHOT); /* one shot */ return TRUE; } diff --git a/components/net/freemodbus/port/porttimer_m.c b/components/net/freemodbus/port/porttimer_m.c index 00441bfd1c..ebf80004d8 100644 --- a/components/net/freemodbus/port/porttimer_m.c +++ b/components/net/freemodbus/port/porttimer_m.c @@ -46,7 +46,7 @@ BOOL xMBMasterPortTimersInit(USHORT usTimeOut50us) rt_timer_init(&timer, "master timer", timer_timeout_ind, /* bind timeout callback function */ RT_NULL, - (50 * usT35TimeOut50us) / (1000 * 1000 / RT_TICK_PER_SECOND), + (50 * usT35TimeOut50us) / (1000 * 1000 / RT_TICK_PER_SECOND) + 1, RT_TIMER_FLAG_ONE_SHOT); /* one shot */ return TRUE; -- GitLab