/// <summary> /// 设备命令互发 /// 基于网络 /// </summary> /// <param name="index"></param> /// <param name="action"></param> /// <param name="paramter"></param> /// <returns></returns> public string SendEquipmentCmd(int index, string action, string paramter) { string result = string.Empty; TcpClient client = new TcpClient(); client.Connect(IPAddress.Parse(NetUtil.GetStationIp(index)), NetUtil.PORT_LITE_DATA_SERVER); using (NetworkStream stream = client.GetStream()) { LiteData liteData = new LiteData(); liteData.Name = "RemoteEquipmentCmd"; liteData.Paramters = new string[] { action, paramter }; string request = JsonConvert.SerializeObject(liteData); byte[] requestBuffer = System.Text.Encoding.UTF8.GetBytes(request); stream.Write(requestBuffer, 0, requestBuffer.Length); byte[] respBuffer = new byte[1024]; int len = stream.Read(respBuffer, 0, respBuffer.Length); if (len > 0) { result = System.Text.Encoding.UTF8.GetString(respBuffer, 0, len); } } client.Close(); return(result); }
/// <summary> /// 获取手机的IP地址 /// </summary> /// <param name="index"></param> /// <returns></returns> public string GetPhoneIP(int index) { string ip = string.Empty; TcpClient client = new TcpClient(); client.Connect(IPAddress.Parse(NetUtil.GetStationIp(0)), NetUtil.PORT_LITE_DATA_SERVER); using (NetworkStream stream = client.GetStream()) { string request = "TargetIp " + index; byte[] requestBuffer = System.Text.Encoding.UTF8.GetBytes(request); stream.Write(requestBuffer, 0, requestBuffer.Length); byte[] respBuffer = new byte[1024]; int len = stream.Read(respBuffer, 0, respBuffer.Length); if (len > 0) { ip = System.Text.Encoding.UTF8.GetString(respBuffer, 0, len); } } client.Close(); return(ip); }
/// <summary> /// 流程运行完成事件 /// </summary> /// <param name="index"></param> /// <returns></returns> public bool SendCompleteFlag(int index) { bool result = false; TcpClient client = new TcpClient(); client.Connect(IPAddress.Parse(NetUtil.GetStationIp(0)), NetUtil.PORT_LITE_DATA_SERVER); using (NetworkStream stream = client.GetStream()) { string request = "Complete " + index; byte[] requestBuffer = System.Text.Encoding.UTF8.GetBytes(request); stream.Write(requestBuffer, 0, requestBuffer.Length); byte[] respBuffer = new byte[1024]; int len = stream.Read(respBuffer, 0, respBuffer.Length); if (len > 0) { string response = System.Text.Encoding.UTF8.GetString(respBuffer, 0, len); result = true; } } client.Close(); return(result); }