Multithread and Circle Buffer Technique Applied in The Online Inspection of Raw Silk Size

Multithread and Circle Buffer Technique Applied in The Online Inspection of Raw Silk Size

Available online at www.sciencedirect.com Available online at www.sciencedirect.com Procedia Engineering Procedia Engineering 00 (2011)23000–000 Pro...

213KB Sizes 0 Downloads 32 Views

Available online at www.sciencedirect.com Available online at www.sciencedirect.com

Procedia Engineering

Procedia Engineering 00 (2011)23000–000 Procedia Engineering (2011) 521 – 524 www.elsevier.com/locate/procedia

PEEA 2011

Multithread and circle buffer technique applied in the online inspection of raw silk size Zhenhai Huanga, Baoquan Chib,Suozhuai Dongc Guirong Wangd,Hong Xue a,b,d,e

College of electrical & Mechanical Engineering, China Jiliang University,Hangzhou 310018,china c Zhejiang entrance and exit to the inspection and quarantine burea

Abstract For the question of losing data when large amounts of data fasting calculation while fasting acquisition in raw silk inspection, it is proposed in this paper that multithread and circle buffer technique are used to solve the question. The calculation of raw silk size, the algorithm of the defect classing, the data acquisition and the treatment of multi-thread technique are put forward. The method in this paper is proved to be the feasibility and the effectively through the experiment.

© 2011 Published by Elsevier Ltd. Selection and/or peer-review under responsibility of [name organizer] Key Words: size: Inspection of raw silk size; Multithread technique; Circle buffer

1.Introduction China's raw silk exports account for 90% of the international market. Zhejiang Province is the main export province and actively improves the technology of electronic methods of detection of raw silk. Simultaneity, it promotes the revision of silk electronics testing standards. For improving the position of province and even China in the international silk market, there is an urgent and important[1,2]. In the raw silk detection theory, there are two methods, one is image-based detection method [3,4,5], another is based on the photoelectric - capacitive sensor detection method [6,7]. However, due to the slowly image capturing, image processing and other processes, application conditions of the image detection in the index calculation of silk-line size test are not ripe. Chinese raw silk electronics testing standards group is recently led by China Silk Association and set up by the researchers of Zhejiang Silk Co Ltd., Zhejiang Entry-Exit Inspection and Quarantine Inspection wire center, Suzhou University, Zhejiang Cathaya International Ltd. The group did a lot of research and made a breakthrough in test equipment and test methods, grading and other aspects. It determined the

1877-7058 © 2011 Published by Elsevier Ltd. doi:10.1016/j.proeng.2011.11.2541

2522

Zhenhai et al. / Procedia Engineering (2011) 521 – 524 Huang zhenHuang hai/ Procedia Engineering 00 (2011)23000–000

direction based on optical - electronic capacitance sensor detection. And it developed into a raw silk size electronic detector which based on capacitive sensing. Compared with the traditional method of manual inspection, the instrument greatly improves the detection efficiency accompanying high precision characteristics. Whereas there are still some problems in the current raw silk detector, especially in the calculation of the average degree and standard deviation of average degree exist the problems including less calculation samples and the data losing. This paper proposes a rolling algorithm of average size and standard deviation of the average size. We adopt multi-threaded programming and circular buffers to solve above problems.

2.Calculation of average size and standard deviation[8,9] 2.1. Average size In the raw silk test, we need detect average size and classification of defects. We also need calculate the average size and standard deviation. The rolling formula of average size follows as (2-1): Huang zhen hai. Tel.: 0571-86914549; fax: 0571-86914592.Phone:13738159020 E-mail address: [email protected].

X n +1 ≈

X n • n + x n +1 n +1

(2-1) Rolling calculation is that when we receive X n of the first n data, keep it in reserve. Then we use it at the time of calculating the average of former n+1 data. For a large amount of data calculation, the calculation of above is timesaver. The greater the value of n, the higher the accuracy. 2.2 Denier standard deviation Denier standard deviation is calculated as (2-2)

( x n − x1 ) 2 + " + ( x n − x n ) 2 n



Xn =

nxˆ

Then, ∧

2

n

= ( x n − x1 ) + " + ( xn − xn ) 2

(2-2) 2

2

(n + 1) x n +1 = ( x n +1 − x1 ) 2 + " ( x n +1 − x n +1 ) 2 ∧

⇒ (n + 1) x n

+1

2

(2-3)

≈ ( x n − x1 ) 2 + " + ( x n − x n ) 2 + ( x n +1 − x n +1 ) 2 ∧



⇒ Xn 1 = +

(2-4) (2-5)

2

n x n + ( x n +1 − x n +1 ) 2 n +1

(2-6)

In calculating the standard deviation, we put a certain amount of data as a benchmark. We calculate the standard deviation of n+1 data by type (2-6) which is rolling operation; this can ensure accuracy and the speed of calculation. 3.Multi-threading and circle buffer technique

Zhenhai et al. / Procedia Engineering 23 (2011) 521 – 524 HuangHuang zhen hai/ Procedia Engineering 00 (2011) 000–000

