/// <summary> /// Get equipements from the gateway /// </summary> private void GetEquipements() { //// Get equipements list EquipementsList list = this.FindEquipementsList(); //// Get data part equipements = GetListData(list.Data); //// Foreach equipement in data foreach (string equipement in equipements) { this.SaveEquipement(equipement); } }
public EquipementsList FindEquipementsList() { //// Init result EquipementsList result = null; //// Create an UDP client UdpClient findList = new UdpClient(); //// Gateway IP adress as endpoint IPEndPoint gateway = new IPEndPoint(IPAddress.Parse(PackageHost.GetSettingValue <string>("GatewayIP")), PackageHost.GetSettingValue <int>("GatewayMulticastPort")); //// Constellation IP adress as endpoint IPEndPoint constellation = (IPEndPoint)findList.Client.LocalEndPoint; //// Command to sent string command = @"{""cmd"":""get_id_list""}"; Byte[] buffer = Encoding.ASCII.GetBytes(command); try { //// Send command to gateway findList.Send(buffer, buffer.Length, gateway); //// Receive data var receivedData = findList.Receive(ref constellation); string returnData = Encoding.UTF8.GetString(receivedData).Trim(); //// Deserialize it to EquipementsList class result = JsonConvert.DeserializeObject <EquipementsList>(returnData); return(result); } catch (Exception ex) { PackageHost.WriteError("Error FindEquipementList : {0}", ex); return(result); } }