private void btONVIFConnect_Click(object sender, RoutedEventArgs e) { if (btONVIFConnect.Content.ToString() == "Connect") { btONVIFConnect.Content = "Disconnect"; if (onvifControl != null) { onvifControl.Disconnect(); onvifControl.Dispose(); onvifControl = null; } if (string.IsNullOrEmpty(edONVIFLogin.Text) || string.IsNullOrEmpty(edONVIFPassword.Text)) { MessageBox.Show("Please specify IP camera user name and password."); return; } onvifControl = new ONVIFControl(); var result = onvifControl.Connect(edONVIFURL.Text, edONVIFLogin.Text, edONVIFPassword.Text); if (!result) { onvifControl = null; MessageBox.Show("Unable to connect to ONVIF camera."); return; } var deviceInfo = onvifControl.GetDeviceInformation(); lbONVIFCameraInfo.Content = $"Model {deviceInfo.Model}, Firmware {deviceInfo.Firmware}"; edONVIFLiveVideoURL.Text = edIPUrl.Text = onvifControl.GetVideoURL(); edIPLogin.Text = edONVIFLogin.Text; edIPPassword.Text = edONVIFPassword.Text; cbONVIFProfile.Items.Clear(); var profiles = onvifControl.GetProfiles(); foreach (var profile in profiles) { cbONVIFProfile.Items.Add($"{profile.Name}"); } if (cbONVIFProfile.Items.Count > 0) { cbONVIFProfile.SelectedIndex = 0; } onvifPtzRanges = onvifControl.PTZ_GetRanges(); onvifControl.PTZ_SetAbsolute(0, 0, 0); onvifPtzX = 0; onvifPtzY = 0; onvifPtzZoom = 0; } else { btONVIFConnect.Content = "Connect"; if (onvifControl != null) { onvifControl.Disconnect(); onvifControl.Dispose(); onvifControl = null; } } }
private void btONVIFConnect_Click(object sender, EventArgs e) { #if NETCOREAPP MessageBox.Show("ONVIF not avauilable for .Net Core SDK build."); #else if (btONVIFConnect.Text == "Connect") { btONVIFConnect.Text = "Disconnect"; if (onvifControl != null) { onvifControl.Disconnect(); onvifControl.Dispose(); onvifControl = null; } if (string.IsNullOrEmpty(edONVIFLogin.Text) || string.IsNullOrEmpty(edONVIFPassword.Text)) { MessageBox.Show("Please specify IP camera user name and password."); return; } onvifControl = new ONVIFControl(); var result = onvifControl.Connect(edONVIFURL.Text, edONVIFLogin.Text, edONVIFPassword.Text); if (!result) { onvifControl = null; MessageBox.Show("Unable to connect to ONVIF camera."); return; } var deviceInfo = onvifControl.GetDeviceInformation(); if (deviceInfo != null) { lbONVIFCameraInfo.Text = $"Model {deviceInfo.Model}, Firmware {deviceInfo.Firmware}"; } cbONVIFProfile.Items.Clear(); var profiles = onvifControl.GetProfiles(); foreach (var profile in profiles) { cbONVIFProfile.Items.Add($"{profile.Name}"); } if (cbONVIFProfile.Items.Count > 0) { cbONVIFProfile.SelectedIndex = 0; } edONVIFLiveVideoURL.Text = cbIPURL.Text = onvifControl.GetVideoURL(); edIPLogin.Text = edONVIFLogin.Text; edIPPassword.Text = edONVIFPassword.Text; onvifPtzRanges = onvifControl.PTZ_GetRanges(); onvifControl.PTZ_SetHome(); onvifPtzX = 0; onvifPtzY = 0; onvifPtzZoom = 0; } else { btONVIFConnect.Text = "Connect"; if (onvifControl != null) { onvifControl.Disconnect(); onvifControl.Dispose(); onvifControl = null; } } #endif }
private async void btONVIFConnect_Click(object sender, EventArgs e) { if (btONVIFConnect.Text == "Connect") { try { btONVIFConnect.Enabled = false; btONVIFConnect.Text = "Connecting"; if (onvifControl != null) { onvifControl.Disconnect(); onvifControl.Dispose(); onvifControl = null; } if (string.IsNullOrEmpty(edONVIFLogin.Text) || string.IsNullOrEmpty(edONVIFPassword.Text)) { MessageBox.Show("Please specify IP camera user name and password."); return; } onvifControl = new ONVIFControl(); var result = await onvifControl.ConnectAsync(edONVIFURL.Text, edONVIFLogin.Text, edONVIFPassword.Text); if (!result) { onvifControl = null; MessageBox.Show("Unable to connect to ONVIF camera."); return; } var deviceInfo = await onvifControl.GetDeviceInformationAsync(); if (deviceInfo != null) { lbONVIFCameraInfo.Text = $"Model {deviceInfo.Model}, Firmware {deviceInfo.Firmware}"; } cbONVIFProfile.Items.Clear(); var profiles = await onvifControl.GetProfilesAsync(); foreach (var profile in profiles) { cbONVIFProfile.Items.Add($"{profile.Name}"); } if (cbONVIFProfile.Items.Count > 0) { cbONVIFProfile.SelectedIndex = 0; } edONVIFLiveVideoURL.Text = cbIPURL.Text = await onvifControl.GetVideoURLAsync(); edIPLogin.Text = edONVIFLogin.Text; edIPPassword.Text = edONVIFPassword.Text; onvifPtzRanges = await onvifControl.PTZ_GetRangesAsync(); await onvifControl.PTZ_SetAbsoluteAsync(0, 0, 0); onvifPtzX = 0; onvifPtzY = 0; onvifPtzZoom = 0; btONVIFConnect.Text = "Disconnect"; } finally { btONVIFConnect.Enabled = true; btONVIFConnect.Text = "Connect"; } } else { btONVIFConnect.Text = "Connect"; if (onvifControl != null) { onvifControl.Disconnect(); onvifControl.Dispose(); onvifControl = null; } } }