コード例 #1
0
        private void OnDataReceived(KObject data)
        {
            //处理速度

            //On data Receive
            _syncContext.Post(new SendOrPostCallback(delegate { updateMsg("DataCount:" + count.ToString()); }), null);
            _syncContext.Post(new SendOrPostCallback(delegate
            {
                updateMsg("Data received" + timeStamp() + "   DataCount:" + count.ToString());
                if (count == 51)
                {
                    updateMsg("Data Stream will end");
                }
                count++;
            }), null);


            //get profile data

            _dataSource = (GoDataSet)data;
            for (UInt32 i = 0; i < _dataSource.Count; i++)
            {
                GoDataMsg dataObj = (GoDataMsg)_dataSource.Get(i);
                switch (dataObj.MessageType)
                {
                case GoDataMessageType.ResampledProfile:
                {
                    GoResampledProfileMsg profileMsg = (GoResampledProfileMsg)dataObj;
                    _dataContext.xResolution = (double)profileMsg.XResolution / 1000000;
                    _dataContext.zResolution = (double)profileMsg.ZResolution / 1000000;
                    _dataContext.xOffset     = (double)profileMsg.XOffset / 1000;
                    _dataContext.zOffset     = (double)profileMsg.ZOffset / 1000;
                    _profileShape.width      = profileMsg.Width;
                    _profileShape.size       = profileMsg.Size;
                    //generate csv file for point data save
                    sb.Clear();
                    if (!File.Exists(filePath))
                    {
                        sb.Append("Index,");
                        for (int k = 0; k < _profileShape.width; k++)
                        {
                            sb.Append(k.ToString() + ",");
                        }
                        File.AppendAllText(filePath, sb.ToString());
                        //updateMsg("Create file sucessfully");
                        sb.Clear();
                    }
                    short[]        points        = new short[_profileShape.width];
                    ProfilePoint[] profileBuffer = new ProfilePoint[_profileShape.width];
                    IntPtr         pointsPtr     = profileMsg.Data;
                    Marshal.Copy(pointsPtr, points, 0, points.Length);

                    for (UInt32 arrayIndex = 0; arrayIndex < _profileShape.width; ++arrayIndex)
                    {
                        if (points[arrayIndex] != -32768)
                        {
                            profileBuffer[arrayIndex].x = Resolution2Value(_dataContext.xResolution, _dataContext.xOffset, arrayIndex);
                            profileBuffer[arrayIndex].z = Resolution2Value(_dataContext.zResolution, _dataContext.zOffset, points[arrayIndex]);
                        }
                        else
                        {
                            profileBuffer[arrayIndex].x = Resolution2Value(_dataContext.xResolution, _dataContext.xOffset, arrayIndex);
                            profileBuffer[arrayIndex].z = -32768;
                        }

                        //Get Value   save to file
                        sb.Append(index.ToString() + ",");
                        index++;
                        sb.Append("x:" + profileBuffer[arrayIndex].x.ToString() + "#" + "z:" + profileBuffer[arrayIndex].z.ToString() + ",");
                    }

                    sb.Append(Environment.NewLine);
                    // write to file
                    File.AppendAllText(filePath, sb.ToString());
                }
                break;

                default: break;
                }
            }
        }
コード例 #2
0
        void ProfileProcessingFunc(KObject data, int dataQuene)
        {
            GoDataSet _dataSource = new GoDataSet();

            _dataSource = (GoDataSet)data;
            DataContext   _dataContext  = new DataContext();
            ProfileShape  _profileShape = new ProfileShape();
            StringBuilder sb            = new StringBuilder();
            StringBuilder rawSb         = new StringBuilder();

            for (UInt32 i = 0; i < _dataSource.Count; i++)
            {
                GoDataMsg dataObj = (GoDataMsg)_dataSource.Get(i);
                switch (dataObj.MessageType)
                {
                case GoDataMessageType.ResampledProfile:
                {
                    GoResampledProfileMsg profileMsg = (GoResampledProfileMsg)dataObj;
                    _dataContext.xResolution = (double)profileMsg.XResolution / 1000000;
                    _dataContext.zResolution = (double)profileMsg.ZResolution / 1000000;
                    _dataContext.xOffset     = (double)profileMsg.XOffset / 1000;
                    _dataContext.zOffset     = (double)profileMsg.ZOffset / 1000;
                    _profileShape.width      = profileMsg.Width;
                    _profileShape.size       = profileMsg.Size;
                    //generate csv file for point data save
                    short[]        points        = new short[_profileShape.width];
                    ProfilePoint[] profileBuffer = new ProfilePoint[_profileShape.width];
                    IntPtr         pointsPtr     = profileMsg.Data;
                    Marshal.Copy(pointsPtr, points, 0, points.Length);

                    for (UInt32 arrayIndex = 0; arrayIndex < _profileShape.width; ++arrayIndex)
                    {
                        if (points[arrayIndex] != -32768)
                        {
                            profileBuffer[arrayIndex].x = _dataContext.xOffset + _dataContext.xResolution * arrayIndex;
                            profileBuffer[arrayIndex].z = _dataContext.zOffset + _dataContext.zResolution * points[arrayIndex];
                        }
                        else
                        {
                            profileBuffer[arrayIndex].x = _dataContext.xOffset + _dataContext.xResolution * arrayIndex;
                            profileBuffer[arrayIndex].z = -32768;
                        }

                        zValueList.Add(profileBuffer[arrayIndex].z);
                    }


                    sb.Clear();


                    if (!File.Exists(filePath))
                    {
                        sb.Append("Index,");

                        for (int k = 0; k < profileBuffer.Length; k++)
                        {
                            sb.Append(profileBuffer[k].x.ToString() + ",");
                        }
                        sb.Append(Environment.NewLine);
                        File.AppendAllText(filePath, sb.ToString());
                        //updateMsg("Create file sucessfully");
                        sb.Clear();
                    }

                    sb.Append(dataQuene.ToString() + ",");
                    //Get Value   save to file
                    for (int k = 0; k < profileBuffer.Length; k++)
                    {
                        sb.Append(profileBuffer[k].z.ToString() + ",");
                    }
                    sb.Append(Environment.NewLine);
                    // write to file
                    File.AppendAllText(filePath, sb.ToString());
                    sb.Clear();
                }
                break;

                default: break;
                }
            }
        }