資源簡介
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#實現查詢功能
評論
共有 條評論