资源简介
PFOpenProtocol协议C#实现代码,用于工业现场拧紧机设备数据采集、参数下发。适用于主流品牌拧紧机。
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Tools;
namespace Protocols.PFOpenProtocol
{
public class PFOpenProtocol
{
#region 枚举
public enum OPRetCode
{
opOk //正确应答
opUnKnow //未知错误
opNetWorkError //网络错误
opAcceptedMidError //应答MID错误
opCommandIsRefuse //请求被拒绝
opCommandIsRefuse_FunctionRepeat //请求未被接受错误代码9,功能重复
opCommandIsRefuse_FunctionNotExist //10订阅没有开启
opCommandIsRefuse_PsetCanNotBeSet //程序号无法设置错误代码3
opCommandIsRefuse_JobCanNotBeSet //请求未被接受错误代码20,功能重复
opCommandIsRefuse_InvalidData //程序号无法设置错误代码01
opCommandIsRefuse_ToolIsInaccessible //工具无法到达27
opCommandIsRefuse_JobAbortionIsInProgress //28
opBufferSmall //缓存越界
opBufferEmpty //缓存为空
opTimeOut //请求超时
}
#endregion
#region 内部类
private class OpenProtoclCMD
{
public int Length;
public int Mid;
public int Rev;
public byte[] DataFile;
public OpenProtoclCMD(byte[] Data)
{
string str = System.Text.Encoding.ASCII.GetString(Data);
this.Length = Int32.Parse(str.Substring(04));
this.Mid = Int32.Parse(str.Substring(4 4));
try
{
this.Rev = str.Substring(8 3).Equals(“ “) ? 0 : Int32.Parse(str.Substring(8 3));
}
catch
{
this.Rev = 0;
}
if (Length > 20)
{
DataFile = new byte[Length - 20];
Buffer.BlockCopy(Data 20 DataFile 0 Length - 20);
}
else
{
DataFile = null;
}
}
public OpenProtoclCMD(int Mid int Revbyte[] DataFile)
{
this.Mid = Mid;
this.Rev = Rev;
this.DataFile = DataFile;
if (DataFile == null)
this.Length = 20;
else
this.Length = 20 + DataFile.Length;
}
public OpenProtoclCMD(int Mid int Rev)
{
this.Length = 20;
this.Mid = Mid;
this.Rev = Rev;
DataFile = null;
}
public byte[] ToBytes()
{
byte[] ret;
String s
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 44646 2018-01-12 13:50 PFOpenProtocol.cs
----------- --------- ---------- ----- ----
44646 1
- 上一篇:学生管理系统 C# 项目
- 下一篇:AE C#实现查询功能
评论
共有 条评论