You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace EPSON_SOCKET
{
public class EventArgsCmd : EventArgs
{
public String CmdType { get; set; } //$表示发送,#表示接收,!表示错误.
public String Cmd { get; set; } //命令字,例如,execute,login
public String Str { get; set; }
public String[] Result { get; set; }
public EventArgsCmd(String str)
{
// 解析返回命令,并清理返回数据内容格式.
if (str == null) return;
CmdType = str.Substring(0, 1);
str = str.Substring(1);
str = str.Replace("\"", "");
str = str.Replace(" ", "");
str = str.Replace("\r\n", "");
str = str.Replace(";", ","); //统一所有分隔符为,
Str = str;
Result = new string[0];
if (!string.IsNullOrEmpty(str))
{
Result = str.Split(',');
Cmd = Result[0];
}
}
// 从字符串中解析点位数据.
public static Vector3d ParseVector3d(String str)
{
Vector3d vec3d = new Vector3d();
str = str.Replace("\"", "");
str = str.Replace(" ", "");
str = str.Replace("\r\n", "");
str = str.Replace(";", ",");
String[] arr = str.Split(',');
for (int i = 0; i < arr.Length; i++)
{
if (arr[i].IndexOf("=") >= 0)
{
String[] temp = arr[i].Split('=');
if (temp.Length >= 2)
{
double val = Convert.ToDouble(temp[1]);
temp[0] = temp[0].Trim(' ');
switch (temp[0])
{
case "x":
vec3d.X = val;
break;
case "y":
vec3d.Y = val;
break;
case "z":
vec3d.Z = val;
break;
case "u":
vec3d.U = val;
break;
}
}
}
}
//Cleanup:
return vec3d;
}
}
}