zoukankan      html  css  js  c++  java
  • Freemodbus 1.5

    源:http://blog.sina.com.cn/s/blog_4935209001012eax.html

    文档位置:http://www.freemodbus.org/api/index.html

     
    一、介绍
    Freemodbus是modbus协议在嵌入式处理器上的实现。包括AVR,PIC,WIN32等等平台。它是开放性源代码,可用于商业目的。
    它实现了Modbus RTU/ASCII、TCP三种传输方式,当前版本是1.5,支持以下功能:
    • 读输入寄存器 (0x04)
    • 读保持寄存器 (0x03)
    • 写单个寄存器 (0x06)
    • 写多个寄存器 (0x10)
    • 读/写多个寄存器 (0x17)
    • 读取线圈状态 (0x01)
    • 写单个线圈 (0x05)
    • 写多个线圈 (0x0F)
    • 读输入状态 (0x02)
    • 报告从机标识 (0x11)
    本实现基于最新的标准并且与标准完全兼容。接收和传输Modbus RTU/ASCII数据帧是通过一个由硬件提取层的调用来驱动状态机实现的。这就使得协议非常容易移植到其他的平台之上。当接收一个完整的数据帧后,该数据帧被传入Modbus应用层,数据帧的内容在该层内得到解析。为方便地增加新的Modbus功能,Freemodbus在应用层提供了钩子函数Hooks。
     
    如果用到了Modbus TCP协议,那么当准备处理一个新数据帧的时候,移植层就必须首先向协议层发送一个事件标志。然后,协议栈调用一个返回值为接收到的Modbus TCP数据帧的函数,并且开始处理这个数据帧。如果数据有效,则响应的Modbus反馈帧将提供给移植层生成反馈帧。最后,该反馈帧被发送到客户端。
     
    二、实现FreeModbus协议所需要的软/硬件需求
    Modbus协议对硬件的需求非常少——基本上任何具有串行接口,并且有一些能够容纳modbus数据帧的RAM的微控制器都足够了。
    • 一个异步串行接口,能够支持接收缓冲区满和发送缓存区空中断。
    • 一个能够产生RTU传输所需要的t3.5 字符超时定时器的时钟。

    对于软件部分,仅仅需要一个简单的事件队列。 The STR71X/FreeRTOS 移植使用 FreeRTOS 队列作为事件队列来减少 Modbus 任务所需要的时间。小点的微控制器往往不允许使用操作系统,在那种情况下,可以使用一个全局变量来实现该事件队列(The Atmel AVR 移植使用这种方式实现)。

    实际的存储器需求决定于所使用的 Modbus 模块的多少。下表列出了所支持的功能编译后所需要的存储器。 ARM 项数值是使用 GNUARM 编译器 3.4.4 使用 -O1 选项得到的。 AVR项数值是使用 WinAVR 编译器 3.4.5 使用 -Os 选项编译得到的。

    Module ARM Code ARM RAM (static) AVR Code AVR RAM (static)
    Modbus RTU (Required) 1132Byte 272Byte 1456Byte 266Byte
    Modbus ASCII (Optional) 1612Byte 28Byte 1222Byte 16Byte
    Modbus Functions [1] 1180Byte 34Byte 1602Byte 34Byte
    Modbus Core (Required) 924Byte 180Byte 608Byte 75Byte
    Porting Layer (Required [2]) 1756Byte 16Byte 704Byte 7Byte
    Totals 7304Byte 530Byte 5592Byte 398Byte
    [1]: 实际大小决定于可支持的Modbus功能码的多少。功能码可以在头文件 mbconfig.h中进行配置。
    [2]: 决定于硬件。
     
    已完成的移植:
    Cortex M3 devices:
    • Atmel AT91SAM3S.
    ARM devices:
    • STR71X with FreeRTOS/GCC. See STR71X/simple2.c for an example.
    • STR71TCP with FreeRTOS/lwIP/GCC. This port includes FreeRTOS, lwIP and a fully working PPP stack. The lwIP, PPP and FreeRTOS part is generic and therefore can be used for other ports ( or other projects ).
    • LPC214X with Keil. See LPC214X/demo.c for an example. This port uses the Keil ARM Compiler 2.41.
    • AT91SAM7X with FreeRTOS/Rowley. See AT91SAM7X_ROWLEY/demo.c for an example.
    AVR devices:
    • ATMega8/16/32/128/168/169 with WinAVR. See AVR/demo.c for an example.
    Coldfire devices:
    • MCF5235 with GCC. See MCF5235/demo.c for an example.
    • MCF5235 with CodeWarrior and FreeRTOS port for ColdFire. See MCF5235CW/demo.c for an example.
    • MCF5235/TCP with GCC. This port features FreeRTOS and the lwIP stack. The lwIP part is generic and therefore it should be used as a basis for other lwIP ports.
    MSP430 devices
    • MSP430F169 with Rowley Crossworks. See MSP430/demo.c for an example.
    • MSP430F169 with GCC. See MSP430/demo.c for an example.
    Z8Encore devices
    • Z8F6422 and Z8F1622 port. See Z8ENCORE/demo.c for an example. The port uses ZDS II - Z8 Encore! 4.10.1 as development environment.
    Win32:
    • A Win32 Modbus RTU/ASCII Port.
    • A Win32 Modbus/TCP Port.
    Linux:
    • A Linux (uCLinux or other distributions) Modbus RTU/ASCII Port.
  • 相关阅读:
    mysql数据库汉字首字母简拼全拼
    window.showModalDialog刷新父窗口和本窗口的方法及注意
    c#.net语句e.Row.RowType == DataControlRowType.DataRow是什么含义?
    SQL 拿到一天内的数据
    在线脚本编辑器
    输入正确的邮箱地址
    jquery中的$(document).ready()方法和window.onload方法区别
    转载从XML文件中读取数据绑定到DropDownList
    GridView中DropDownList联动
    For 循环 和Foreach 的区别
  • 原文地址:https://www.cnblogs.com/LittleTiger/p/4373962.html
Copyright © 2011-2022 走看看