public void EnumDevicePoint(string opcServerAddress, List <string> parentPath, Action <PointInfomation> onFindPoint) { var client = new Way.Lib.NetStream(this.Address, this.Port); var json = Newtonsoft.Json.JsonConvert.SerializeObject(new Command() { Type = "EnumDevicePoint", DeviceAddress = opcServerAddress, ParentPath = parentPath, }); byte[] bs = System.Text.Encoding.UTF8.GetBytes(json); client.Write(bs.Length); client.Write(bs); while (true) { var len = client.ReadInt(); if (len < 0) { break; } bs = client.ReceiveDatas(len); string point = System.Text.Encoding.UTF8.GetString(bs); onFindPoint(Newtonsoft.Json.JsonConvert.DeserializeObject <PointInfomation>(point)); } client.Dispose(); }
public ServerInfo GetServerInfo() { var client = new Way.Lib.NetStream(this.Address, this.Port); var json = Newtonsoft.Json.JsonConvert.SerializeObject(new Command() { Type = "GetServerInfo" }); byte[] bs = System.Text.Encoding.UTF8.GetBytes(json); client.Write(bs.Length); client.Write(bs); int len = client.ReadInt(); bs = client.ReceiveDatas(len); client.Dispose(); return(Newtonsoft.Json.JsonConvert.DeserializeObject <ServerInfo>(System.Text.Encoding.UTF8.GetString(bs))); }
public bool CheckDeviceExist(string deviceAddress) { var client = new Way.Lib.NetStream(this.Address, this.Port); var json = Newtonsoft.Json.JsonConvert.SerializeObject(new Command() { Type = "CheckDeviceExist", DeviceAddress = deviceAddress }); byte[] bs = System.Text.Encoding.UTF8.GetBytes(json); client.Write(bs.Length); client.Write(bs); bool result = client.ReadBoolean(); client.Dispose(); return(result); }
public object[] ReadValue(string deviceAddress, string[] points) { var client = new Way.Lib.NetStream(this.Address, this.Port); var json = Newtonsoft.Json.JsonConvert.SerializeObject(new Command() { Type = "ReadValue", DeviceAddress = deviceAddress, Points = points }); byte[] bs = System.Text.Encoding.UTF8.GetBytes(json); client.Write(bs.Length); client.Write(bs); object[] values = new object[points.Length]; for (int i = 0; i < points.Length; i++) { int index = client.ReadInt(); PointValueType valueType = (PointValueType)client.ReadInt(); if (valueType == PointValueType.Short) { values[index] = client.ReadShort(); } else if (valueType == PointValueType.Int) { values[index] = client.ReadInt(); } else if (valueType == PointValueType.Float) { values[index] = client.ReadFloat(); } else if (valueType == PointValueType.String) { values[index] = System.Text.Encoding.UTF8.GetString(client.ReceiveDatas(client.ReadInt())); } else { throw new Exception($"not support value type {valueType}"); } } client.Dispose(); return(values); }
/// <summary> /// 获取设备路径 /// </summary> /// <param name="proObj">属性值</param> /// <returns></returns> public string GetDeviceAddress(Dictionary <string, string> proValues) { var client = new Way.Lib.NetStream(this.Address, this.Port); var json = Newtonsoft.Json.JsonConvert.SerializeObject(new Command() { Type = "GetDeviceAddress", Values = new object[] { proValues } }); byte[] bs = System.Text.Encoding.UTF8.GetBytes(json); client.Write(bs.Length); client.Write(bs); int len = client.ReadInt(); bs = client.ReceiveDatas(len); client.Dispose(); return(System.Text.Encoding.UTF8.GetString(bs)); }
void handleSocket(Socket socket) { var client = new Way.Lib.NetStream(socket); new Thread(() => { try { var len = client.ReadInt(); byte[] bs = client.ReceiveDatas(len); Command cmd = Newtonsoft.Json.JsonConvert.DeserializeObject <Command>(System.Text.Encoding.UTF8.GetString(bs)); var handler = GetHandler(cmd.Type); handler.Handle(client, cmd); client.ReceiveDatas(1); } catch (Exception ex) { } finally { client.Dispose(); } }).Start(); }
public bool[] WriteValue(string deviceAddress, string[] points, object[] values) { var result = new bool[points.Length]; var client = new Way.Lib.NetStream(this.Address, this.Port); var json = Newtonsoft.Json.JsonConvert.SerializeObject(new Command() { Type = "WriteValue", DeviceAddress = deviceAddress, Points = points, Values = values }); byte[] bs = System.Text.Encoding.UTF8.GetBytes(json); client.Write(bs.Length); client.Write(bs); for (int i = 0; i < result.Length; i++) { result[i] = client.ReadBoolean(); } client.Dispose(); return(result); }