NC600串口调试工具


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
“);
err_exit();
}

if ((listen_fd = socket(AF_INET SOCK_STREAM 0)) < 0)
{
printf(“tcp socket error
“);
err_exit();
}

if (bind(listen_fd (struct sockaddr *)&local_ip sizeof(local_ip)) < 0)
{
printf(“tcp bind error
“);
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

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)