public static string GenerateDeviceId(MTConnectSniffer.MTConnectDevice device) { // Create Identifier input string s = string.Format("{0}|{1}|{2}", device.DeviceName, device.Port, device.MacAddress); s = Uri.EscapeDataString(s); // Create Hash var b = Encoding.UTF8.GetBytes(s); var h = SHA1.Create(); b = h.ComputeHash(b); var l = b.ToList(); l.Reverse(); b = l.ToArray(); // Convert to Base64 string s = Convert.ToBase64String(b); // Remove non alphanumeric characters var regex = new Regex("[^a-zA-Z0-9 -]"); s = regex.Replace(s, ""); s = s.ToUpper(); return(s); }
private bool AddDevice(MTConnectSniffer.MTConnectDevice device) { // Generate the Device ID Hash string deviceId = GenerateDeviceId(device); // Check to make sure the Device is not already added if (!Configuration.Devices.Exists(o => o.DeviceId == deviceId)) { var conn = new Api.v2.Data.Connection(); conn.Address = device.IpAddress.ToString(); conn.PhysicalAddress = device.MacAddress.ToString(); conn.Port = device.Port; // Create a new Device and start it var d = new Device(deviceId, conn, device.DeviceName); Configuration.Devices.Add(d); StartDevice(d); log.Info("New Device Added : " + deviceId + " : " + device.DeviceName + " : " + device.IpAddress + " : " + device.Port); return(true); } return(false); }
private void DeviceFinder_DeviceFound(MTConnectSniffer.MTConnectDevice device) { foundDevice = device; if (AddDevice(device)) { devicesFound++; } }
private void DeviceFinder_SearchCompleted(long milliseconds) { if (devicesFound > 0) { Configuration.Save(); } var time = TimeSpan.FromMilliseconds(milliseconds); log.Info(string.Format("Device Finder : Search Completed : {0} Devices Found in {1}", devicesFound, time.ToString())); devicesFound = 0; foundDevice = null; }