-
大小: 201KB文件类型: .zip金币: 1下载: 0 次发布日期: 2021-06-01
- 语言: 其他
- 标签: MODBUS-RTU
资源简介
LINUX下的MODBUS-RTU驱动程序
代码片段和文件信息
/* modbus_rtu.c
By P.Costigan email: phil@pcscada.com.au http://pcscada.com.au
These library of functions are designed to enable a program send and
receive data from a device that communicates using the Modbus protocol.
Copyright (C) 2000 Philip Costigan P.C. SCADA link PTY. LTD.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not write to the Free Software
Foundation Inc. 675 Mass Ave Cambridge MA 02139 USA.
The functions included here have been derived from the
Modicon Modbus Protocol Reference Guide
which can be obtained from Schneider at www.schneiderautomation.com.
This code has its origins with
paul@pmcrae.freeserve.co.uk (http://www.pmcrae.freeserve.co.uk)
who wrote a small program to read 100 registers from a modbus slave.
I have used his code as a catalist to produce this more functional set
of functions. Thanks paul.
*/
#include /* File control definitions */
#include /* Standard input/output */
#include
#include
#include /* POSIX terminal control definitions */
#include /* Time structures for select() */
#include /* POSIX Symbolic Constants */
#include /* Error definitions */
#include “modbus_rtu.h“
//#define DEBUG /* uncomment to see the data sent and received */
int char_interval_timeout;
/*************************************************************************
modbus_query( packet length)
Function to add a checksum to the end of a packet.
Please note that the packet array must be at least 2 fields longer than
string_length.
**************************************************************************/
void modbus_query( unsigned char *packet size_t string_length )
{
int temp_crc;
/* declaration */
unsigned int crc(unsigned char buf[]int startint cnt);
temp_crc = crc( packet 0 string_length );
packet[ string_length++ ] = temp_crc >> 8;
packet[ string_length++ ] = temp_crc & 0x00FF;
packet[ string_length ] = 0;
}
/***********************************************************************
send_query( file_descriptor query_string query_length )
Function to send a query out to a modbus slave.
************************************************************************/
int send_query( int ttyfd unsigned char *query size_t string_length )
{
int write_stat;
#ifdef DEBUG
int i;
#endif
modbus_query(
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 158036 1999-04-16 22:37 wes3.wav
文件 287744 1999-05-02 20:47 vresume.exe
文件 10459 2000-02-22 12:50 read_reg.c
文件 23178 2007-05-10 21:33 modbus_tcp_c.htm
文件 6346 2007-05-10 21:40 modbus_rtu.h
文件 7173 2007-05-10 21:35 modbus_tcp.h
文件 7378 2007-05-10 21:34 modbus_tcp.htm
文件 22972 2007-05-10 21:36 modbus_tcp_c.c
文件 23095 2007-05-10 21:40 modbus_rtu.c
- 上一篇:线性代数导论第5版课后答案
- 下一篇:微信分享到朋友,朋友圈,QQ,QQ空间
评论
共有 条评论