private void HandleCommand(List <byte> hexBuffer, AsyncClient client = null) { if (hexBuffer != null && hexBuffer.Count >= 6) { if (hexBuffer[0] == 0x00 && hexBuffer[1] == 0x02 && hexBuffer[3] == 0x03)//应该是泵类型命令 { #region //m_Client.s CmdSendPumpType cmdPump = new CmdSendPumpType(); cmdPump.Direction = 1; //cmdPump.PumpState = PumpStatus.Run; List <byte> debugBytes = cmdPump.GetBytesDebug(); int iCount = debugBytes.Count - 4; if (pumpTypeResponseFlag == 1)//全部启动 { debugBytes[iCount - 1] = 0x02; debugBytes[iCount - 2] = 0x02; debugBytes[iCount - 3] = 0x02; debugBytes[iCount - 4] = 0x02; debugBytes[iCount - 5] = 0x02; debugBytes[iCount - 6] = 0x02; } else if (pumpTypeResponseFlag == 2)//全部停止 { debugBytes[iCount - 1] = 0x01; debugBytes[iCount - 2] = 0x01; debugBytes[iCount - 3] = 0x01; debugBytes[iCount - 4] = 0x01; debugBytes[iCount - 5] = 0x01; debugBytes[iCount - 6] = 0x01; } client.Send(Common.Hex2Char(debugBytes.ToArray())); #endregion } else if (hexBuffer[0] == 0x00 && hexBuffer[1] == 0x03 && hexBuffer[3] == 0x09)//应该是老化开始命令 { //m_Client.s CmdCharge cmdcharge = new CmdCharge(); cmdcharge.Direction = 1; List <byte> debugBytes = cmdcharge.GetBytesDebug(); client.Send(Common.Hex2Char(debugBytes.ToArray())); } else if (hexBuffer[0] == 0x00 && hexBuffer[1] == 0x04) //放电命令 { CmdDischarge cmd = new CmdDischarge(); cmd.Direction = 1; List <byte> debugBytes = cmd.GetBytesDebug(); client.Send(Common.Hex2Char(debugBytes.ToArray())); } else if (hexBuffer[0] == 0x00 && hexBuffer[1] == 0x05) //补电命令 { CmdRecharge cmd = new CmdRecharge(); cmd.Direction = 1; List <byte> debugBytes = cmd.GetBytesEx(); client.Send(Common.Hex2Char(debugBytes.ToArray())); } } }
/// <summary> /// 添加通道号的原因是由于控制器轮询一次6个串口很费时间,不如指定具体的串口 /// </summary> /// <param name="rate"></param> /// <param name="volume"></param> /// <param name="remoteSocket"></param> /// <param name="func"></param> /// <param name="timeoutFunc"></param> /// <param name="channel"></param> public void SendCmdCharge(decimal rate, decimal volume, AsyncSocketUserToken remoteSocket, EventHandler <EventArgs> func, EventHandler <EventArgs> timeoutFunc, byte channel = 0xFF) { CmdCharge cmd = new CmdCharge(); cmd.Channel = channel; cmd.SetRate(rate); cmd.SetVolume(volume); cmd.RemoteSocket = remoteSocket; long ip = ControllerManager.GetLongIPFromSocket(remoteSocket); AddCommand(ip, cmd, func, timeoutFunc); }