Example #1
0
        public bool StopCurrentImage()
        {
            int tmpStatus = status & ObjectLJV7.STATUS.CURRENTIMAGE;

            buffer_set.Clear();
            _FrameData = null;

            if (tmpStatus == 0)
            {
                MessageBox.Show("即時影像模式尚未開啟");
                return(false);
            }
            //未開高速模式才需要關閉機器
            tmpStatus = status & ObjectLJV7.STATUS.STARTHIGHTSPEED;
            if (tmpStatus == 0)
            {
                if (StopGetValue() == false)
                {
                    return(false);
                }
            }
            if (SetContinue(TriggerMode.External) == false)
            {
                return(false);
            }

            status &= ~ObjectLJV7.STATUS.CURRENTIMAGE;
            return(true);
        }
Example #2
0
        public bool StartCurrentImage(ushort highSpeedPort, byte bySendPos, uint frequency)
        {
            int tmpStatus = status & ObjectLJV7.STATUS.CURRENTIMAGE;

            if (tmpStatus > 0)
            {
                MessageBox.Show("即時影像模式已開啟");
                return(false);
            }
            //未開高速模式才需要開啟機器
            tmpStatus = status & ObjectLJV7.STATUS.STARTHIGHTSPEED;
            if (tmpStatus == 0)
            {
                if (SetContinue(TriggerMode.Continuous) == false)
                {
                    return(false);
                }
                if (StartGetValue(highSpeedPort, bySendPos, frequency) == false)
                {
                    return(false);
                }
            }
            else
            {
                buffer_set.Clear();
                _FrameData = null;
                MessageBox.Show("高速模式下,無法開啟即時影像模式");
                return(false);
            }

            status |= ObjectLJV7.STATUS.CURRENTIMAGE;
            return(true);
        }
Example #3
0
            public static void DoWriteFile(FrameData_LJV7 frame, string filepath)
            {
                ThreadWriteFile writer = new ThreadWriteFile();

                writer.frame    = frame;
                writer.filepath = filepath;
                writer.DoWriteFile();
            }
