资源简介
NC600串口调试工具,NC600:tcpserver,tcpclient指令,源代码等
代码片段和文件信息
/*
* this is a sample when ntd acts as tcp client
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include “nser.h“
void set_param(int fd);
void set_report(int fd);
void do_communicate(int fd);
void send_time_break(fd);
void send_close(fd);
void err_exit();
#define LOCAL_IPADDR “192.168.0.91“ // sckcfg N -rip LOCAL_IPADDR
#define LOCAL_PORT 5000 // sckcfg N -rt LOCAL_PORT
int main(int argc char ** argv)
{
int socket_fd listen_fd;
struct sockaddr_in local_ip;
int nbio = 1;
WSADATA wsadata;
WSAStartup(0x101 &wsadata);
memset(&local_ip 0 sizeof(local_ip));
local_ip.sin_family = AF_INET;
local_ip.sin_port = htons((unsigned short)LOCAL_PORT);
local_ip.sin_addr.s_addr = inet_addr(LOCAL_IPADDR);
if (local_ip.sin_addr.s_addr == INADDR_NONE)
{
printf(“inet_addr error\n“);
err_exit();
}
if ((listen_fd = socket(AF_INET SOCK_STREAM 0)) < 0)
{
printf(“tcp socket error\n“);
err_exit();
}
if (bind(listen_fd (struct sockaddr *)&local_ip sizeof(local_ip)) < 0)
{
printf(“tcp bind error\n“);
err_exit();
}
listen(listen_fd 1);
socket_fd = accept(listen_fd NULL NULL);
nbio = 1;
ioctlsocket(socket_fdFIONBIO&nbio);
set_param(socket_fd);
set_report(socket_fd);
do_communicate(socket_fd);
WSACleanup();
return 0;
}
void set_param(int fd)
{
unsigned char mask;
unsigned char mode;
unsigned char flow;
unsigned char ctrl;
unsigned long baud;
unsigned char buf[32];
mode = CS8 | STOP1 | PAR_NONE; // 8 bits data 1 bit stop no parity
flow = FLOW_NONE; // no flowctrl
ctrl = C_DTR | C_RTS; // DTR on RTS on
baud = 9600; // baud is 9600bps
mask = MASK_MODE | MASK_FLOW | MASK_CTRL | MASK_BAUD;
buf[0] = 0xff;
buf[1] = SET_SERIAL;
buf[2] = mask;
buf[3] = mode;
buf[4] = flow;
buf[5] = ctrl;
buf[6] = baud >> 24;
buf[7] = baud >> 16;
buf[8] = baud >> 8;
buf[9] = baud;
send(fd (char *)buf 10 0);
}
void send_break(int fd int set_break)
{
unsigned char mask;
unsigned char mode;
unsigned char flow;
unsigned char ctrl;
unsigned long baud;
unsigned char buf[10];
if (set_break)
mode = SET_BREAK; // 8 bits data 1 bit stop no parity
else
mode = CLEAR_BREAK;
flow = FLOW_NONE; // no flowctrl
ctrl = C_DTR | C_RTS; // DTR on RTS on
baud = 9600; // baud is 9600bps
mask = MASK_BRK;
buf[0] = 0xff;
buf[1] = SET_SERIAL;
buf[2] = mask;
buf[3] = mode;
buf[4] = flow;
buf[5] = ctrl;
buf[6] = baud >> 24;
buf[7] = baud >> 16;
buf[8] = baud >> 8;
buf[9] = baud;
send(fd (char *)buf 10 0);
}
void set_report(int fd)
{
unsigned char type;
unsigned char buf[3];
type = REPORT_IF_CHANGED; // after do this ntd will report status w
- 上一篇:STM32F4+USBHID双向通讯
- 下一篇:Qt学生成绩管理系统源码可运行
相关资源
- VSPD及串口调试工具
- 基于Qt5的串口调试助手
-
yeeli
nk 串口调试工具 - 串口调试助手V2.2源代码
- QT4.6实践编写串口调试助手原创全源码
- 串口调试工具,共4个XCOM V2.0 原子+C
- NB-IoT串口调试工具
- 简洁好用的串口调试助手
- 串口调试助手VC源码
- 串口调试器
- 串口调试助手十六进制数据转成十进
- 串口调试助手+TCP/IP通信+源码
- 串口调试工具,串口设置包括 端口,
- 虚拟串口调试工具
- Qt从零开始制作串口调试助手_各步骤
- stm32 ADC采集DAC电压并显示在串口调试
- 串口调试助手源代码 VS+Qt
- stm32 sd卡sdio模式接口读写带串口调试
- 能判断奇偶校验的串口调试助手
- 51单片机与PC串口通信的protues仿真的工
- 串口调试助手 vc 源代码
- 串口调试助手完整版
- QT串口调试工具用于stm32串口通信
- PC蓝牙串口调试助手
- CoolTermMac Mac下好用的串口调试工具
- RS485串口调试案例带CRC校检
- macos下的串口调试工具
- Qt 串口助手增强版带示波器曲线源代
- 串口调试助手源码 串口调试助手源码
- vs2015搭载Qt Creator 4.5.1写的一个串口调
评论
共有 条评论