Multi-threaded data collection and circle buffer technique: In order to protect system achieving highspeed data acquisition, and at the same time, achieving high-speed data processing, we not only use good algorithms but also adopt multi-threaded programming techniques in the software design. Data collection thread is a worker thread, that is, when this thread receives a response, it can do graphics operations in any windows. Only in this way, this thread will be unblocked to provide the normal continuous data acquisition. Another data processing thread will be open up for user interface thread. Initially, the data processing threads is not working. Under the Win32 API function WaitForSingleObject, the thread will go into sleeping. At this time, it does not consume any CPU time. when the data acquisition thread obtain the specified length of data to user space, then using Win32 API function SetEvent sent the specified message to the data processing threads. The data processing thread resume processing state immediately. This processing includes computing denier indicator, denier standard deviation, defect statistics, denier real-time Curve, Save and other operations.

Figure 1 access diagram of multi-threaded and circle buffer

However, when operations such as the user moving the window blocked the processing thread and the acquisition thread is non-stop, the result may loss data sent by acquisition thread. We use two buffer queues to avoid this problem. Assuming that the acquisition thread obtain 8K each time from the device, we adopt a two-dimensional array, such as pADBuffer [Count] [DataLen], in the user program. DataLen is defined as length of data collected each time by the acquisition thread, Count stands for the number of members of the buffer queue. If we set to 32, then the buffer queue is actually an array pADBuffer [32] [8192]. By changing the value of Count, namely the value of Index, acquisition and processing threads fill and refer to a data buffer of a DataLen length which is pointed by Index subscript. Note that two threads do not share a subscript variable Index. For the first time acquisition of data, we set our own ReadIndex to 0, that is, the first buffer is to acquire AD data. After finished data collecting, it send a message to the processing thread, and common variable of the two threads, SegmentCounts, plus 1. (SegmentCounts variable is used to record the current time the number of buffer queue which is occupied by acquisition thread, but doesn’t be disposed by processing thread.) Then it sets ReadIndex offset to 1, next it starts to use the second buffer for collection until ReadIndex equal to 31. And then it moves back to 0 and restart. When processing thread receives message each time, it will determine the number of data cache areas which isn’t handled due to block. Then it handles the block. At last, SegmentCounts variables subtract the

3523

4524

Zhenhai et al. / Procedia Engineering (2011) 521 – 524 Huang zhenHuang hai/ Procedia Engineering 00 (2011)23000–000

number of buffer which is handled in the current events. The handled buffer is pointed by CurrentIndex. The larger the buffer, the longer the time, even if the processing thread is occasionally busy leading to blocking, you can cache the block in the region after data acquisition, making it difficult to loss data. Through this program, users can estimate SegmentCounts in acquisition thread, if its value is greater than 32, the buffer queue certainly spill over, it can be alarm. Access process of circle buffer which is based on multi-threaded data is shown in Figure 1. Implementation of multi-threaded programming and cycle cache programming techniques is critical to solve the problem of data loss during on-line detection of defects and the raw silk fiber degrees. 4.test results System test is finished in 2007 in Zhejiang Export Commodities Inspection Bureau. Software testing process is divided into two parts, figure of sensor voltage curve graphic and numerical calculations (including defects statistics and fiber degree indicators denier) testing. It is proved by debugging in the prompt: (1) The speed of data acquisition is faster than 24 000 data per second, fully meeting the requirements of the test system. Curve graphic display is the proof of the correction of data collection. (2) Under the operating speed of 600 m / sec in the raw silk testing organizations, data acquisition is going along with defects statistics and calculation of fiber degree, fully meeting requirements of raw silk detection system. Acknowledgments. The research is supported the project Z106853 and Y1110813 of zhejiang province natural science foundation.

Reference [1]. Yi-hui. Forum speech [M]. Proceeding International Silk Forum. 2006 [2]. Wei Hu, Liangmin Wang. Analysis of raw silk automated detection [J]. Journal of Scientific Instrument. 2006.6, No.6, 375 ~ 377 [3]. Hongwen Sun, Qingguan Chen. Test methods and equipment of the performance of silk hold together [J]. Textile Journal. 2005.2, Vol26, No1 [4]. Hongwen Sun, Qingguan Chen. Performance testing system of raw silk hold together based on virtual instrument [J]. Textile Journal. 2005.8, Vol26, No4 [5]. Kegang Dao, Aijuan Du. Research in application of Computer image detection in the raw silk testing [J]. Modern Metrology .1999, No (4) [6]. Chunli Wu, Hu Gu, Lun Bai. Research in the hierarchical sampling method of defect in silk electronic inspection method [J]. 2005, No (4) [7]. Tao Niu, Yi Hu, Jianmei Xu, Wei Hu, Lun Bai. Distribution of rough defects in raw silk electronic. Silk. 2011, No (3), 26 ~ 28 [8]. Guangchun Li, Jianguo Huang, zhigang Wang. Applications of multi-threading technology in data acquisition. Electronic components applications. 2009, No (7), 85 ~ 87 [9. Jianhong Li, Yuzhu He. Applications of Multi-threading technology in complex data acquisition system. Electronic Measurement Technology. 2008, No (5), 102 ~ 104