public async Task asyncInitialize() { try { timeString = System.DateTime.Now.ToString("yy'_'M'_'dd'_'HH'_'mm"); var file = Path.Combine(DataFolder, "Hexapod_" + timeString + "_" + "sent.csv"); using (var sentCommands = new StreamWriter(file, true)) { sentCommands.WriteLine("Record Time, Send Time, FN Code, FN Time, X, Y, Z, V, U, W, Receive Time, FN Code, FN Time, X, Y, Z, V, U, W"); sentCommands.Flush(); } recorder = new Consumer <string>(RecordToFile); var recorderTask = recorder.Start(); Connected = true; udpHex = UDPHex.Connect(IPremote, UDPremote, IPlocal, UDPlocal); // TODO: request a lot of info about the hexapod. await recorderTask; } finally { recorder = null; udpHex.Disconnect(); udpHex = null; } }
public static UDPHex Connect( string IPremote = "192.168.15.255", int UDPremote = 7408, string IPlocal = "192.168.15.100", int UDPlocal = 8410) { var connection = new UDPHex(); connection.mboxIPE = new IPEndPoint(IPAddress.Parse(IPremote), UDPremote); // Where it's going (the .255 indicates it's a broadcast!) connection.localIPE = new IPEndPoint(IPAddress.Parse(IPlocal), UDPlocal); // Who we are (.100) connection.udpClient = new UdpClient(); connection.udpClient.Client.Bind(connection.localIPE); return(connection); }