| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842 |
- using Cognex.VisionPro;
- using Cognex.VisionPro.ToolBlock;
- using CSScripting;
- using Microsoft.Win32;
- using NPOI.SS.Formula.Functions;
- using SR7Link;
- using SRAPI;
- using SRCSharpDemo;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using System.Runtime.CompilerServices;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using TeamAAS_VP.Enums;
- using TeamAAS_VP.Interfaces;
- using TeamAAS_VP.Models;
- namespace TeamAAS_VP.Core.Cameras
- {
- public class SSZNCamera : ICamera, INotifyPropertyChanged
- {
- #region 字段
- private Thread m_hReceiveThread;
- // 用于序列化对同一相机实例的操作,防止同一实例被并发操作
- //private readonly SemaphoreSlim _operationSemaphore = new SemaphoreSlim(1, 1);
- // 用于保护状态变量(例如 IsGrabbing)的并发访问
- private readonly object _stateLock = new object();
- private SR7ApiOneTimeCallbackImpl iSR7APi = new SR7ApiOneTimeCallbackImpl();
- public SRCSharpTools srcsharpTools = new SRCSharpTools();
- private SR7IFGetDataCallBack GetDataDelegate;
- private ErrConnectCallBack _errConnectDelegate;
- // 用于 Grab() 的一次性等待/完成通知
- private TaskCompletionSource<ICogImage> _grabTcs;
- #endregion
- #region define
- private int lastTotalPoints = 0; // 记录上次的总点数 / Record the last total points
- public int coutCallbackPoints;//统计总回调行数 / Count the total number of callback rows
- public uint profile16Bits = 0;//0:32bit 1:16bit
- //define
- public const int INVALID_VALUE_MIN = -1000000000;
- public const int INVALID_VALUE_MAX = 1000000000;
- #endregion
- #region Image cache variable
- //image cache
- public int[][] ImgBuff32; // 32-bit height data
- public short[][] ImgBuff16; // 16-bit height data
- public byte[][] GrayBuff; // Grayscale data
- public int[][] Encoder; // Encoder data
- public int coutCallbackPoints_B;
- #endregion
- #region 属性
- /// <summary>
- /// 是否是3D相机
- /// </summary>
- public bool Is3D { get; } = true;
- public CameraBrand CameraBrand { get => CameraBrand.SSZN; }
- public string Name { get; private set; }
- public Guid ID { get; private set; }
- public int Index { get; set; }
- public string ManufacturerName { get; private set; }
- public bool IsFindByIp { get; private set; }
- public string ModelName { get; private set; }
- public string SerialNumber { get; private set; }
- public string CameraIp { get; private set; }
- public CameraType CameraType { get; private set; }
- public UInt32 ImageWidth { get; private set; }
- public UInt32 ImageHeight { get; private set; }
- private bool _IsGrabbing;
- /// <summary>
- /// 正在采集
- /// </summary>
- public bool IsGrabbing
- {
- get { return _IsGrabbing; }
- private set { SetProperty(ref _IsGrabbing, value); }
- }
- private ICogImage _Image;
- public ICogImage Image
- {
- get { return _Image; }
- private set { SetProperty(ref _Image, value); }
- }
- public bool IsConnected { get; private set; }
- /// <summary>
- /// 采集用时
- /// </summary>
- public TimeSpan TotalTime { get; private set; }
- /// <summary>
- /// 错误信息
- /// </summary>
- public string ErrorMessage { get; private set; }
- private bool _CameraRevFinish;
- /// <summary>
- /// 图像接收完成
- /// </summary>
- public bool CameraRevFinish
- {
- get { return _CameraRevFinish; }
- set { SetProperty(ref _CameraRevFinish, value); }
- }
- /// <summary>
- /// 图像接收超时时间30s
- /// </summary>
- private double Timeout = 30;
- #endregion
- #region 事件
- public event Action<ICogImage, TimeSpan, string,Guid> ImageCallbackEvent;
- public event Action<Guid, bool> CameraConnectChangedEvent;
- #endregion
- public SSZNCamera(Guid id, int index, string name, string serialNumber, string cameraip, bool isFindByIp)
- {
- ID = id;
- Name = serialNumber;
- Index = index;
- CameraIp = cameraip;
- SerialNumber = serialNumber;
- IsFindByIp = isFindByIp;
- IsConnected = false;
- }
- #region 方法
- /// <summary>
- /// 外部设置批处理点数(例如从 UI 的 PlcPoint.Camera_Data)
- /// </summary>
- /// <param name="batchPoints"></param>
- public void SetBatchPoints(int batchPoints)
- {
- // 保证线程安全
- //_operationSemaphore.Wait();
- try
- {
- try
- {
- // 如果 SDK 对象支持 BatchPoints 字段,则设置
- iSR7APi.BatchPoints = batchPoints;
- }
- catch { }
- try
- {
- // 将值写回相机配置(保持与 OpenDevice 一致的行为)
- iSR7APi.SetParams(0, (int)SAVEPOWEROFF.ESAPO_SAVE, -1, SR7IF_SETTING_ITEM.BATCH_POINT, batchPoints);
- //SR7LinkFunc.SR7IF_StartMeasureWithCallback(0, 1);
-
- }
- catch { }
- }
- finally
- {
- //_operationSemaphore.Release();
- }
- }
- /// <summary>
- /// 获取设备
- /// </summary>
- /// <returns></returns>
- public static CameraInfo[] GetDevices()
- {
- List<CameraInfo> cameras = new List<CameraInfo>();
- try
- {
- if (!CheckSoftwareInstalled().isInstalled)
- {
- LogHelper.WriteLogInfo("未安装MVS");
- return cameras.ToArray();
- }
- SR7ApiOneTimeCallbackImpl sR7Api = new SR7ApiOneTimeCallbackImpl();
- List<string> cameraIPs = new List<string>();
- if (!sR7Api.SearchCameraIP(out cameraIPs))
- {
- return cameras.ToArray();
- }
- else
- {
- for (int i = 0; i < cameraIPs.Count; i++)
- {
- cameras.Add(new CameraInfo()
- {
- CameraNo = i + 1,
- CameraName = "SSZN_" + cameraIPs[i],
- CameraBrand = CameraBrand.SSZN,
- CameraType = CameraType.GIGE,
- ManufacturerName = "SSZN",
- Model = "SSZN_Model",
- SerialNumber = "SSZN_SerialNumber",
- CameraIp = cameraIPs[i],
- IsFindByIp = true,
- });
- }
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("搜索深视3D相机列表时出错!", ex);
- }
- return cameras.ToArray();
- }
- /// <summary>
- /// 检查相机软件是否安装
- /// </summary>
- /// <returns></returns>
- public static (bool isInstalled, string version) CheckSoftwareInstalled()
- {
- return (true, "");
- }
- /// <summary>
- /// 打开相机
- /// </summary>
- /// <returns></returns>
- /// <exception cref="Exception"></exception>
- public bool OpenDevice()
- {
- //_operationSemaphore.Wait();
- try
- {
- if (!iSR7APi.CameraBOnline)
- {
- //SR7Link.ErrConnectCallBack ErrConnectDelegate = new SR7Link.ErrConnectCallBack(ErrConnectFunc);
- //ErrConnectDelegate = new ErrConnectCallBack(ErrConnectFunc);
- //int nOpenRet = iSR7APi.Open(Index - 1, CameraIp, 2000, ErrConnectDelegate);
- if(_errConnectDelegate==null)
- {
- _errConnectDelegate=new ErrConnectCallBack(ErrConnectFunc);
- }
- int nOpenRet = iSR7APi.Open(Index - 1, CameraIp, 2000, _errConnectDelegate);
- if (nOpenRet == (int)SR7Link.SR7IF_ERROR.SR7IF_OK)
- {
-
- //设置相机参数,否则无法取图 / Set the camera parameters, otherwise you will not be able to take pictures
- //一次回调和无限回调可以设置批处理测量On,批处理数据接收无和循环 / One-time callback and infinite callback can set batch measurement On, batch data receiving None and loop
- //异步回调必须在Ed软件中设置 / Asynchronous callbacks must be set in the EdgeImaging software
- int nReadBastchValue = -1;
- int nSetParamRet = -1;
- int getParamRet = iSR7APi.GetParams(Index - 1, -1, SR7IF_SETTING_ITEM.BATCH_ON_OFF, out nReadBastchValue);
- if (nReadBastchValue != 1)
- {
- nSetParamRet = iSR7APi.SetParams(Index - 1, (int)SAVEPOWEROFF.ESAPO_SAVE, -1, SR7IF_SETTING_ITEM.BATCH_ON_OFF, 1);
- LogHelper.WriteLogInfo($"Set Batch On Off: {nSetParamRet}");
- }
- int _BatchPoints = 0;
- getParamRet = iSR7APi.GetParams(Index - 1, -1, SR7IF_SETTING_ITEM.BATCH_POINT, out _BatchPoints);
- iSR7APi.BatchPoints = _BatchPoints;
- nSetParamRet = iSR7APi.SetParams(Index - 1, (int)SAVEPOWEROFF.ESAPO_SAVE, -1, SR7IF_SETTING_ITEM.CYCLICAL_PATTERN, 0);
- int nSetParamRet1 = iSR7APi.SetParams(Index - 1, (int)SAVEPOWEROFF.ESAPO_SAVE, -1, SR7IF_SETTING_ITEM.SEGMENT_BUFER, 0);
- LogHelper.WriteLogInfo($"Set Batch Data Receive: {nSetParamRet1}{nSetParamRet1}");
- GetDataDelegate = new SR7IFGetDataCallBack(GetDataCallBack);
- iSR7APi.Init(Index - 1, 0, 2000, GetDataDelegate);
- }
- LogHelper.WriteLogInfo($"Connect Camera {nOpenRet} {GetSDKErrMsgByCode(nOpenRet)}");
- }
- if (!IsConnected)
- {
- if (iSR7APi.CameraAOnline)
- {
- CameraConnectChangedEvent?.Invoke(ID, true);
- }
- }
- IsConnected = iSR7APi.CameraAOnline;
- return IsConnected;
- }
- finally
- {
- //_operationSemaphore.Release();
- }
- }
- /// <summary>
- /// 打开相机异步
- /// </summary>
- /// <returns></returns>
- public Task<bool> OpenDeviceAsync()
- {
- return Task.Run(() =>
- {
- return OpenDevice();
- });
- }
- /// <summary>
- /// 关闭相机
- /// </summary>
- public void CloseDevice()
- {
- // ch:关闭设备 | en:Close Device
- //_operationSemaphore.Wait();
- try
- {
- if (iSR7APi == null)
- {
- return;
- }
- iSR7APi.Stop();
- int nRet = iSR7APi.Close();
- LogHelper.WriteLogInfo($"Close Camera: {nRet}{GetSDKErrMsgByCode(nRet)}");
- }
- finally
- {
- //_operationSemaphore.Release();
- }
- }
- /// <summary>
- /// 采集图像(同步阻塞实现:发送一次启动,等待回调或超时,返回图像)
- /// </summary>
- /// <returns></returns>
- public ICogImage Grab(bool isRealtime=true)
- {
- // 采用同步阻塞方式实现,一次采集等待回调完成或超时返回
- //_operationSemaphore.Wait();
- try
- {
- if (!isRealtime)
- return Image;
- DateTime now = DateTime.Now;
- while (!CameraRevFinish)
- {
- Thread.Sleep(10);
- if (DateTime.Now.Subtract(now).TotalSeconds>Timeout)
- {
- LogHelper.WriteLogDebug("图像采集超时");
- return null;
- }
- }
- return Image;
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("Grab 出错", ex);
- return null;
- }
- finally
- {
- _grabTcs = null;
- //_operationSemaphore.Release();
- }
- }
- #region Init Memory
- public void InitImageBufferMem(bool isExistCameraB, int nWidth, int nHeight)
- {
- int nTotalPoints = nWidth * nHeight;
- if (nTotalPoints <= 0 || nTotalPoints <= lastTotalPoints)
- {
- for (int i = 0; i < 2; i++)
- {
- for (int j = 0; j < nTotalPoints; j++)
- {
- ImgBuff32[i][j] = -1000000000; // 初始化为 -1000000000
- }
- for (int j = 0; j < nTotalPoints; j++)
- {
- ImgBuff16[i][j] = 0;
- GrayBuff[i][j] = 0;
- }
- for (int j = 0; j < nHeight; j++)
- {
- Encoder[i][j] = 0;
- }
- }
- if (nTotalPoints == lastTotalPoints)
- {
- return;
- }
- // 避免重复初始化 / Avoid repeated initialization
- }
- // 如果 nTotalPoints 发生变化,才重新分配内存
- // If nTotalPoints changes, reallocate memory
- FreeMemory();
- ImgBuff32 = new int[2][];
- ImgBuff16 = new short[2][];
- GrayBuff = new byte[2][];
- Encoder = new int[2][];
- for (int i = 0; i < 2; i++)
- {
- ImgBuff32[i] = new int[nTotalPoints]; // 32-bit 高度数据 / height data
- for (int j = 0; j < nTotalPoints; j++)
- {
- ImgBuff32[i][j] = -1000000000; // 初始化为 -1000000000
- }
- ImgBuff16[i] = new short[nTotalPoints]; // 16-bit 高度数据 / height data
- GrayBuff[i] = new byte[nTotalPoints]; // 灰度数据 / grayscale data
- Encoder[i] = new int[nHeight]; // 编码器数据 / Encoder data
- }
- lastTotalPoints = nTotalPoints;
- }
- public void FreeMemory()
- {
- if (ImgBuff32 != null)
- {
- ImgBuff32 = null;
- ImgBuff16 = null;
- GrayBuff = null;
- Encoder = null;
- lastTotalPoints = 0;
- GC.Collect();
- }
- }
- #endregion
- /// <summary>
- /// 开始采集图像
- /// </summary>
- public void StartGrabbing()
- {
- //lock (_stateLock)
- //{
- // if (IsGrabbing)
- // return;
- // IsGrabbing = true;
- //}
- //m_hReceiveThread = new Thread(GetStreamThreadProc) { IsBackground = true };
- //m_hReceiveThread.Start();
- }
- /// <summary>
- /// 停止采集图像
- /// </summary>
- public void StopGrabbing()
- {
- //try
- //{
- // lock (_stateLock)
- // {
- // IsGrabbing = false;
- // }
- // Thread.Sleep(1000);
- // if (m_hReceiveThread != null)
- // {
- // m_hReceiveThread.Abort();
- // m_hReceiveThread = null;
- // }
- //}
- //catch (Exception)
- //{
- //}
- }
- /// <summary>
- /// 设置曝光时间
- /// </summary>
- /// <param name="ExposureTime"></param>
- /// <returns></returns>
- public bool SetExposureTime(float ExposureTime)
- {
- //_operationSemaphore.Wait();
- //try
- //{
- // if (!mvCameraAcq.bIsOpened)
- // return false;
- // mvCameraAcq.ExposureTime = (double)ExposureTime;
- // return true;
- //}
- //finally
- //{
- // _operationSemaphore.Release();
- //}
- return true;
- }
- /// <summary>
- /// 获取曝光时间
- /// </summary>
- /// <returns></returns>
- public float GetExposureTime()
- {
- //_operationSemaphore.Wait();
- //try
- //{
- // if (!mvCameraAcq.bIsOpened)
- // return 0;
- // return (float)mvCameraAcq.ExposureTime;
- //}
- //finally
- //{
- // _operationSemaphore.Release();
- //}
- return 0;
- }
- /// <summary>
- /// 设置增益
- /// </summary>
- /// <param name="Gain"></param>
- /// <returns></returns>
- public bool SetGain(float Gain)
- {
- //_operationSemaphore.Wait();
- //try
- //{
- // if (!mvCameraAcq.bIsOpened)
- // return false;
- // mvCameraAcq.AnalogGain = (double)Gain;
- // return true;
- //}
- //finally
- //{
- // _operationSemaphore.Release();
- //}
- return true;
- }
- /// <summary>
- /// 获取增益
- /// </summary>
- /// <returns></returns>
- public float GetGain()
- {
- //_operationSemaphore.Wait();
- //try
- //{
- // if (!mvCameraAcq.bIsOpened)
- // return 0;
- // return (float)mvCameraAcq.AnalogGain;
- //}
- //finally
- //{
- // _operationSemaphore.Release();
- //}
- return 0;
- }
- private void GetStreamThreadProc()
- {
- while (IsGrabbing)
- {
- try
- {
- Grab();
- ImageCallbackEvent?.Invoke(Image, TotalTime, ErrorMessage,ID);
- }
- catch (Exception)
- {
- }
- Thread.Sleep(10);
- }
- IsGrabbing = false;
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="nProfileWidth">单条轮廓宽度数据 / Returns a single contour width data</param>
- /// <param name="nHighlen">返回的批处理行数 / The number of rows in the batch returned</param>
- /// <param name="nFlag">回调函数执行状态,根据不同模式自定义 / Callback function execution status, customized according to different modes</param>
- /// <param name="nStatusCode">错误码,0无错误 / Error code, 0 no error</param>
- /// <param name="ProfileBits">Sync callback 0:32bit data, 1:16bit data</param>
-
- public void GetDataCallBack(int nProfileWidth, int nHighlen, int nFlag, int nStatusCode, int ProfileBits)
- {
- profile16Bits = (uint)ProfileBits;
- if (nStatusCode == 0)
- {
- Console.WriteLine($"Into GetDataFunc W:{nProfileWidth},H:{nHighlen},ErrCode:{nStatusCode}({GetSDKErrMsgByCode(nStatusCode)})");
- //这里拿到相机数据做显示,可以根据其他具体业务实现自己的逻辑
- //The camera data is obtained here for display, and you can implement your own logic according to other specific businesses
- int nTempWidth = nProfileWidth;// iSR7APi.GetProfileDataWidth();
- //双相机时,一次回调和异步回调nProfileWidth=3200,无限循环回调nProfileWidth=6400
- //For dual cameras, nProfileWidth=3200 for one-time callback and asynchronous callback, and nProfileWidth=6400 for infinite loop callback
- //if (iSR7APi.CameraBOnline && m_callbackMode == 2)//双相机 / dual camera
- // nTempWidth /= 2;
- int offset = coutCallbackPoints * nTempWidth;
- //int offset = 0;
- //iSR7APi.BatchPoints = nHighlen;
- SImagePro.SPointCloudHead pcHead = new SImagePro.SPointCloudHead(0, 0, 0, 0, 0);
- pcHead.width = (uint)nTempWidth;
- pcHead.height = (uint)iSR7APi.BatchPoints;
- pcHead.xInterval = iSR7APi.GetProfileData_XPitch();
- pcHead.yInterval = iSR7APi.GetProfileData_XPitch();
- //if (coutCallbackPoints != coutCallbackPoints_B)
- //{
-
- InitImageBufferMem(iSR7APi.CameraAOnline, nProfileWidth, iSR7APi.BatchPoints);
- // //ShowRGBImage(ImgBuff32[0], pcHead, pictureBoxA);
- //}
- //else if(coutCallbackPoints==0)
- //{
- // InitImageBufferMem(iSR7APi.CameraAOnline, nProfileWidth, iSR7APi.BatchPoints);
- //}
- // coutCallbackPoints_B = coutCallbackPoints;
- if (ProfileBits == 0)
- {
- //nHighlen = iSR7APi.BatchPoints;
- int[] tempHeightDataA = new int[nTempWidth * nHighlen];
- byte[] tempGrayDataA = new byte[nTempWidth * nHighlen];
- iSR7APi.GetData(tempHeightDataA, tempGrayDataA, Encoder[0], (int)pcHead.width, (int)nHighlen, 0);
- Array.Copy(tempHeightDataA, 0, ImgBuff32[0], 0, nTempWidth * nHighlen);
- Array.Copy(tempGrayDataA, 0, GrayBuff[0], 0, nTempWidth * nHighlen);
-
- if (ImgBuff32 != null && ImgBuff32.Length != 0 && ImgBuff32[0] != null)
- {
- //ShowRGBImage(ImgBuff32[0], pcHead, pictureBoxA);
- CogImage16Range cogImage16Range = SSZNCognexParser.SSZNParser.LoadSSZN3DImage(ImgBuff32[0], (int)pcHead.width, (int)pcHead.height, pcHead.xInterval, pcHead.yInterval);
- Image = cogImage16Range;
- CameraRevFinish = true;
- ImageCallbackEvent?.Invoke(Image, TotalTime, ErrorMessage, ID);
- }
-
-
- }
- else
- {
- short[] temp16bitDataA = new short[nTempWidth * nHighlen];
- byte[] tempGrayDataA = new byte[nTempWidth * nHighlen];
- iSR7APi.GetData(temp16bitDataA, tempGrayDataA, Encoder[0], (int)pcHead.width, (int)nHighlen, 0);
- Array.Copy(temp16bitDataA, 0, ImgBuff16[0], offset, nTempWidth * nHighlen);
- Array.Copy(tempGrayDataA, 0, GrayBuff[0], offset, nTempWidth * nHighlen);
- int[] showtemp16bitDataA = new int[pcHead.width * pcHead.height];
- //ShowTiff16Data(ImgBuff16[0], showtemp16bitDataA);
- if (ImgBuff16 != null && ImgBuff16.Length != 0 && ImgBuff16[0] != null)
- {
- //ShowRGBImage(showtemp16bitDataA, pcHead, pictureBoxA);
- }
- }
- if (iSR7APi.CameraBOnline && ImgBuff32[1] != null)
- {
- if (ProfileBits == 0)
- {
- int[] tempHeightDataB = new int[nTempWidth * nHighlen];
- byte[] tempGrayDataB = new byte[nTempWidth * nHighlen];
- iSR7APi.GetData(tempHeightDataB, tempGrayDataB, Encoder[1], (int)pcHead.width, (int)nHighlen, 1);
- Array.Copy(tempHeightDataB, 0, ImgBuff32[1], offset, nTempWidth * nHighlen);
- Array.Copy(tempGrayDataB, 0, GrayBuff[1], offset, nTempWidth * nHighlen);
- //ShowRGBImage(ImgBuff32[1], pcHead, pictureBoxB);
- }
- else
- {
- short[] tempHeightDataB = new short[nTempWidth * nHighlen];
- byte[] tempGrayDataB = new byte[nTempWidth * nHighlen];
- iSR7APi.GetData(tempHeightDataB, tempGrayDataB, Encoder[1], (int)pcHead.width, (int)nHighlen, 1);
- Array.Copy(tempHeightDataB, 0, ImgBuff16[1], offset, nTempWidth * nHighlen);
- Array.Copy(tempGrayDataB, 0, GrayBuff[1], offset, nTempWidth * nHighlen);
- int[] showtemp16bitDataB = new int[pcHead.width * pcHead.height];
- //ShowTiff16Data(ImgBuff16[1], showtemp16bitDataB);
- //ShowRGBImage(showtemp16bitDataB, pcHead, pictureBoxB);
- }
- }
- coutCallbackPoints += nHighlen;
-
- }
- else
- {
- Console.WriteLine($"Data CallBack Exception:{nStatusCode}({GetSDKErrMsgByCode(nStatusCode)})");
-
- }
- }
- public void ErrConnectFunc(int dwDeviceId, int nErrCode)
- {
- LogHelper.WriteLogInfo($"Into ConnectExceptionCallback Error Code: {nErrCode}{GetSDKErrMsgByCode(nErrCode)}");
- iSR7APi.CameraAOnline = false;
- iSR7APi.CameraBOnline = false;
- //:1:Data overflow,3:Disconnect, 4:Wrong version
- //Non-asynchronous mode: -1 represents a general error, such as link failure, setup failure, data acquisition failure, etc., -1000;
- switch (nErrCode)
- {
- case 1:
- LogHelper.WriteLogInfo($"Into ConnectExceptionCallback Error Code: {nErrCode}{srcsharpTools.GetTranslation("CAMERA_EXCEPTION_1")}");
- break;
- case 3:
- LogHelper.WriteLogInfo($"Into ConnectExceptionCallback Error Code: {nErrCode}{srcsharpTools.GetTranslation("CAMERA_EXCEPTION_3")}");
- break;
- case 4:
- LogHelper.WriteLogInfo($"Into ConnectExceptionCallback Error Code: {nErrCode}{srcsharpTools.GetTranslation("CAMERA_EXCEPTION_3")}");
- break;
- case -1:
- LogHelper.WriteLogInfo($"Into ConnectExceptionCallback Error Code: {nErrCode}{srcsharpTools.GetTranslation("CAMERA_EXCEPTION_N1")}");
- break;
- default:
- break;
- }
- }
- public string GetSDKErrMsgByCode(int nErrCode)
- {
- string strErrMsg;
- switch ((SR7Link.SR7IF_ERROR)nErrCode)
- {
- case SR7IF_ERROR.SR7IF_ERROR_NOT_FOUND: strErrMsg = srcsharpTools.GetTranslation("SR7IF_ERROR_NOT_FOUND"); break;
- case SR7IF_ERROR.SR7IF_ERROR_COMMAND: strErrMsg = srcsharpTools.GetTranslation("SR7IF_ERROR_COMMAND"); break;
- case SR7IF_ERROR.SR7IF_ERROR_PARAMETER: strErrMsg = srcsharpTools.GetTranslation("SR7IF_ERROR_PARAMETER"); break;
- case SR7IF_ERROR.SR7IF_ERROR_UNIMPLEMENTED: strErrMsg = srcsharpTools.GetTranslation("SR7IF_ERROR_UNIMPLEMENTED"); break;
- case SR7IF_ERROR.SR7IF_ERROR_HANDLE: strErrMsg = srcsharpTools.GetTranslation("SR7IF_ERROR_HANDLE"); break;
- case SR7IF_ERROR.SR7IF_ERROR_MEMORY: strErrMsg = srcsharpTools.GetTranslation("SR7IF_ERROR_MEMORY"); break;
- case SR7IF_ERROR.SR7IF_ERROR_TIMEOUT: strErrMsg = srcsharpTools.GetTranslation("SR7IF_ERROR_TIMEOUT"); break;
- case SR7IF_ERROR.SR7IF_ERROR_DATABUFFER: strErrMsg = srcsharpTools.GetTranslation("SR7IF_ERROR_DATABUFFER"); break;
- case SR7IF_ERROR.SR7IF_ERROR_STREAM: strErrMsg = srcsharpTools.GetTranslation("SR7IF_ERROR_STREAM"); break;
- case SR7IF_ERROR.SR7IF_ERROR_CLOSED: strErrMsg = srcsharpTools.GetTranslation("SR7IF_ERROR_CLOSED"); break;
- case SR7IF_ERROR.SR7IF_ERROR_VERSION: strErrMsg = srcsharpTools.GetTranslation("SR7IF_ERROR_VERSION"); break;
- case SR7IF_ERROR.SR7IF_ERROR_ABORT: strErrMsg = srcsharpTools.GetTranslation("SR7IF_ERROR_ABORT"); break;
- case SR7IF_ERROR.SR7IF_ERROR_ALREADY_EXISTS: strErrMsg = srcsharpTools.GetTranslation("SR7IF_ERROR_ALREADY_EXISTS"); break;
- case SR7IF_ERROR.SR7IF_ERROR_FRAME_LOSS: strErrMsg = srcsharpTools.GetTranslation("SR7IF_ERROR_FRAME_LOSS"); break;
- case SR7IF_ERROR.SR7IF_ERROR_ROLL_DATA_OVERFLOW: strErrMsg = srcsharpTools.GetTranslation("SR7IF_ERROR_ROLL_DATA_OVERFLOW"); break;
- case SR7IF_ERROR.SR7IF_ERROR_ROLL_BUSY: strErrMsg = srcsharpTools.GetTranslation("SR7IF_ERROR_ROLL_BUSY"); break;
- case SR7IF_ERROR.SR7IF_ERROR_MODE: strErrMsg = srcsharpTools.GetTranslation("SR7IF_ERROR_MODE"); break;
- case SR7IF_ERROR.SR7IF_ERROR_CAMERA_NOT_ONLINE: strErrMsg = srcsharpTools.GetTranslation("SR7IF_ERROR_CAMERA_NOT_ONLINE"); break;
- case SR7IF_ERROR.SR7IF_ERROR: strErrMsg = srcsharpTools.GetTranslation("SR7IF_ERROR"); break;
- case SR7IF_ERROR.SR7IF_NORMAL_STOP: strErrMsg = srcsharpTools.GetTranslation("SR7IF_NORMAL_STOP"); break;
- case SR7IF_ERROR.SR7IF_OK: strErrMsg = ""; break;
- default:
- strErrMsg = "";
- break;
- }
- return strErrMsg;
- }
- #endregion
- #region 属性通知
- /// <summary>
- /// Occurs when a property value changes.
- /// </summary>
- public event PropertyChangedEventHandler PropertyChanged;
- /// <summary>
- /// Checks if a property already matches a desired value. Sets the property and
- /// notifies listeners only when necessary.
- /// </summary>
- /// <typeparam name="T">Type of the property.</typeparam>
- /// <param name="storage">Reference to a property with both getter and setter.</param>
- /// <param name="value">Desired value for the property.</param>
- /// <param name="propertyName">Name of the property used to notify listeners. This
- /// value is optional and can be provided automatically when invoked from compilers that
- /// support CallerMemberName.</param>
- /// <returns>True if the value was changed, false if the existing value matched the
- /// desired value.</returns>
- protected virtual bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
- {
- if (EqualityComparer<T>.Default.Equals(storage, value)) return false;
- storage = value;
- RaisePropertyChanged(propertyName);
- return true;
- }
- /// <summary>
- /// Checks if a property already matches a desired value. Sets the property and
- /// notifies listeners only when necessary.
- /// </summary>
- /// <typeparam name="T">Type of the property.</typeparam>
- /// <param name="storage">Reference to a property with both getter and setter.</param>
- /// <param name="value">Desired value for the property.</param>
- /// <param name="propertyName">Name of the property used to notify listeners. This
- /// value is optional and can be provided automatically when invoked from compilers that
- /// support CallerMemberName.</param>
- /// <param name="onChanged">Action that is called after the property value has been changed.</param>
- /// <returns>True if the value was changed, false if the existing value matched the
- /// desired value.</returns>
- protected virtual bool SetProperty<T>(ref T storage, T value, Action onChanged, [CallerMemberName] string propertyName = null)
- {
- if (EqualityComparer<T>.Default.Equals(storage, value)) return false;
- storage = value;
- onChanged?.Invoke();
- RaisePropertyChanged(propertyName);
- return true;
- }
- /// <summary>
- /// Raises this object's PropertyChanged event.
- /// </summary>
- /// <param name="propertyName">Name of the property used to notify listeners. This
- /// value is optional and can be provided automatically when invoked from compilers
- /// that support <see cref="CallerMemberNameAttribute"/>.</param>
- protected void RaisePropertyChanged([CallerMemberName] string propertyName = null)
- {
- OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
- }
- /// <summary>
- /// Raises this object's PropertyChanged event.
- /// </summary>
- /// <param name="args">The PropertyChangedEventArgs</param>
- protected virtual void OnPropertyChanged(PropertyChangedEventArgs args)
- {
- PropertyChanged?.Invoke(this, args);
- }
- #endregion
- }
- }
|