-
大小: 359KB文件类型: .rar金币: 2下载: 0 次发布日期: 2021-06-14
- 语言: C/C++
- 标签: Windows Modbus/TCP 服务器
资源简介
实现了一个基于Windows操作系统的Modbus/TCP服务器,采用C语言编写,可以方便初学者使用
代码片段和文件信息
/*
* FreeModbus Libary: Win32 Demo Application
* Copyright (C) 2006 Christian Walter
*
* 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 St Fifth Floor Boston MA 02110-1301 USA
*
* File: $Id: demo.cppv 1.2 2006/06/26 19:24:07 wolti Exp $
*/
#include “stdafx.h“
#pragma comment(lib“Ws2_32.lib“)
/* ----------------------- Modbus includes ----------------------------------*/
#include “mb.h“
/* ----------------------- Defines ------------------------------------------*/
#define PROG _T(“freemodbus“)
#define REG_INPUT_START 1000
//输入寄存器的起始地址
#define REG_INPUT_NREGS 4
//输入寄存器的数量
#define REG_HOLDING_START 2000
//保持寄存器的起始地址
#define REG_HOLDING_NREGS 130
//保持寄存器的数量
/* ----------------------- Static variables ---------------------------------*/
static USHORT usRegInputStart = REG_INPUT_START;
static USHORT usRegInputBuf[REG_INPUT_NREGS];
static USHORT usRegHoldingStart = REG_HOLDING_START;
static USHORT usRegHoldingBuf[REG_HOLDING_NREGS];
static HANDLE hPollThread;
static CRITICAL_SECTION hPollLock;
static enum ThreadState
{
STOPPED
RUNNING
SHUTDOWN
} ePollThreadState;
/* ----------------------- Static functions ---------------------------------*/
static BOOL bCreatePollingThread( void );
static enum ThreadState eGetPollingThreadState( void );
static void eSetPollingThreadState( enum ThreadState eNewState );
static DWORD WINAPI dwPollingThread( LPVOID lpParameter );
/* ----------------------- Start implementation -----------------------------*/
int
_tmain( int argc _TCHAR * argv[] )
{
int iExitCode;
TCHAR cCh;
BOOL bDoExit;
if( eMBTCPInit( MB_TCP_PORT_USE_DEFAULT ) != MB_ENOERR )
{
_ftprintf( stderr _T( “%s: can‘t initialize modbus stack!\r\n“ ) PROG );
iExitCode = EXIT_FAILURE;
}
else
{
/* Create synchronization primitives and set the current state
* of the thread to STOPPED.
*/
InitializeCriticalSection( &hPollLock );
eSetPollingThreadState( STOPPED );
/* CLI interface. */
_tprintf( _T( “Type ‘q‘ for quit or ‘h‘ for help!\r\n“ ) );
bDoExit = FALSE;
do
{
_tprintf( _T( “> “ ) );
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 19528 2006-03-14 14:41 ModbusWIN\Debug\demo.obj
文件 17661 2006-03-14 14:41 ModbusWIN\Debug\mb.obj
文件 12633 2006-03-14 14:41 ModbusWIN\Debug\mbfunccoils.obj
文件 1232 2006-03-14 14:41 ModbusWIN\Debug\mbfuncdiag.obj
文件 10440 2006-03-14 14:41 ModbusWIN\Debug\mbfuncdisc.obj
文件 13792 2006-03-14 14:41 ModbusWIN\Debug\mbfuncholding.obj
文件 10339 2006-03-14 14:41 ModbusWIN\Debug\mbfuncinput.obj
文件 11055 2006-03-14 14:41 ModbusWIN\Debug\mbfuncother.obj
文件 12479 2006-03-14 14:41 ModbusWIN\Debug\mbtcp.obj
文件 12260 2006-03-14 14:41 ModbusWIN\Debug\mbutils.obj
文件 11167 2006-03-14 14:41 ModbusWIN\Debug\portevent.obj
文件 18313 2006-03-14 14:41 ModbusWIN\Debug\portother.obj
文件 27070 2006-03-14 14:41 ModbusWIN\Debug\porttcp.obj
文件 107520 2006-03-14 14:41 ModbusWIN\Debug\vc60.idb
文件 69632 2006-03-14 14:41 ModbusWIN\Debug\vc60.pdb
文件 196676 2006-03-14 14:41 ModbusWIN\Debug\WIN32TCPModbus.exe
文件 347512 2006-03-14 14:41 ModbusWIN\Debug\WIN32TCPModbus.ilk
文件 157316 2006-03-14 14:41 ModbusWIN\Debug\WIN32TCPModbus.pch
文件 656384 2006-03-14 14:41 ModbusWIN\Debug\WIN32TCPModbus.pdb
文件 8895 2011-04-11 11:47 ModbusWIN\demo.cpp
文件 10775 2006-03-09 13:55 ModbusWIN\mb.c
文件 18361 2006-03-09 13:55 ModbusWIN\mb.h
文件 5047 2006-12-08 06:10 ModbusWIN\mbconfig.h
文件 3788 2006-12-08 06:10 ModbusWIN\mbfr
文件 3232 2011-04-11 10:55 ModbusWIN\mbfunc.h
文件 9907 2011-03-31 17:56 ModbusWIN\mbfunccoils.c
文件 1662 2006-12-08 06:10 ModbusWIN\mbfuncdiag.c
文件 4614 2007-02-19 07:48 ModbusWIN\mbfuncdisc.c
文件 12255 2011-03-31 17:56 ModbusWIN\mbfuncholding.c
文件 4838 2007-09-12 18:15 ModbusWIN\mbfuncinput.c
............此处省略22个文件信息
- 上一篇:无向图的邻接矩阵压缩存储.cpp
- 下一篇:数据库课程设计C语言
相关资源
- Qt5串口通信-windows
- 简易web服务器的设计与实现
- 新编Windows API参考大全.doc
- windows hook 框架(detours )
- 高性能服务器代码(50_06th_server_thre
- TCP/IP客户端和服务器端源代码,好用
- windows网络编程_文件传输
- Windows扩展命令程序(源码)
- LabwindowsCVI 串口编程及事例.docx
- Windows_API_函数大全 C/C++
- c++实现的文件上传服务器
- ffmpeg推流视频文件到rtmp服务器
- VC源码获取WINDOWS系统所有的用户密码
- c语言 Windows_程序设计_第五版
- windows下的ffmpeg、MFC制作的播放器
- 逐梦旅程 Windows游戏编程之从零开始
- 使用socket套接字发送udp数据包
- plist 文件文本二进制互转
- CAsyncSocket异步实现服务器与客户端
- Windows游戏编程大师技巧(CHM)
- Windows+C语言构建网络聊天室内含源程
- c++编写的smtp和pop3服务器实现
- c++ 帮助手册 chm
- Hoo WinTail 最新版本(v4.2.982)破解补丁
-
C++调用Windows MediaPla
yer实现的多媒体 - 局域网下,手机可以和电脑通过sock
- MFC下TCP服务器
- WIndow下使用QT C++开发生成带Logo的二维
- winTC(windows下的c语言编译器
- php-cpp项目移值到windows的vs2017解决方案
川公网安备 51152502000135号
评论
共有 条评论