tara0809 发表于 2014-10-16 15:31:34

Modbus RTU的WLAN传输

本人是菜鸟,想用PIC Explorer 16和 Wi-Fi PICtail MRF24WB0MA   做一个 Modbus RTU的WLAN传输。
Modbus RTU 通过TCP/ UDP是每个frame每个frame 的传输还是多个frame 包在一起呢!
十分感激!

niaojingxin 发表于 2014-10-16 15:48:05

modbus rtu有字节数限制,还是分包安全点吧。

tara0809 发表于 2014-10-16 16:07:18

niaojingxin 发表于 2014-10-16 15:48
modbus rtu有字节数限制,还是分包安全点吧。

之前在做的是分包的TCP, 用的是Microchip Applications Library软件,其中 UART2TCP-BridgeRingbuffer-Overflow, 原因是TCP的头有至少24Bytes。
分包做是不是用UDP 跟好呢?

tara0809 发表于 2014-10-17 14:42:52

{:cry:}{:cry:}{:cry:}{:cry:}

tara0809 发表于 2014-10-20 22:42:58

{:shocked:}{:shocked:}{:shocked:}

xrb3115 发表于 2014-10-20 23:15:19

用modbusTCP 不好吗?比你直接在 frame 中放个 RTU 要规范,而且转换也非常方便

bugkillbug 发表于 2014-10-20 23:23:36

直接用modbusTCP 更方便些
通用性也好

nongxiaoming 发表于 2014-10-20 23:48:05

modbus不是有TCP模式吗?直接用这个要好

tara0809 发表于 2014-10-21 16:17:50

xrb3115 发表于 2014-10-20 23:15
用modbusTCP 不好吗?比你直接在 frame 中放个 RTU 要规范,而且转换也非常方便 ...

硬件是给定了,用Modbus RTU控制的,现在要实现无线的控制!

tara0809 发表于 2014-10-21 16:18:17

bugkillbug 发表于 2014-10-20 23:23
直接用modbusTCP 更方便些
通用性也好

硬件是给定了,用Modbus RTU控制的,现在要实现无线的控制!

tara0809 发表于 2014-10-21 16:18:45

lovemp 发表于 2014-10-20 23:45
硬件都做好了么?

硬件是给定了,用Modbus RTU控制的,现在要实现无线的控制!

bossmaster_chan 发表于 2014-10-21 17:50:19

需求上,基本上就是用modbusTCP,用Modbus RTU去掉CRC16碼,開socket每个frame每个frame 的传输

tara0809 发表于 2014-10-21 21:52:46

bossmaster_chan 发表于 2014-10-21 17:50
需求上,基本上就是用modbusTCP,用Modbus RTU去掉CRC16碼,開socket每个frame每个frame 的传输 ...

用demo 软件移植,但是其中 UART2TCP-Bridge中 Ringbuffer-Overflow, 原因是TCP的头有至少24Bytes。如何解决呢

bossmaster_chan 发表于 2014-10-22 12:30:11

