|
@@ -1,33 +1,18 @@
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
-using System.ComponentModel;
|
|
|
-using System.Data;
|
|
|
using System.Drawing;
|
|
|
-using System.IO;
|
|
|
-using System.Linq;
|
|
|
using System.Net;
|
|
|
-using System.Runtime.InteropServices;
|
|
|
-using System.Runtime.Remoting.Contexts;
|
|
|
-using System.Text;
|
|
|
-using System.Text.RegularExpressions;
|
|
|
-using System.Threading;
|
|
|
-using System.Threading.Tasks;
|
|
|
using System.Timers;
|
|
|
-using System.Web.UI.WebControls;
|
|
|
using System.Windows.Forms;
|
|
|
using MvCamCtrl.NET;
|
|
|
using MvCameraControl;
|
|
|
-using Vanara.PInvoke;
|
|
|
-using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
|
|
-using static AntdUI.Math3D;
|
|
|
-using static CameraModel.Form1;
|
|
|
-using static MvCamCtrl.NET.MyCamera;
|
|
|
+
|
|
|
|
|
|
namespace CameraModel
|
|
|
{
|
|
|
public partial class Form1 : Form
|
|
|
{
|
|
|
- const DeviceTLayerType devLayerType = DeviceTLayerType.MvGigEDevice | DeviceTLayerType.MvUsbDevice | DeviceTLayerType.MvGenTLCameraLinkDevice
|
|
|
+ private const DeviceTLayerType devLayerType = DeviceTLayerType.MvGigEDevice | DeviceTLayerType.MvUsbDevice | DeviceTLayerType.MvGenTLCameraLinkDevice
|
|
|
| DeviceTLayerType.MvGenTLCXPDevice | DeviceTLayerType.MvGenTLXoFDevice;
|
|
|
|
|
|
private IDevice _device = null;
|
|
@@ -41,6 +26,9 @@ namespace CameraModel
|
|
|
private System.Timers.Timer timer;
|
|
|
private System.Timers.Timer ConnentedTimer;
|
|
|
private Dictionary<string,string> devices = new Dictionary<string,string>();
|
|
|
+ private const string ip = "192.168.1.12";
|
|
|
+ private const string subnet = "255.255.255.0";
|
|
|
+ private const string gateway = "192.168.1.254";
|
|
|
public Form1()
|
|
|
{
|
|
|
InitializeComponent();
|
|
@@ -61,10 +49,7 @@ namespace CameraModel
|
|
|
changeConnectStatus = (flag) => { ConnectStatusChange(flag); };
|
|
|
updateDevice = () => { updateDeviceSuccess(); };
|
|
|
// ch: 初始化 SDK | en: Initialize SDK
|
|
|
- MyCamera.MV_CC_Initialize_NET();
|
|
|
-
|
|
|
- //// ch: 枚举设备 | en: Enum Device List
|
|
|
- //DeviceListAcq();
|
|
|
+ //MyCamera.MV_CC_Initialize_NET();
|
|
|
SDKSystem.Initialize();
|
|
|
// 初始化定时器
|
|
|
InitTimer();
|
|
@@ -75,7 +60,7 @@ namespace CameraModel
|
|
|
|
|
|
private void updateDeviceSuccess()
|
|
|
{
|
|
|
- if(_device != null || _device.IsConnected)
|
|
|
+ if(_device != null)
|
|
|
{
|
|
|
//MVCC_STRINGVALUE pstValue = new MVCC_STRINGVALUE();
|
|
|
//m_MyCamera.MV_CC_GetDeviceUserID_NET(ref pstValue);
|
|
@@ -129,20 +114,17 @@ namespace CameraModel
|
|
|
button_update.Enabled = true;
|
|
|
button_clear.Enabled = true;
|
|
|
|
|
|
- //MV_CC_DEVICE_INFO pstDevInfo = new MV_CC_DEVICE_INFO();
|
|
|
- //m_MyCamera.MV_CC_GetDeviceInfo_NET(ref pstDevInfo);
|
|
|
+
|
|
|
string ModelName = _device.DeviceInfo.ModelName;
|
|
|
- //MyCamera.MV_GIGE_DEVICE_INFO_EX gigeInfo = (MyCamera.MV_GIGE_DEVICE_INFO_EX)MyCamera.ByteToStruct(pstDevInfo.SpecialInfo.stGigEInfo, typeof(MyCamera.MV_GIGE_DEVICE_INFO_EX));
|
|
|
+
|
|
|
// 查找型号
|
|
|
input1.Text = GetDeviceId(ModelName);
|
|
|
|
|
|
if(!string.IsNullOrEmpty(input1.Text) && input1.Text.Length <= 15)
|
|
|
{
|
|
|
// 修改型号
|
|
|
- //m_MyCamera.MV_CC_SetDeviceUserID_NET(input1.Text);
|
|
|
//DeviceUserID
|
|
|
_device.Parameters.SetStringValue("DeviceUserID",input1.Text);
|
|
|
- IsUpdateSuccess();
|
|
|
ConnentedTimer.Stop();
|
|
|
LogListBox("型号修改成功," + cbDeviceList.SelectedValue + "=====>" + input1.Text);
|
|
|
IsSuccess = true;
|
|
@@ -156,7 +138,7 @@ namespace CameraModel
|
|
|
}
|
|
|
else //断开
|
|
|
{
|
|
|
- //m_MyCamera = new MyCamera();
|
|
|
+
|
|
|
pictureBox1.Image = global::CameraModel.Properties.Resources.电力_红灯;
|
|
|
pictureBox2.Image = global::CameraModel.Properties.Resources.电力_红灯;
|
|
|
LogListBox("设备已断开!!!");
|
|
@@ -186,17 +168,7 @@ namespace CameraModel
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- private void IsUpdateSuccess()
|
|
|
- {
|
|
|
- //MVCC_STRINGVALUE pstValue = new MVCC_STRINGVALUE();
|
|
|
- //m_MyCamera.MV_CC_GetDeviceUserID_NET(ref pstValue);
|
|
|
- string UserDefinedName = _device.DeviceInfo.UserDefinedName;
|
|
|
- if (!UserDefinedName.Equals(input1.Text))
|
|
|
- {
|
|
|
- //MessageBox.Show("更改失败");
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
private string GetDeviceId(string ModelName)
|
|
|
{
|
|
|
|
|
@@ -315,17 +287,7 @@ namespace CameraModel
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- private string DeleteTail(string strUserDefinedName)
|
|
|
- {
|
|
|
- strUserDefinedName = Regex.Unescape(strUserDefinedName);
|
|
|
- int nIndex = strUserDefinedName.IndexOf("\0");
|
|
|
- if (nIndex >= 0)
|
|
|
- {
|
|
|
- strUserDefinedName = strUserDefinedName.Remove(nIndex);
|
|
|
- }
|
|
|
|
|
|
- return strUserDefinedName;
|
|
|
- }
|
|
|
private bool OpenDevice()
|
|
|
{
|
|
|
int nRet = -1;
|
|
@@ -334,7 +296,7 @@ namespace CameraModel
|
|
|
pictureBox2.Image = global::CameraModel.Properties.Resources.电力_红灯;
|
|
|
if (devInfoList.Count == 0 || cbDeviceList.SelectedIndex == -1)
|
|
|
{
|
|
|
- MessageBox.Show("没有检测或选择设备!");
|
|
|
+ LogListBox("没有检测或选择设备!");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -391,7 +353,7 @@ namespace CameraModel
|
|
|
string netExportIp = nIp1.ToString() + "." + nIp2.ToString() + "." + nIp3.ToString() + "." + nIp4.ToString();
|
|
|
//ch:需要重新创建句柄,设置为静态IP方式进行保存 | en: Need to recreate the handle and set it to static IP mode for saving
|
|
|
//ch: 创建设备 | en: Create device
|
|
|
- _device = DeviceFactory.CreateDeviceByIp("192.168.1.12", netExportIp);
|
|
|
+ _device = DeviceFactory.CreateDeviceByIp(ip, netExportIp);
|
|
|
if (null == _device)
|
|
|
{
|
|
|
LogListBox("Create handle fail");
|
|
@@ -421,10 +383,7 @@ namespace CameraModel
|
|
|
}
|
|
|
private bool SetIp(IGigEDevice _IGigEDevice)
|
|
|
{
|
|
|
- string ip = "192.168.1.12";
|
|
|
- string subnet = "255.255.255.0";
|
|
|
- string gateway = "192.168.1.254";
|
|
|
-
|
|
|
+
|
|
|
uint ipUint = IpToUint(ip);
|
|
|
uint subnetUint = IpToUint(subnet);
|
|
|
uint gatewayUint = IpToUint(gateway);
|
|
@@ -465,17 +424,18 @@ namespace CameraModel
|
|
|
|
|
|
private void button_update_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
- //MV_CC_DEVICE_INFO pstDevInfo = new MV_CC_DEVICE_INFO();
|
|
|
- //m_MyCamera.MV_CC_GetDeviceInfo_NET(ref pstDevInfo);
|
|
|
-
|
|
|
|
|
|
- //MyCamera.MV_GIGE_DEVICE_INFO_EX gigeInfo = (MyCamera.MV_GIGE_DEVICE_INFO_EX)MyCamera.ByteToStruct(pstDevInfo.SpecialInfo.stGigEInfo, typeof(MyCamera.MV_GIGE_DEVICE_INFO_EX));
|
|
|
// 查找型号
|
|
|
string UserDefinedName = _device.DeviceInfo.UserDefinedName;
|
|
|
input1.Text = GetDeviceId(UserDefinedName);
|
|
|
//m_MyCamera.MV_CC_SetDeviceUserID_NET(input1.Text);
|
|
|
- _device.Parameters.SetStringValue("DeviceUserID", input1.Text);
|
|
|
- IsUpdateSuccess();
|
|
|
+ int nRet = _device.Parameters.SetStringValue("DeviceUserID", input1.Text);
|
|
|
+ if (nRet != MvError.MV_OK)
|
|
|
+ {
|
|
|
+ LogListBox("型号修改失败,状态码:" + nRet);
|
|
|
+ LogHelper.LoggerMsg(LogLevel.Error, "型号修改失败! 状态码:" + nRet);
|
|
|
+ return;
|
|
|
+ }
|
|
|
LogListBox("型号修改成功," + cbDeviceList.SelectedValue + "=====>" + input1.Text);
|
|
|
string ModelName = _device.DeviceInfo.ModelName;
|
|
|
if (!devices.ContainsKey(ModelName))
|
|
@@ -563,5 +523,20 @@ namespace CameraModel
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ private void Form1_FormClosing(object sender, FormClosingEventArgs e)
|
|
|
+ {
|
|
|
+ // 关闭定时器
|
|
|
+ if (ConnentedTimer.Enabled)
|
|
|
+ {
|
|
|
+ ConnentedTimer.Stop();
|
|
|
+ }
|
|
|
+ if (timer.Enabled)
|
|
|
+ {
|
|
|
+ timer.Stop();
|
|
|
+ }
|
|
|
+ // 释放设备
|
|
|
+ ReleaseCamera();
|
|
|
+ }
|
|
|
}
|
|
|
}
|