/**
* @internal
* @file modpoll.cpp
*
* @if NOTICE
*
* $Id: modpoll.cpp,v 1.19 2006/10/20 05:18:40 henrik Exp $
*
* Copyright (c) 2002-2006 FOCUS Software Engineering Pty Ltd, Australia.
* All rights reserved. <www.focus-sw.com>
*
* USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS OF A
* SEPARATE LICENSE STATEMENT AND LIMITED WARRANTY.
*
* IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD FOCUS SOFTWARE ENGINEERING,
* ITS RELATED COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY
* CLAIMS OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR
* DISTRIBUTION OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES
* ARISING OUT OF OR RESULTING FROM THE USE, MODIFICATION, OR DISTRIBUTION
* OF PROGRAMS OR FILES CREATED FROM, BASED ON, AND/OR DERIVED FROM THIS
* SOURCE CODE FILE.
*
* @endif
*/
// Platform header
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#ifdef _WIN32
# include "getopt.h"
#else
# include <unistd.h>
#endif
// Include FieldTalk package header
#include "MbusRtuMasterProtocol.hpp"
#include "MbusAsciiMasterProtocol.hpp"
#include "MbusTcpMasterProtocol.hpp"
#include "MbusRtuOverTcpMasterProtocol.hpp"
/*****************************************************************************
* String constants
*****************************************************************************/
const char versionStr[]= "2.4.0";
const char progName[] = "modpoll";
const char bannerStr[] =
"\n"
"%s - FieldTalk(tm) Modbus(R) Polling Utility\n"
"Copyright (c) 2002-2006 FOCUS Software Engineering Pty Ltd\n"
"Visit http://www.modbusdriver.com for Modbus libraries and tools.\n"
"\n";
const char usageStr[] =
"%s [options] serialport|host \n"
"Arguments: \n"
"serialport Serial port when using Modbus ASCII or Modbus RTU protocol \n"
" COM1, COM2 ... on Windows \n"
" /dev/ttyS0, /dev/ttyS1 ... on Linux \n"
" /dev/ser1, /dev/ser2 ... on QNX \n"
"host Host name or dotted ip address when using MODBUS/TCP protocol \n"
"General options: \n"
"-m ascii Modbus ASCII protocol\n"
"-m rtu Modbus RTU protocol (default)\n"
"-m tcp MODBUS/TCP protocol\n"
"-m enc Encapsulated Modbus RTU over TCP\n"
"-a # Slave address (1-255 for RTU/ASCII, 0-255 for TCP, 1 is default)\n"
"-r # Start reference (1-65536, 100 is default)\n"
"-c # Number of values to poll (1-100, 1 is default)\n"
"-t 0 Discrete output (coil) data type\n"
"-t 1 Discrete input data type\n"
"-t 3 16-bit input register data type\n"
"-t 3:hex 16-bit input register data type with hex display\n"
"-t 3:int 32-bit integer data type in input register table\n"
"-t 3:mod 32-bit module 10000 data type in input register table\n"
"-t 3:float 32-bit float data type in input register table\n"
"-t 4 16-bit output (holding) register data type (default)\n"
"-t 4:hex 16-bit output (holding) register data type with hex display\n"
"-t 4:int 32-bit integer data type in output (holding) register table\n"
"-t 4:mod 32-bit module 10000 type in output (holding) register table\n"
"-t 4:float 32-bit float data type in output (holding) register table\n"
"-i Slave operates on big-endian 32-bit integers\n"
"-f Slave operates on big-endian 32-bit floats\n"
"-1 Poll only once, otherwise poll every second\n"
"Options for MODBUS/TCP:\n"
"-p # TCP port number (502 is default)\n"
"Options for Modbus ASCII and Modbus RTU:\n"
"-b # Baudrate (e.g. 9600, 19200, ...) (9600 is default)\n"
"-d # Databits (7 or 8 for ASCII protocol, 8 for RTU)\n"
"-s # Stopbits (1 or 2, 1 is default)\n"
"-p none No parity\n"
"-p even Even parity (default)\n"
"-p odd Odd parity\n"
"-4 # RS4-85 mode, RTS on while transmitting and another # ms after\n"
"";
/*****************************************************************************
* Enums
*****************************************************************************/
enum
{
RTU, ///< Modbus RTU protocol
ASCII, ///< Modbus ASCII protocol
TCP, ///< MODBUS/TCP protocol
RTUOVERTCP ///< Encapsulated RTU over TCP
};
enum
{
T0_BIT, ///< bit data types, discrete output table
T1_BIT, ///< bit data types, discrete input table
T3_REG16, ///< 16-bit register (short) types, input table
T3_HEX16, ///< 16-bit register types with hex display, input table
T3_INT32, ///< 32-bit integer types (2 16-bit registers), input table
T3_MOD10000, ///< 32-bit modulo 10000 types, input table
T3_FLOAT32, ///< Float types (2 16-bit registers), input table
T4_REG16, ///< 16-bit register (short) types, output table
T4_HEX16, ///< 16-bit register types with hex display, output table
T4_INT32, ///< 32-bit integer types (2 16-bit registers), output table
T4_MOD10000, ///< 32-bit modulo 10000 types, output table
T4_FLOAT32 ///< Float types (2 16-bit registers), output table
};
/*****************************************************************************
* Gobal configuration data
*****************************************************************************/
int slaveAddr = 1;
int ref = 100;
int refCnt = 1;
int pollCnt = -1;
long baudRate = 9600;
int dataBits = 8;
int stopBits = 1;
int parity = MbusSerialMasterProtocol::SER_PARITY_EVEN;
int protocol = RTU;
int dataType = T4_REG16;
int swapInts = 0;
int swapFloats = 0;
char *portName = NULL;
int port = 502;
int rs485Mode = 0;
/*****************************************************************************
* Protocol and data pointers
*****************************************************************************/
MbusMasterFunctions *mbusPtr = NULL;
void *dataPtr = NULL;
/*****************************************************************************
* Function implementation
*****************************************************************************/
/**
* Prints a usage message on stdout and exits
*/
void printUsage()
{
printf("Usage: ");
printf(usageStr, progName);
exit(EXIT_SUCCESS);
}
/**
* Prints version info on stdout
*/
void printVersion()
{
printf(bannerStr, progName);
printf("Version: %s using FieldTalk library version %s\n",
versionStr, MbusMasterFunctions::getPackageVersion());
}
/**
* Prints the current configuration on stdout
*/
void printConfig()
{
printf(bannerStr, progName);
printf("Protocol configuration: ");
switch (protocol)
{
case RTU:
printf("Modbus RTU\n");
break;
case ASCII:
printf("Modbus ASCII\n");
break;
case TCP:
printf("MODBUS/TCP\n");
break;
case RTUOVERTCP:
printf("Encapsulated RTU over TCP\n");
break;
default:
printf("unknown\n");
break;
}
printf("Slave configuration...: ");
printf("Address/Id = %d, ", slaveAddr);
printf("start reference = %d, ", ref);
printf("count = %d\n", refCnt);
printf("Communication.........: ");
if ((protocol == TCP) || (protocol == RTUOVERTCP))
printf("%s, port %d\n", portName, port);
else
{
printf("%s, %ld, %d, %d", portName,baudRate, dataBits, stopBits);
switch (parity)
{
case MbusSerialMasterProtocol::SER_PARITY_NONE:
printf("none\n");
break;
case MbusSerialMasterProtocol::SER_PARITY_EVEN:
printf("even\n");
break;
case MbusSerialMasterProtocol::SER_PARITY_ODD:
printf("odd\n");
break;
default:
printf("unknown\n");
break;
}
}
printf("Data type...........
没有合适的资源?快使用搜索试试~ 我知道了~
modpoll.2.4.0.zip
共7个文件
modpoll:3个
cpp:1个
exe:1个
5星 · 超过95%的资源 需积分: 9 39 下载量 147 浏览量
2008-07-28
23:10:48
上传
评论
收藏 118KB ZIP 举报
温馨提示
MODBUS 调试工具
资源推荐
资源详情
资源评论
收起资源包目录
modpoll.2.4.0.zip (7个子文件)
solaris
sparc
modpoll 70KB
win32
modpoll.exe 80KB
qnx6
modpoll 56KB
LICENSE 5KB
README 5KB
linux
modpoll 59KB
modpoll.cpp 24KB
共 7 条
- 1
资源评论
- 28號2014-11-01简单的调试小工具
hhhcc
- 粉丝: 2
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功