资源简介
linux tcpmodbus服务端 输入寄存器(0x04)离散输入寄存器(0x02)保持寄存器(0x03(读) 0x06(单个写) 0x10(多个写))
代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include “linux_thread.inc“
#define MAX_MODBUS_REVLEN 4096
#define MAX_CLIENT_CNT 10
#define STATUS_ON 1
#define STATUS_OFF 0
char modbus_sockt_state[MAX_CLIENT_CNT];
unsigned int modbus_sockt_timer[MAX_CLIENT_CNT];
int modbus_client_sockptr[MAX_CLIENT_CNT];
struct sockaddr_in Server_Addr Client_addr;
int modbus_sockptr;
unsigned short int test_keep[10]={12345678910};
void UINT16ToBigEndien(unsigned short int u16_data unsigned char *dat_out)
{
dat_out[0] = u16_data >> 8;
dat_out[1] = u16_data;
}
unsigned char GetStatusInput(unsigned short addrunsigned char* err)//添加自己点表 离散输入寄存器0x02
{
unsigned char ret;
ret = 0;
*err=0;
if ((addr >=0)&&(addr<10))
{
ret = 1;
}
else
{
*err=2;
}
return (ret);
}
unsigned short GetKeepInput(unsigned short addrunsigned char *err)//添加自己点表 读保持寄存器0x03
{
unsigned short ret;
unsigned char *uc_point;
unsigned char *uc_point2;
*err=0;
ret = 0;
if((addr>=0)&&(addr<10))
{
ret=test_keep[addr];
}
else
{
*err=2;
}
return (ret);
}
unsigned short GetModbusInput(unsigned short addrunsigned char *err)//添加自己点表 输入寄存器0x04
{
unsigned short ret;
*err=0;
if((addr>=0)&&(addr<10))
{
ret=addr+1;
}
else
{
*err=2;
}
return (ret);
}
int SetModbus(unsigned short addr unsigned int datasetunsigned char *err)//添加自己点表 设置保持寄存器0x06 或0x10
{
unsigned char *uc_point;
unsigned char *uc_point2;
*err=0;
if((addr>=0)&&(addr<10))
{
if(dataset<255)
test_keep[addr]=dataset;
else
*err=3;
}
else
{
*err=2;
}
return 1;
}
int AnalysModbus(unsigned char *datain unsigned short len unsigned char *dataout)
{
unsigned short event;
unsigned short protocol;
unsigned short length;
unsigned char *datap;
unsigned char *datapout;
unsigned char addr;
unsigned char cmd;
unsigned short startaddr;
unsigned short regcnt;
unsigned short regaddr;
unsigned short setvalue;
unsigned char setlen;
unsigned short uitemp;
unsigned char *ctp;
unsigned char result;
unsigned short bat_no;
time_t timep_save;
unsigned char time_buf_save[6]err;
char tempc_buf[50];
int grp_no;
int index;
int i j;
index = 0;
while (index < len - 6)
{
datap = (unsigned char *)(&datain[index]);
event = datap[0] * 0x100 + datap[1];
protocol = datap[2] * 0x100 + datap[3];
length = datap[4] * 0x100 + datap[5];
if (protocol == 0 && length >= 2)
{
dataout[0] = event >> 8;
dataout[1] = event;
dataout[2] = protocol >> 8;
dataout[3] = protocol;
dataout[4] = 0;//later
dataout[5] = 0;//later
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 883 2018-07-25 09:13 Makefile.server
文件 12762 2018-07-25 09:12 tcpmodbusserver
文件 12402 2018-07-25 09:16 tcpmodbusserver.c
文件 2487 2018-07-25 09:30 linux_thread.inc
----------- --------- ---------- ----- ----
28534 4
相关资源
- Cygwin1.5.24-2
- arm-linux-gcc-4.3.2交叉编译
- Linux课程设计 实现qq通信
- cocos2dx3.x使用socket创建服务端和客户端
- license intel parallel studio xe 2015 for linu
- 伪终端实现GSM
- Linux系统CentOS-6.2、6.5、7.0
- Linux破解wifi密码(完全教程+工具)
- ARM LINUX 进程间通讯 共享内存
- linux下weblogic的安装与配置详解
- UNIX环境高级编程 第三版 随书代码
- socket编程_windows_linux_数据传输
- 自己编写ping程序
- Linux下利用TCPsocket传输图片
- Linux下串口数据发送程序
- 静态路由的实现linux
- BitBake User Manual .pdf
-
Openem
bedded User Manual .pdf - 电量检测芯片max17055linux驱动
- stm32在ubuntu linux下开发测试源文件
- IOCP 客户端和服务端
- 操作系统原理课程设计报告
- linux 下weblogic部署web项目
- qt libusb U盘通信
- linux mdio 读写phy 寄存器工具
- 简单ping程序的实现
- OV5648摄像头linux驱动代码
- Linux C聊天室源码
- windows系统运行的scp,实现从Linux系统
- 华为支付SDK服务端回调接口V1.0.1
评论
共有 条评论