change-扫码器键值对主键调换

collectionStore
liuwf 11 months ago
parent ffcbace19f
commit bb7d41c102

@ -32,7 +32,7 @@ namespace Aucma.Core.Scanner
public static MvCodeReader.MV_CODEREADER_DEVICE_INFO_LIST m_stDeviceList = new MvCodeReader.MV_CODEREADER_DEVICE_INFO_LIST(); public static MvCodeReader.MV_CODEREADER_DEVICE_INFO_LIST m_stDeviceList = new MvCodeReader.MV_CODEREADER_DEVICE_INFO_LIST();
// (成功创建)连接上的设备和其ip(string)集合 // (成功创建)连接上的设备和其ip(string)集合
public static Dictionary<MvCodeReader, string> m_cMyDevices = new Dictionary<MvCodeReader, string>(); public static Dictionary<string, MvCodeReader> m_cMyDevices = new Dictionary<string, MvCodeReader>();
#region 设备连接状态 #region 设备连接状态
/// <summary> /// <summary>
@ -42,18 +42,18 @@ namespace Aucma.Core.Scanner
public static bool ConnectionStatus(string ip) public static bool ConnectionStatus(string ip)
{ {
// 遍历所有已打开相机 // 遍历所有已打开相机
foreach (KeyValuePair<MvCodeReader, string> hashmap in m_cMyDevices) foreach (var hashmap in m_cMyDevices)
{ {
if (ip.Equals(hashmap.Value)) if (ip.Equals(hashmap.Key))
{ {
return true; return true;
} }
} }
// 没有连接上,重新获取并创建设备 //// 没有连接上,重新获取并创建设备
Task.Run(() => //Task.Run(() =>
{ //{
DeviceListAcq(); // DeviceListAcq();
}); //});
return false; return false;
} }
#endregion #endregion
@ -124,14 +124,14 @@ namespace Aucma.Core.Scanner
} }
RefreshLogMessageEvent?.Invoke("创建并打开第" + i + "个扫码器设备成功,ip:" + ip); RefreshLogMessageEvent?.Invoke("创建并打开第" + i + "个扫码器设备成功,ip:" + ip);
//设置触发模式 //设置触发模式
nRet = m_cMyDevice.MV_CODEREADER_SetEnumValue_NET("TriggerMode", (uint)MvCodeReader.MV_CODEREADER_TRIGGER_MODE.MV_CODEREADER_TRIGGER_MODE_ON); //nRet = m_cMyDevice.MV_CODEREADER_SetEnumValue_NET("TriggerMode", (uint)MvCodeReader.MV_CODEREADER_TRIGGER_MODE.MV_CODEREADER_TRIGGER_MODE_ON);
if (MvCodeReader.MV_CODEREADER_OK != nRet) //if (MvCodeReader.MV_CODEREADER_OK != nRet)
{ //{
Console.WriteLine("设置触发模式失败"); // Console.WriteLine("设置触发模式失败");
return; // return;
} //}
//添加到集合 //添加到集合
m_cMyDevices.Add(m_cMyDevice, ip); m_cMyDevices.Add(ip, m_cMyDevice);
} }
} }
} }
@ -156,13 +156,15 @@ namespace Aucma.Core.Scanner
IntPtr pstFrameInfoEx2 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(MvCodeReader.MV_CODEREADER_IMAGE_OUT_INFO_EX2))); IntPtr pstFrameInfoEx2 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(MvCodeReader.MV_CODEREADER_IMAGE_OUT_INFO_EX2)));
Marshal.StructureToPtr(stFrameInfoEx2, pstFrameInfoEx2, false); Marshal.StructureToPtr(stFrameInfoEx2, pstFrameInfoEx2, false);
foreach (KeyValuePair<MvCodeReader, string> hashmap in m_cMyDevices) foreach (var hashmap in m_cMyDevices)
{
Task.Run(() =>
{ {
nRet = hashmap.Key.MV_CODEREADER_StartGrabbing_NET(); nRet = hashmap.Value.MV_CODEREADER_StartGrabbing_NET();
while (m_bGrabbing) while (m_bGrabbing)
{ {
// 光电触发了有图像 // 光电触发了有图像
nRet = hashmap.Key.MV_CODEREADER_GetOneFrameTimeoutEx2_NET(ref pData, pstFrameInfoEx2, 1000); nRet = hashmap.Value.MV_CODEREADER_GetOneFrameTimeoutEx2_NET(ref pData, pstFrameInfoEx2, 1000);
// ch:获取一帧图像 | en:Get one image // ch:获取一帧图像 | en:Get one image
if (MvCodeReader.MV_CODEREADER_OK == nRet) if (MvCodeReader.MV_CODEREADER_OK == nRet)
{ {
@ -186,11 +188,11 @@ namespace Aucma.Core.Scanner
Array.Copy(stBcrResult.stBcrInfoEx2[i].chCode, buffer, 22); Array.Copy(stBcrResult.stBcrInfoEx2[i].chCode, buffer, 22);
} }
string strCode = Encoding.GetEncoding("UTF-8").GetString(buffer).Trim().TrimEnd('\0'); string strCode = Encoding.GetEncoding("UTF-8").GetString(buffer).Trim().TrimEnd('\0');
RefreshLogMessageEvent?.Invoke("相机ip:" + hashmap.Value + " Get CodeNum: " + "CodeNum[" + i.ToString() + "], CodeString[" + strCode + "]"); RefreshLogMessageEvent?.Invoke("相机ip:" + hashmap.Key + " Get CodeNum: " + "CodeNum[" + i.ToString() + "], CodeString[" + strCode + "]");
if (!string.IsNullOrEmpty(strCode) && lastCode != strCode) if (!string.IsNullOrEmpty(strCode) && lastCode != strCode)
{ {
RefreshMaterialCodeStrEvent?.Invoke(strCode,hashmap.Value); RefreshMaterialCodeStrEvent?.Invoke(strCode, hashmap.Key);
lastCode = strCode; lastCode = strCode;
} }
@ -200,6 +202,7 @@ namespace Aucma.Core.Scanner
Thread.Sleep(500); Thread.Sleep(500);
} }
});
} }
} }
@ -219,17 +222,17 @@ namespace Aucma.Core.Scanner
Console.WriteLine("开始关闭所有设备"); Console.WriteLine("开始关闭所有设备");
int nRet = MvCodeReader.MV_CODEREADER_OK; int nRet = MvCodeReader.MV_CODEREADER_OK;
// 关闭所有已打开相机 // 关闭所有已打开相机
foreach (KeyValuePair<MvCodeReader, string> hashmap in m_cMyDevices) foreach (var hashmap in m_cMyDevices)
{ {
// ch:停止抓图 | en:Stop grab image // ch:停止抓图 | en:Stop grab image
nRet = hashmap.Key.MV_CODEREADER_StopGrabbing_NET(); nRet = hashmap.Value.MV_CODEREADER_StopGrabbing_NET();
if (MvCodeReader.MV_CODEREADER_OK != nRet) if (MvCodeReader.MV_CODEREADER_OK != nRet)
{ {
Console.WriteLine("设备ip:" + hashmap.Value + "停止抓图失败"); Console.WriteLine("设备ip:" + hashmap.Value + "停止抓图失败");
Console.WriteLine("Stop grabbing failed{0:x8}", nRet); Console.WriteLine("Stop grabbing failed{0:x8}", nRet);
} }
// ch:关闭设备 | en:Close device // ch:关闭设备 | en:Close device
nRet = hashmap.Key.MV_CODEREADER_CloseDevice_NET(); nRet = hashmap.Value.MV_CODEREADER_CloseDevice_NET();
if (MvCodeReader.MV_CODEREADER_OK != nRet) if (MvCodeReader.MV_CODEREADER_OK != nRet)
{ {
Console.WriteLine("设备ip:" + hashmap.Value + "关闭失败"); Console.WriteLine("设备ip:" + hashmap.Value + "关闭失败");
@ -237,7 +240,7 @@ namespace Aucma.Core.Scanner
} }
// ch:销毁设备 | en:Destroy device // ch:销毁设备 | en:Destroy device
nRet = hashmap.Key.MV_CODEREADER_DestroyHandle_NET(); nRet = hashmap.Value.MV_CODEREADER_DestroyHandle_NET();
if (MvCodeReader.MV_CODEREADER_OK != nRet) if (MvCodeReader.MV_CODEREADER_OK != nRet)
{ {
Console.WriteLine("设备ip:" + hashmap.Value + "销毁失败"); Console.WriteLine("设备ip:" + hashmap.Value + "销毁失败");

Loading…
Cancel
Save