Ejemplo n.º 1
0
        /// <summary>
        /// 回调方式获取数据
        /// </summary>
        public void DataCallBackReceiveFun()
        {
            if (!Connected)
            {
                return;
            }

            if (_heightData != null)
            {
                for (var i = 0; i < _heightData.Length; i++)
                {
                    _heightData[i] = -1000000;
                }
            }

            //开始批处理
            var _currentDeviceId = 0;
            var rc         = -1;
            var dataObject = new IntPtr();

            rc = _bIoTrigger ? SR7LinkFunc.SR7IF_StartIOTriggerMeasure(_currentDeviceId, 20000, 0) : SR7LinkFunc.SR7IF_StartMeasure(_currentDeviceId, 20000);

            if (rc < 0)
            {
                var t3X1 = "批处理操作失败,返回值:" + rc.ToString();
                MessageBox.Show(t3X1, @"提示", MessageBoxButtons.OK);
                return;
            }

            // 获取批处理总行数
            var tempBatchPoint = SR7LinkFunc.SR7IF_ProfilePointSetCount(_currentDeviceId, dataObject);

            // 获取轮廓宽度
            _mDataWidth = SR7LinkFunc.SR7IF_ProfileDataWidth(_currentDeviceId, dataObject);

            // 数据x方向间距(mm)
            _mXPitch = SR7LinkFunc.SR7IF_ProfileData_XPitch(_currentDeviceId, dataObject);

            var tmt = "";
            var tx1 = "批处理行数:" + tempBatchPoint;
            var tx2 = "轮廓宽度:" + _mDataWidth;
            var tx3 = "数据x方向间距(mm):" + _mXPitch;

            tmt = tx1 + "\r\n" + tx2 + "\r\n" + tx3;
        }
Ejemplo n.º 2
0
        public int DisConnect(int deviceId)
        {
            if (Connected)
            {
                var rc = SR7LinkFunc.SR7IF_CommClose(deviceId);
                if (rc < 0)
                {
                    MessageBox.Show(@"设备断开失败!");
                    return(rc);
                }

                Connected = false;
                return(rc);
            }

            MessageBox.Show(@"未连接该设备!");
            return(-1);
        }
Ejemplo n.º 3
0
        public int Connect(int deviceId, SR7IF_ETHERNET_CONFIG ethernetConfig)
        {
            var rc = SR7LinkFunc.SR7IF_EthernetOpen(deviceId, ref ethernetConfig);

            EthernetConfig = ethernetConfig;
            DeviceId       = deviceId;
            if (rc < 0)
            {
                MessageBox.Show(@"设备连接失败!");
                Connected = false;
            }
            else
            {
                MessageBox.Show(@"设备连接成功!");
                Connected = true;
                //获取型号判断高度范围
                var strModel = SR7LinkFunc.SR7IF_GetModels(deviceId);
                var sModel   = Marshal.PtrToStringAnsi(strModel);
                HeightRange = sModel switch
                {
                    "SR7050" => 2.5,
                    "SR7080" => 6,
                    "SR7140" => 12,
                    "SR7240" => 20,
                    "SR7400" => 50,
                    _ => 8.4
                };


                var reT = SR7LinkFunc.SR7IF_HighSpeedDataEthernetCommunicationInitalize(deviceId,
                                                                                        ref ethernetConfig,
                                                                                        0,
                                                                                        _callback,
                                                                                        dwProfileCnt,
                                                                                        0);
            }

            return(rc);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 回调接受数据
        /// </summary>
        /// <param name="buffer"></param>         指向储存概要数据的缓冲区的指针.
        /// <param name="size"></param>           每个单元(行)的字节数量.
        /// <param name="count"></param>          存储在pBuffer中的内存的单元数量.
        /// <param name="notify"></param>         中断或批量结束等中断的通知.
        /// <param name="user"></param>           用户自定义信息.
        public void ReceiveHighSpeedData(IntPtr buffer, uint size, uint count, uint notify, uint user)
        {
            if (notify != 0)
            {
                if (Convert.ToBoolean(notify & 0x08))
                {
                    SR7LinkFunc.SR7IF_StopMeasure(0);
                    System.Console.Write(@"批处理超时!\n");
                    MessageBox.Show(@"批处理超时", @"提示", MessageBoxButtons.OK);
                    _mCurBatchNo = 0;
                }
            }

            if (count == 0 || size == 0)
            {
                return;
            }
            var profileSize = (uint)(size / Marshal.SizeOf(typeof(int))); //轮廓宽度
            // 获取批处理总行数
            var dataObject     = new IntPtr();
            var tempBatchPoint = SR7LinkFunc.SR7IF_ProfilePointSetCount(0, dataObject);

            _batchCallBackPoint = tempBatchPoint;
            _mBatchWidth        = Convert.ToInt32(profileSize);

            //数据拷贝
            var bufferArray = new int[profileSize * count];

            Marshal.Copy(buffer, bufferArray, 0, (int)(profileSize * count));
            var tmpNum = Convert.ToInt32(_mCurBatchNo * profileSize);

            if (_mCurBatchNo >= _batchCallBackPoint)
            {
                return;
            }
            if (_mCurBatchNo + count > _batchCallBackPoint)
            {
                var tmpCount = _batchCallBackPoint - _mCurBatchNo;
                Array.Copy(bufferArray, 0, _heightData, tmpNum, count * tmpCount);
                GC.Collect();
            }
            else
            {
                Array.Copy(bufferArray, 0, _heightData, tmpNum, profileSize * Convert.ToInt32(count));
                GC.Collect();
            }
            _mCurBatchNo += Convert.ToInt32(count);

            _bCall = true;

            if (notify == 0)
            {
                return;
            }
            if (notify == 0x10000)
            {
                SR7LinkFunc.SR7IF_StopMeasure(0);
                System.Console.Write(@"数据接收完成!\n");
                _bCall       = false;
                _mCurBatchNo = 0;
                var tmpys = (int)(Convert.ToDouble(_batchCallBackPoint) / 560); //Y方向缩放倍数
                var tmpxs = (int)(Convert.ToDouble(_mBatchWidth) / 800);        //X方向缩放倍数
                if (_batchCallBackPoint < 560)
                {
                    tmpys = 1;
                }
                if (_mBatchWidth < 800)
                {
                    tmpxs = 1;
                }

                _bCall = false;
                _bStop = false;
                BatchDataRollShow(_heightData, HeightRange, -HeightRange, 255, _mBatchWidth, _batchCallBackPoint,
                                  tmpxs, tmpys); //显示高度数据
            }
            if (Convert.ToBoolean(notify & 0x80000000))
            {
                System.Console.Write(@"批处理重新开始!\n");
                _mCurBatchNo = 0;
            }

            if (Convert.ToBoolean(notify & 0x04))
            {
                System.Console.Write(@"新批处理!\n");
            }
        }