使用UDP协议与韩国OACIS压机通讯
最近一个项目需要发送SN给OACIS,
研究了一下OACIS文档,


从文档中可以看出,传输协议只能使用UDP,切传输命令为>SN1; + SN + ; + LF
LF的定义在Linux和Unix中换行符,但是在Windows中换行为CRLF,MAC中又为CR
所以这里只能用ASCII,LF的ASCII为10
所以程序如下:
public class OACISHelper
{
public string[] strArrGV;
public string strCN;
public string strDateTime;
public string strFM; public string strOACISIPAdd;
public int iOACISPort;
public string strSN; public bool setSN(string val_strSN)
{
char ch = Convert.ToChar();
string str = string.Concat(new object[] { ">SN1;", val_strSN, ";", ch });
string str2 = this.Request(str);
return ((str2.Length > ) && (str2.Substring(, ) == "<SN1"));
} private string Request(string val_strRequest)
{
string str = this.RequestOneTime(val_strRequest);
if ((str.Substring(, ) != "#") || (str.Substring(str.Length - ) != "$"))
{
str = this.RequestOneTime(val_strRequest);
if ((str.Substring(, ) == "#") && (str.Substring(str.Length - ) == "$"))
{
return str;
}
str = this.RequestOneTime(val_strRequest);
if ((str.Substring(, ) == "#") && (str.Substring(str.Length - ) == "$"))
{
return str;
}
str = this.RequestOneTime(val_strRequest);
if ((str.Substring(, ) == "#") && (str.Substring(str.Length - ) == "$"))
{
return str;
}
str = this.RequestOneTime(val_strRequest);
if ((str.Substring(, ) == "#") && (str.Substring(str.Length - ) == "$"))
{
return str;
}
}
return str;
} private string RequestOneTime(string val_strRequest)
{
byte[] bytes = null;
try
{
byte[] dgram = Encoding.Default.GetBytes(val_strRequest);
UdpClient client = new UdpClient();
IPEndPoint remoteEP = new IPEndPoint(IPAddress.Any, );
client.Client.ReceiveTimeout = 0x3e8;
client.Send(dgram, dgram.Length, this.strOACISIPAdd, this.iOACISPort);
bytes = client.Receive(ref remoteEP);
return Encoding.Default.GetString(bytes);
}
catch (Exception exception)
{
string str2 = "";
if (bytes != null)
{
for (int i = ; i < bytes.Length; i++)
{
str2 = str2 + " / " + i.ToString() + "-" + bytes[i].ToString();
}
}
return exception.Message;
}
} public bool readResults()
{
string str = this.Request("@UG;LN;004;$");
string[] strArray = str.Split(new char[] { ';' });
if (((strArray[] == "#UG") && (strArray[strArray.Length - ] == "$")) && (strArray.Length == 0x86))
{
this.strCN = strArray[];
this.strFM = strArray[];
this.strSN = strArray[strArray.Length - ];
this.strDateTime = strArray[];
for (int i = ; i < ; i++)
{
this.strArrGV[i] = strArray[i + ];
}
return true;
}
this.strSN = str;
return false;
}
}
使用UDP协议与韩国OACIS压机通讯的更多相关文章
- 闲来无事,写个基于UDP协议的Socket通讯Demo
项目一期已经做完,二期需求还没定稿,所以最近比较闲. 上一篇写的是TCP协议,今天写一下UDP协议.TCP是有连接协议,所以发送和接收消息前客户端和服务端需要建立连接:UDP是无连接协议,所以发送消息 ...
- QQ--基于TCP/UDP协议的通讯原理
QQ是一个基于TCP/UDP协议的通讯软件 发送消息的时候是UDP打洞,登陆的时候使用HTTP~因为登陆服务器其实就是一个HTTP服 务器,只不过不是常用的那些,那个服务器是腾讯自行开发的! 一 ...
- Shell 脚本实现TCP/UDP协议通讯
Shell 脚本实现TCP/UDP协议通讯 http://www.cnblogs.com/occult/archive/2012/12/25/2832183.html
- 数据通讯与网络 第五版第24章 传输层协议-UDP协议部分要点
24.1 介绍 本章节主要集中于传输层协议的解读,图24.1展示TCP.UDP.SCTP在TCP\IP协议栈的位置 24.1.1 服务(Service) 每个协议都提供不同的服务,所以应该合理正确的使 ...
- TwinCAT 3中基于UDP协议通讯的C++实现
因为项目需要,学习了TwinCAT3中使用UDP协议进行通讯的基本知识.这个做个简单的笔记,方便以后查询. 1 概述 倍福为了实现从实时环境中直接访问网卡(network cards)专门提供了一个函 ...
- 采用UDP协议实现PIC18F97J60 ethernet bootloader
了解更多关于bootloader 的C语言实现,请加我QQ: 1273623966 (验证信息请填 bootloader),欢迎咨询或定制bootloader(在线升级程序). TCP/IP Stac ...
- 网络编程——基于TCP协议的Socket编程,基于UDP协议的Socket编程
Socket编程 目前较为流行的网络编程模型是客户机/服务器通信模式 客户进程向服务器进程发出要求某种服务的请求,服务器进程响应该请求.如图所示,通常,一个服务器进程会同时为多个客户端进程服务,图中服 ...
- [深入浅出WP8.1(Runtime)]Socket编程之UDP协议
13.3 Socket编程之UDP协议 UDP协议和TCP协议都是Socket编程的协议,但是与TCP协议不同,UDP协议并不提供超时重传,出错重传等功能,也就是说其是不可靠的协议.UDP适用于一次只 ...
- 【转】关于TCP和UDP协议消息保护边界的介绍
在 socket网络程序中,TCP和UDP分别是面向连接和非面向连接的.因此TCP的socket编程,收发两端(客户端和服务器端)都要有一一成对的 socket,因此,发送端为了将多个发往接收端的包, ...
随机推荐
- python 核心编程课后练习(chapter 6)
6-1 #6-1 #help(string) import string str = "helloworld" substr = "h1e" if string ...
- 《Unix/Linux网络日志分析与流量监控》获2015年度最受读者喜爱的IT图书奖
<Unix/Linux网络日志分析与流量监控>获2015年度最受读者喜爱的IT图书奖.刊登在<中华读书报>( 2015年01月28日 19 版) 我的2015年新作刊登在< ...
- Xenko基础API笔记2-Enum Keys按键
Name Description A The 'a' key. Add The 'add' key. Apps The 'apps' key. Attn The 'attn' key. B The ...
- cacti应用
cacti被很多IDC/CDN提供商用来进行带宽计算使用:带宽的95计费(95th Percentile charging) 95计费法是CDN常用计费方法: CDN基本上是每月结一次款.每5分钟取一 ...
- php-fpm 在centos 7下的安装配置
安装php: sudo yum install php php-fpm php-mysql php-mbstring php-mcrypt php-sockets php-curl php-commo ...
- Spring使用非applicationContext.xm 默认名的配置文件的配置
Spring默认的配置文件是applicationContext.xml,但是有些时候,希望拆分Spring的配置文件,让其单一化,每一个都只进行自己的配置,如图所示 那么就需要在web.xml中配置 ...
- cs11_c++_lab4a
SparseVector.hh class SparseVector { private: //结构体不一定会用到,不用初始化 struct node { int index; int value; ...
- <读书笔记> 代码整洁之道
概述 1.本文档的内容主要来源于书籍<代码整洁之道>作者Robert C.Martin,属于读书笔记. 2.软件质量,不仅依赖于架构和项目管理,而且与代码质量紧密相关,本书提出一 ...
- win10 剪贴板 拒绝访问 Cannot open clipboard
win10 Cannot open clipboard:拒绝访问. 在RAD IDE代码编辑器中,双击选中的文本,会自动复制到剪贴板里,导致的问题是 从 A处复制文本 到B处双击选中,粘贴的时候,是B ...
- Setup QT 5.5.1 + OpenCV 3.0 + Visual Studio 2013 on windows 10
1. Install Visual studio 2013 community version which is free to use for personal usage. 2. Setup th ...