我看了一下 void UART2TCPBridgeTask(void) 函數中的程式,其中提到最大傳輸字數 wMaxPut的部份程式如下:
                        // Transmit pending data that has been placed into the UART RX FIFO (in the ISR)
                        //
                        wMaxPut = TCPIsPutReady(MySocket);        // Get TCP TX FIFO space
                        wMaxGet = RXHeadPtrShadow - RXTailPtrShadow;        // Get UART RX FIFO byte count
                        if(RXHeadPtrShadow < RXTailPtrShadow)
                                wMaxGet += sizeof(vUARTRXFIFO);
                        if(wMaxPut > wMaxGet)                                // Calculate the lesser of the two
                                wMaxPut = wMaxGet;
                        if(wMaxPut)                                                        // See if we can transfer anything
                        {
                                // Transfer the data over.Note that a two part put
                                // may be needed if the data spans the vUARTRXFIFO
                                // end to start address.
                                w = vUARTRXFIFO + sizeof(vUARTRXFIFO) - RXTailPtrShadow;
                                if(wMaxPut >= w)
                                {
                                        TCPPutArray(MySocket, RXTailPtrShadow, w);
                                        RXTailPtrShadow = vUARTRXFIFO;
                                        wMaxPut -= w;
                                }
                                TCPPutArray(MySocket, RXTailPtrShadow, wMaxPut);
                                RXTailPtrShadow += wMaxPut;

                                // No flush.The stack will automatically flush and do
                                // transmit coallescing to minimize the number of TCP
                                // packets that get sent.If you explicitly call TCPFlush()
                                // here, latency will go down, but so will max throughput
                                // and bandwidth efficiency.
                        }

                        //
                        // Transfer received TCP data into the UART TX FIFO for future transmission (in the ISR)
                        //
                        wMaxGet = TCPIsGetReady(MySocket);        // Get TCP RX FIFO byte count
                        wMaxPut = TXTailPtrShadow - TXHeadPtrShadow - 1;// Get UART TX FIFO free space
                        if(TXHeadPtrShadow >= TXTailPtrShadow)
                                wMaxPut += sizeof(vUARTTXFIFO);
                        if(wMaxPut > wMaxGet)                                // Calculate the lesser of the two
                                wMaxPut = wMaxGet;
                        if(wMaxPut)                                                        // See if we can transfer anything
                        {
                                // Transfer the data over.Note that a two part put
                                // may be needed if the data spans the vUARTTXFIFO
                                // end to start address.
                                w = vUARTTXFIFO + sizeof(vUARTTXFIFO) - TXHeadPtrShadow;
                                if(wMaxPut >= w)
                                {
                                        TCPGetArray(MySocket, TXHeadPtrShadow, w);
                                        TXHeadPtrShadow = vUARTTXFIFO;
                                        wMaxPut -= w;
                                }
                                TCPGetArray(MySocket, TXHeadPtrShadow, wMaxPut);
                                TXHeadPtrShadow += wMaxPut;
                        }
是否先從監測wMaxPut的數值範圍開始確認是否足夠,再進行下一步,另外TCP的头有至少24Bytes,是已經先扣掉了(從 WORD TCPIsPutReady(TCP_SOCKET hTCP) 函數中了解)

gtrajtr 发表于 2014-11-6 08:17:22

本帖最后由 gtrajtr 于 2014-11-6 08:18 编辑

tara0809 发表于 2014-10-21 16:18
硬件是给定了,用Modbus RTU控制的,现在要实现无线的控制!

用RTU走WLAN,超时不好判断的,通信很难兼顾速度与准确性,因为RTU没有确定的帧头帧尾,你要等足够的时间去确认是否收到完整的帧
WLAN每包数据的收发时间不是固定的


建议走MODBUS ASCII,一样的,大部应用、PLC都支持

tara0809 发表于 2014-11-7 18:30:51

gtrajtr 发表于 2014-11-6 08:17
用RTU走WLAN,超时不好判断的,通信很难兼顾速度与准确性,因为RTU没有确定的帧头帧尾,你要等足够的时间 ...

您好!硬件是给定的了!说的很有道理!现在我用的tcp 传输,接收端直接连接电脑串口数据没有问题,但是连接设备,还不行,貌似设备接收的太慢,导致溢出?如何解决呢。

tara0809 发表于 2014-11-12 17:16:47

bossmaster_chan 发表于 2014-10-22 12:30
我看了一下 void UART2TCPBridgeTask(void) 函數中的程式,其中提到最大傳輸字數 wMaxPut的部份程式如下:
       ...

请教 这个w 是指的什么

w = vUARTRXFIFO + sizeof(vUARTRXFIFO) - RXTailPtrShadow;
页: [1]
查看完整版本: Modbus RTU的WLAN传输