using EC.Utils.Helper; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace EC.Utils.PLC { /// /// 命令类 /// public class PLCCommand3 { public PLCCommand3() { } public string commandNum2 = ""; //public string commandNum3 = ""; public PLCCommand3(byte[] commandbytes) { if (commandbytes.Length < 16) { function1 = -1; return; } commandNum = ByteHelper.SubToString(commandbytes, 0, 10); NO4 = commandbytes[4]; NO5 = commandbytes[5]; NO6 = commandbytes[6]; NO7 = commandbytes[7]; NO8 = commandbytes[8]; NO9 = commandbytes[9]; commandNum2 = ByteHelper.SubToString(commandbytes, 0, 4) + commandbytes[4].ToString() + commandbytes[5].ToString() + commandbytes[6].ToString() + commandbytes[7].ToString() + commandbytes[8].ToString() + commandbytes[9].ToString(); function1 = commandbytes[10];// state1 = commandbytes[11]; state2 = commandbytes[12]; state3 = commandbytes[13]; x1 = commandbytes[14]; y1 = commandbytes[15]; //x2 = commandbytes[17]; //y2 = commandbytes[18]; //x3 = commandbytes[19]; //y3 = commandbytes[20]; //x4 = commandbytes[21]; //y4 = commandbytes[22]; //x5 = commandbytes[23]; //y5 = commandbytes[24]; //x6 = commandbytes[25]; //y6 = commandbytes[26]; //param1 = commandbytes[27]; //param2 = commandbytes[28]; //param3 = commandbytes[29]; } public byte[] ToBytesCommand() { byte[] command = new byte[16]; command = ByteHelper.Append(command, commandNum, 0); command[4] = (byte)NO4; command[5] = (byte)NO5; command[6] = (byte)NO6; command[7] = (byte)NO7; command[8] = (byte)NO8; command[9] = (byte)NO9; command[10] = (byte)function1; command[11] = (byte)state1; command[12] = (byte)state2; command[13] = (byte)state3; command[14] = (byte)x1; command[15] = (byte)y1; //command[17] = (byte)x2; //command[18] = (byte)y2; //command[19] = (byte)x3; //command[20] = (byte)y3; //command[21] = (byte)x4; //command[22] = (byte)y4; //command[23] = (byte)x5; //command[24] = (byte)y5; //command[25] = (byte)x6; //command[26] = (byte)y6; //command[27] = (byte)param1; //command[28] = (byte)param2; //command[29] = (byte)param3; return command; } //public string ToStrCommand() //{ // StringBuilder command = new StringBuilder(); // command.Append(commandNum).Append(equipment).Append(function1); // command.Append(state1); // command.Append(state2); // command.Append(tasNum); // command.Append(x1); // command.Append(y1); // command.Append(x2); // command.Append(y2); // command.Append(x3); // command.Append(y3); // command.Append(x4); // command.Append(y4); // command.Append(x5); // command.Append(y5); // command.Append(x6); // command.Append(y6); // command.Append(param1); // command.Append(param2); // command.Append(param3); // return command.ToString(); //} public int NO4 { get; set; } = 0; public int NO5 { get; set; } = 0; public int NO6 { get; set; } = 0; public int NO7 { get; set; } = 0; public int NO8 { get; set; } = 0; public int NO9 { get; set; } = 0; #region 分类 /// /// 指令流水号 /// public System.String commandNum { get; set; } /// /// 车间 /// // public System.String workShop { get; set; } = "S3"; /// /// 功能号 /// public int function1 { get; set; } = 0; /// /// 状态1 /// public Int32 state1 { get; set; } /// /// 状态2 /// public Int32 state2 { get; set; } /// /// 任务数 /// public Int32 state3 { get; set; } public int x1 { get; set; } public int y1 { get; set; } /// /// 执行状态 是否成功 /// public bool SendState = false; /// /// 执行情况0:没有 1: 完成 /// public Int32 iFinish { get; set; } /// /// 1:A 臂操作 2: B臂操作 3:全部操作 /// // public int axisType = 1; public int dofferStep = 0; #endregion } }