📄 netrtu.h
字号:
#ifndef __NETRTU_H__
#define __NETRTU_H__
#define DEVICE_ERROR_BASE -100
#define DEVICE_NAME_ERROR DEVICE_ERROR_BASE - 1
#define DEVICE_HOST_ERROR DEVICE_ERROR_BASE - 2
#define DEVICE_PORT_ERROR DEVICE_ERROR_BASE - 3
#define DEVICE_CREATE_SOCK_ERROR DEVICE_ERROR_BASE - 4
#define DEVICE_CONNECT_ERROR DEVICE_ERROR_BASE - 5
#define DEVICE_CONNECT_TIMEOUT DEVICE_ERROR_BASE - 6
#define DEVICE_ID_ERROR DEVICE_ERROR_BASE - 7
#define DEVICE_READ_ERROR DEVICE_ERROR_BASE - 8
#define DEVICE_WRITE_ERROR DEVICE_ERROR_BASE - 9
#define ONE_DELAY 50000
#define DEVICE_TX_BUF_SIZE 16384
#define DEVICE_RX_BUF_SIZE 16384
#define MAX_RTUPORT_NO 9999
#define MIN_RTUPORT_NO 1111
#if defined(WIN32)
#include <afxsock.h>
#define EWOULDBLOCK WSAEWOULDBLOCK
#define EISCONN WSAEISCONN
#define EINPROGRESS WSAEINPROGRESS
#define KL_EINTR WSAEINTR
#define EALREADY WSAEALREADY
#elif defined(__unix)
#define KL_EINTR EINTR
#include <netinet/in.h>
#include <unistd.h>
#include <pthread.h>
#include <string.h>
#include <sys/time.h>
#define SOCKET int
#define SOCKET_ERROR -1
#if defined (__sun)
#include <sys/errno.h>
#endif
#endif
#if defined (WIN32)
#include <afxwin.h>
#include <afxsock.h>
#elif defined (__unix)
#include <signal.h>
#include <pthread.h>
#include <errno.h>
#include <fcntl.h>
#include <strings.h>
#include <unistd.h>
#include <sys/signal.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <unistd.h>
#endif
int ReadPort(int sock,char *buf,int size,int retry=1);
int WritePort(int sock,char *buf,int size,int retry=1);
int OpenPort(char *dev);
int ClosePort(int id);
int udp_open(char *dev);
int udp_read(int handle,char *buf,int len,char *dev=NULL);
int udp_read(int tdNo, int handle,char *buf,int len,char *dev=NULL);
int udp_write(int handle,char *buf,int len,char *dev);
int udp_write(int tdNo,int handle,char *buf,int len,char *dev);
int udp_close(int handle);
void delay_t(int n);
int get_last_error();
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -