资源简介
Modbus是一种串行通信协议,是Modicon公司(现在的施耐德电气 Schneider Electric)于1979年为使用可编程逻辑控制器(PLC)通信而发表。Modbus已经成为工业领域通信协议的业界标准(De facto),并且现在是工业电子设备之间常用的连接方式。libmodbus库源文件
代码片段和文件信息
/*
* Copyright © 2001-2011 Stéphane Raimbault
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not write to the Free Software
* Foundation Inc. 51 Franklin Street Fifth Floor Boston MA 02110-1301 USA
*
*
* This library implements the Modbus protocol.
* http://libmodbus.org/
*/
#include
#include
#include
#include
#include
#include
#include
#include “modbus.h“
#include “modbus-private.h“
/* Internal use */
#define MSG_LENGTH_UNDEFINED -1
/* Exported version */
const unsigned int libmodbus_version_major = LIBMODBUS_VERSION_MAJOR;
const unsigned int libmodbus_version_minor = LIBMODBUS_VERSION_MINOR;
const unsigned int libmodbus_version_micro = LIBMODBUS_VERSION_MICRO;
/* Max between RTU and TCP max adu length (so TCP) */
#define MAX_MESSAGE_LENGTH 260
/* 3 steps are used to parse the query */
typedef enum {
_STEP_FUNCTION
_STEP_meta
_STEP_DATA
} _step_t;
const char *modbus_strerror(int errnum) {
switch (errnum) {
case EMBXILFUN:
return “Illegal function“;
case EMBXILADD:
return “Illegal data address“;
case EMBXILVAL:
return “Illegal data value“;
case EMBXSFAIL:
return “Slave device or server failure“;
case EMBXACK:
return “Acknowledge“;
case EMBXSBUSY:
return “Slave device or server is busy“;
case EMBXNACK:
return “Negative acknowledge“;
case EMBXMEMPAR:
return “Memory parity error“;
case EMBXGPATH:
return “Gateway path unavailable“;
case EMBXGTAR:
return “Target device failed to respond“;
case EMBBADCRC:
return “Invalid CRC“;
case EMBBADDATA:
return “Invalid data“;
case EMBBADEXC:
return “Invalid exception code“;
case EMBMDATA:
return “Too many data“;
default:
return strerror(errnum);
}
}
void _error_print(modbus_t *ctx const char *context)
{
if (ctx->debug) {
fprintf(stderr “ERROR %s“ modbus_strerror(errno));
if (context != NULL) {
fprintf(stderr “: %s\n“ context);
} else {
fprintf(stderr “\n“);
}
}
}
int _sleep_and_flush(modbus_t *ctx)
{
#ifdef _WIN32
/* usleep doesn‘t exist on Windows */
Sleep((ctx->response_timeout.tv_sec * 1000) +
(ctx->response_timeout.tv_usec / 10
相关资源
- Modbus通讯TCP/IP实施指南
- 基于ATMega16的freemodbus主站程序移植
- 威纶通TK6070IP触摸屏和51通信的MODBUS代
- FX2N-PLC -MODBUS 通信手册
- MODBUSRTUS7200SMART工程文件.rar
- stm32+modbus项目
- 串口工具带modebus crc校验
- 单片机上实现的modbus_tcp通信
- ModBus RTU-通讯测试软件 ModBus RTU调试助
- labview modbus rtu 主站通用程序
- Modbus TCP通讯程序
- ModbusTCPMQTT
- modbus从站模拟器.zip
- modsan32测试工具
- ModbusTCP 客户端
- ModBus通信协议英文
- MODBUS扫描工具 自研
- ZLG/MODBUS
- modbus通信协议例程
- modbus测试软件
- 51单片机实现Modbus从机程序
- TwinCAT PLC地址与Modbus地址对应关系
- 在PCS7中如何实现CP341做从站进行MODB
- arm9 + linux modbus tcp 运行文件,可用于
- 三维力控与MODBUS仪表通讯说明及例程
- ModbusTCP_Slave程序
- labview与台达plc通讯Modbus RTU
- AB-Micro800系列MODBUS-RTU轮询程序
- 通过485Modbus读取DS18B20温度和控制LED(
- ModbusTCP测试程序源码
评论
共有 条评论