Example #4
0
        public static FrameData_LJV7 DoReadByteFile(string filepath)
        {
            FrameData_LJV7 frame = new FrameData_LJV7();

            frame.Max_Buffer_Compute = -999;
            frame.Min_Buffer_Compute = 999;

            frame.LJVcount       = FrameData_LJV7._DATASETSIZE;
            frame.size_per_frame = FrameData_LJV7._COMPUTESIZE;
            try
            {
                frame.buffer_compute = new float[frame.LJVcount * frame.size_per_frame];
                byte[] buffer = new byte[frame.buffer_compute.Length * sizeof(float)];

                // Open file for reading
                System.IO.FileStream FileStream = new System.IO.FileStream(filepath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                FileStream.Read(buffer, 0, buffer.Length);
                // close file stream
                FileStream.Close();


                Buffer.BlockCopy(buffer, 0, frame.buffer_compute, 0, buffer.Length);
                //ThreadWriteFile.DoWriteFile(frame, filepath + ".csv"); //for test

                //計算最大與最小
                for (int i = 0; i < frame.buffer_compute.Length; i++)
                {
                    if (frame.buffer_compute[i] == -999)
                    {
                        continue;
                    }
                    if (frame.buffer_compute[i] > frame.Max_Buffer_Compute)
                    {
                        frame.Max_Buffer_Compute = frame.buffer_compute[i];
                    }
                    else if (frame.buffer_compute[i] < frame.Min_Buffer_Compute)
                    {
                        frame.Min_Buffer_Compute = frame.buffer_compute[i];
                    }
                }

                FileStream = null;
                buffer     = null;
                return(frame);
            }
            catch (Exception _Exception)
            {
                // Error
                Console.WriteLine("Exception caught in process: {0}", _Exception.Message);
            }
            return(null);
        }
Example #5
0
        public void getLaserReveiced()
        {
            int tmpStatus = status & ObjectLJV7.STATUS.STARTHIGHTSPEED;

            if (tmpStatus == 0)
            {
                Console.WriteLine(DateTime.Now.TimeOfDay + ": getLaserReveiced-尚未開啟高速模式");
                return;
            }
            if (_FrameData != null)
            {
                Console.WriteLine(DateTime.Now.TimeOfDay + ": 遺失資料(上一筆資料尚未收畢) " + ProgressCounter);
                return;
            }

            Console.WriteLine(DateTime.Now.TimeOfDay + ": 開始取資料 " + ProgressCounter);
            _FrameData = new FrameData_LJV7();
            buffer_set.Clear();
        }
Example #6
0
        public static FrameData_LJV7 DoReadPreByteFile(string filepath)
        {
            FrameData_LJV7 frame = new FrameData_LJV7();

            frame.LJVcount       = FrameData_LJV7._DATASETSIZE;
            frame.size_per_frame = 0;
            try
            {
                // Open file for reading
                System.IO.FileStream FileStream = new System.IO.FileStream(filepath, System.IO.FileMode.Open, System.IO.FileAccess.Read);

                List <byte> buffer     = new List <byte>();
                byte[]      buffer_tmp = new byte[frame.LJVcount * sizeof(int)];
                while (FileStream.Read(buffer_tmp, 0, buffer_tmp.Length) > 0)
                {
                    buffer.AddRange(buffer_tmp);
                    frame.size_per_frame++;
                }
                // close file stream
                FileStream.Close();

                byte[] buffer_all = buffer.ToArray();
                frame.buffer = new int[frame.LJVcount * frame.size_per_frame];
                Buffer.BlockCopy(buffer_all, 0, frame.buffer, 0, buffer_all.Length);
                //ThreadWriteFile.DoWriteFile(frame, filepath + ".csv"); //for test

                FileStream = null;
                buffer     = null;
                return(frame);
            }
            catch (Exception _Exception)
            {
                // Error
                Console.WriteLine("Exception caught in process: {0}", _Exception.Message);
            }
            return(null);
        }
Example #7
0
        private void ReceiveData(IntPtr buffer, uint size, uint count, uint notify, uint user)
        {
            uint profileSize = size / sizeof(int);

            if (FrameData_LJV7._PROFILESIZE != profileSize)
            {
                FrameData_LJV7._PROFILESIZE = profileSize;
            }

            //Console.WriteLine(DateTime.Now.TimeOfDay + ": " + profileSize + "," + count + ", " + notify + ", " + user + ", " + buffer_set.Count);

            //notify:
            //p22: 8.3.1.1 dwNotify parameter
            //bit 0: Continuous send was stopped (stop by command)
            //bit 1~3: Continuous send was stopped (automatic stop)
            //bit 8: Send interrupted by clear memory
            //bit 16, 31: Finished sending the batch measurement amount of data
            int t = Convert.ToInt32(notify) & 0x0E;

            //自動停止時要進行自動連線
            if (t > 0 && _errorback != null)
            {
                _errorback(this, Convert.ToInt32(notify));
            }
            if (count == 0 || notify > 0)
            {
                return;
            }

            //目前只開放高速模式和即時影像,及資料尚未收集完畢
            int tmpStatus = status & (ObjectLJV7.STATUS.STARTHIGHTSPEED | ObjectLJV7.STATUS.CURRENTIMAGE);

            if (tmpStatus == 0)
            {
                return;
            }

            Marshal.Copy(buffer, buffer_tmp, 0, Convert.ToInt32(profileSize * count));
            //callback to caller
            if (_receiveback != null)
            {
                //即時模式,回傳並進行繪製即時圖片
                _receiveback(buffer_tmp, profileSize, count);
            }

            //具有高速模式,才需要組合資料,否則直接離開
            tmpStatus = status & ObjectLJV7.STATUS.STARTHIGHTSPEED;
            if (tmpStatus > 0)
            {
                buffer_set.AddRange(buffer_tmp);
            }
            else
            {
                return;
            }

            tmpStatus = status & ObjectLJV7.STATUS.CURRENTIMAGE;
            if (tmpStatus == 0)
            {
                //純高速測試模式,檢查資料起頭
                int headindex = -1;

                /*if (buffer_tmp[0] == 0x42)
                 * {
                 *  Console.WriteLine("資料起頭");
                 *  buffer_set.Clear();
                 * }*/

                //*
                for (int i = 0; i < count; i++)
                {
                    if (buffer_tmp[i * profileSize] == 0x42)
                    {
                        headindex = i;
                        Console.WriteLine("資料起頭: " + headindex);
                        //buffer_set.Clear();
                        break;
                    }
                }//*/

                if (headindex > 0)
                {
                    //若目前資料有資料起頭,移除起頭前的資料
                    //有效資料數: buffer_tmp.Length - headindex
                    buffer_set.RemoveRange(0, buffer_set.Count - (buffer_tmp.Length - headindex));
                }
            }

            //資料未收集完畢,直接離開
            if (buffer_set.Count < FrameData_LJV7._DATASETSIZE * FrameData_LJV7._PROFILESIZE)
            {
                return;
            }
            else if (buffer_set.Count > FrameData_LJV7._DATASETSIZE * FrameData_LJV7._PROFILESIZE)
            {
                //超出,則刪除前面不需測試的資料
                buffer_set.RemoveRange(0, Convert.ToInt32(buffer_set.Count - FrameData_LJV7._DATASETSIZE * FrameData_LJV7._PROFILESIZE));
            }
            //buffer_set.Count == ErrorDetector._DATASETSIZE * ErrorDetector._PROFILESIZE

            tmpStatus = status & ObjectLJV7.STATUS.CURRENTIMAGE;
            if (tmpStatus == 0)
            {
                //純高速測試模式,檢測收到的單筆資料
                lock (ReceivedFIFOLock)
                {
                    //複製buffer_tmp至FIFO
                    _ReceivedFIFO.Add(buffer_set.ToArray());
                    buffer_set.Clear();
                }
                return;
            }

            //即時影像模式時,若啟動高速模式,可收集資料並進行測試(可透過PLC觸發, getLaserReveiced)
            if (_FrameData == null)
            {
                return;
            }
            _FrameData.buffer = buffer_set.ToArray();
            _FrameData.count  = FrameData_LJV7._DATASETSIZE;
            if (_collectback != null)
            {
                _collectback(_FrameData);
            }
            _FrameData = null;
            buffer_set.Clear();
        }