Embodiment
Below in conjunction with drawings and Examples, the present invention is described in further detail.Be understandable that, specific embodiment described herein is only for explaining the present invention, but not limitation of the invention.It also should be noted that, for convenience of description, illustrate only part related to the present invention in accompanying drawing but not entire infrastructure.
First embodiment
Present embodiments provide a kind of technical scheme to the method that the data of serial line interface transmission process.In this technical scheme, the method that the data of serial line interface transmission process is comprised: the data buffer storage queue with variable-length is set; When serial line interface receives data to be written, utilize Data In-Line journey that described data to be written are put the afterbody to described data buffer storage queue; DOL Data Output Line journey is utilized to sequentially read data from described data buffer storage queue, and, between described DOL Data Output Line journey and described Data In-Line journey, keep the exclusive reference to described data buffer storage queue by cross-thread synchronization mechanism.
See Fig. 1, the method that the described data transmitted serial line interface process comprises: operation 11 to operation 13.
In operation 11, the data buffer storage queue with variable-length is set.
In order to prevent because arrange the buffer zone of regular length and the data from overflow that produces, the data buffer storage queue with variable-length is set in the internal memory of computing machine.Set data buffer storage queue is used for the data that buffer memory is transmitted by serial line interface.
In operation 12, when serial line interface receives data to be written, utilize Data In-Line journey that described data to be written are put the afterbody to described data buffer storage queue.
Start Data In-Line journey when serial line interface receives the data needing to write described data buffer storage queue.Described Data In-Line journey is the thread being used for the data to be written received to write to described data buffer storage queue specially.
When the data to be written received are write to described data buffer storage queue by described input thread, described Data In-Line journey does not cover the data write in described data buffer storage queue, but by the deposit data to be written afterbody in described data buffer storage queue.Such as, if before needs write data " 025 " in described data buffer storage queue, stored data " 8549 " in described data buffer storage queue, then, after writing data " 025 ", the data stored in described data buffer storage queue are " 8549025 ".Can the writing mode that this afterbody having write deposits the data re-write be called additional.
In operation 13, DOL Data Output Line journey is utilized to sequentially read data from described data buffer storage queue, and, between described DOL Data Output Line journey and described Data In-Line journey, keep the exclusive reference to described data buffer storage queue by cross-thread synchronization mechanism.
Preferably, the sense data of DOL Data Output Line journey order from described data buffer storage queue can be utilized.Preferred further, described DOL Data Output Line journey every fixed time interval, can check in described data buffer storage queue whether be cached with data, is cached with data, then sense data from described data buffer storage queue if find in described data buffer storage queue.
In addition, it should be noted that, utilize inter-thread communication mechanism can ensure that described DOL Data Output Line journey and the access of described Data In-Line journey to described data buffer storage queue are the access of mutual exclusion.That is, described DOL Data Output Line journey and described Data In-Line journey can not access described data buffer storage queue in the same moment.
Described inter-thread communication mechanism can be incompatible lock mechanism or conditional-variable mechanism.
Mutual exclusion lock can be regarded as a kind of semaphore, is commonly used to prevent multiple thread from accessing identical shared resource at synchronization.Under incompatible lock mechanism, the thread only opening mutual exclusion lock can obtain execution, and other threads can only wait for that mutual exclusion lock just likely obtains execution after being released.Incompatible lock mechanism can be realized by the lock key word in C# language or the synchronized key word in Java language.
Conditional-variable mechanism is another inter-thread communication mechanism.Concrete, by sharing the conditional-variable of the overall situation between thread, to realize between thread synchronous for it.Such as, when the value of conditional-variable is 0, a thread obtains the authority be performed.And when the value of conditional-variable is 1, another one thread obtains the authority be performed.
The present embodiment has the data buffer storage queue of variable-length by arranging, when serial line interface receives data to be written, utilize Data In-Line journey by described data to be written, DOL Data Output Line journey is utilized to sequentially read data from described data buffer storage queue, and, between described DOL Data Output Line journey and described Data In-Line journey, the exclusive reference to described data buffer storage queue is kept by cross-thread synchronization mechanism, the data writing buffer memory can not lost because of the space constraint of buffer area again, and the data having write buffer memory can not be capped, thus improve the reliability of serial data readout.
Second embodiment
The present embodiment, based on the above embodiment of the present invention, further provides when serial line interface receives data to be written, utilizes Data In-Line journey that described data to be written are put a kind of technical scheme of the afterbody to described data buffer storage queue.In this technical scheme, utilize the afterbody that described data to be written are put to described data buffer storage queue by Data In-Line journey to comprise: utilize described Data In-Line journey by the data on serial line interface by turn read to the buffer zone pre-set; Cyclic redundancy check (CRC) (Cyclic redundant check, CRC) is carried out to the data in described buffer zone; Remove the CRC position in described buffer zone in data; Utilize described Data In-Line journey that the mode that the data in buffer zone add with afterbody is write data buffer storage queue described in duty.
Operation 21 in, utilize described Data In-Line journey by the data on serial line interface by turn read to the buffer zone pre-set.
Described Data In-Line journey is the threads of the data for being received by serial line interface stored in data buffer storage queue.In order to be that data are more reliable stored in process, described Data In-Line journey uses buffer zone to carry out the unloading of data.Described buffer zone is the one piece of memory address space be pre-created.It has fixing space size.And, the frame data that the enough storage string line interfaces of space size of described buffer zone receive.
Described Data In-Line journey, when reading described data to be written from described serial line interface, should adopt the mode that order by turn reads.The data received by described serial line interface so just ensured are read to described buffer zone by complete.
In operation 22, CRC is carried out to the data in described buffer zone.
If add CRC position from the data to be written that described serial line interface receives, then can utilize the CRC position in data, CRC is performed to described data to be written.
In operation 23, remove the CRC position in described buffer zone in data.
After completing CRC to described data to be written, the data described to be written stored from described buffer zone remove the CRC position wherein comprised.
In operation 24, utilize described Data In-Line journey that the mode that the data in buffer zone add with afterbody is write to described data buffer storage queue.
Complete after the CRC check of described data to be written and the removal of check bit, the mode that the data to be written completing aforesaid operations add with afterbody is write to described data buffer storage queue.Concrete, by complete CRC check and check bit removal after deposit data to be written at the afterbody of described data buffer storage queue.
It should be noted that, if do not comprise CRC position from the data to be written that serial line interface receives, then do not need executable operations 22 and operation 23.
The present embodiment by Data In-Line journey by the data on serial line interface by turn read to the buffer zone pre-set, and utilize described Data In-Line journey that the mode that the data in buffer zone add with afterbody is write to described data buffer storage queue, thus achieve the data received from serial line interface are write to described data buffer storage queue reliably.
3rd embodiment
The present embodiment, based on the above embodiment of the present invention, further provides a kind of technical scheme utilizing DOL Data Output Line journey to sequentially read data from described data buffer storage queue.In this technical scheme, utilize DOL Data Output Line journey to sequentially read data from described data buffer storage queue, comprising: every fixed time interval, utilize described DOL Data Output Line journey whether to check in described data buffer storage queue with data; If with data in described data buffer storage queue, utilize described DOL Data Output Line journey, and read the data in described data buffer storage queue in first-in first-out mode; Described DOL Data Output Line journey is utilized to empty described data buffer storage queue.
See Fig. 3, utilize DOL Data Output Line journey to sequentially read data from described data buffer storage queue and comprise: operation 31 to operation 33.
In operation 31, every fixed time interval, described DOL Data Output Line journey is utilized whether to check in described data buffer storage queue with data.
The wait of Fixed Time Interval can be realized by the dormancy of described DOL Data Output Line journey.Whenever described DOL Data Output Line journey completes the dormancy of Fixed Time Interval, after being waken up, described DOL Data Output Line journey checks whether described data buffer storage queue is empty.If described data buffer storage queue is empty, then illustrates in described data buffer storage queue and do not write data; If described data buffer storage queue is not empty, then illustrate in described data buffer storage queue with data.
In operation 32, if with data in described data buffer storage queue, utilize described DOL Data Output Line journey, and read the data in described data buffer storage queue in first-in first-out mode.
Through the inspection to described data buffer storage queue, if find, with data in described data buffer storage queue, then described DOL Data Output Line journey reads the data stored in described data buffer storage queue in the mode of first-in first-out.
In operation 33, described DOL Data Output Line journey is utilized to empty described data buffer storage queue.
After completing the reading to data in described data buffer storage queue, described DOL Data Output Line journey is utilized to empty described data buffer storage queue, again to write data in described data buffer storage queue.
The present embodiment passes through every fixed time interval, described DOL Data Output Line journey is utilized whether to check in described data buffer storage queue with data, when in described data buffer storage queue with when data, utilize described DOL Data Output Line journey, and read the data in described data buffer storage queue in first-in first-out mode, and utilize described DOL Data Output Line journey to empty described data buffer storage queue, achieve the reliable reading to the data stored in data buffer queue, thus improve the reliability of the data read process of serial line interface.
4th embodiment
Present embodiments provide a kind of technical scheme to the method that the data of serial line interface transmission process.In this technical scheme, by C# codes implement to the method that the data of serial line interface transmission process.Concrete, the method that the described data transmitted serial line interface process comprises: utilize Data In-Line journey data to be written to be placed on the afterbody of the adjustable length data buffer storage queue pre-set; Utilize DOL Data Output Line journey to sequentially read data from described data buffer storage queue, wherein, between described DOL Data Output Line journey and described Data In-Line journey, keep the exclusive reference to described data buffer storage queue by cross-thread synchronization mechanism.
See Fig. 4, the method that the described data transmitted serial line interface process comprises: operation 41 and operation 42.
In operation 41, Data In-Line journey is utilized data to be written to be placed on the afterbody of the adjustable length data buffer storage queue pre-set.
The code of the Data In-Line journey utilizing C# to realize is as follows:
Visible, after reading a character string, the character string read is added into rcvBuilder object by append method by described Data In-Line journey, instead of character string is re-write rcvBuilder object.
After completing the interpolation of character string, by following code, data buffer storage queue is worked as in the write of the character string of all interpolations:
Visible, the queue operation that enters performed message character string is by the operation performed in the program segment of lock key marker, by the constraint of incompatible lock mechanism.
In operation 42, utilize DOL Data Output Line journey to sequentially read data from described data buffer storage queue, wherein, between described DOL Data Output Line journey and described Data In-Line journey, keep the exclusive reference to described data buffer storage queue by cross-thread synchronization mechanism.
The code of the DOL Data Output Line journey utilizing C# to realize is as follows:
Visible, the dequeue operation performed message character string is by the operation performed in the program segment of lock key marker, by the constraint of incompatible lock mechanism.
The afterbody of the present embodiment by utilizing Data In-Line journey data to be written to be placed on the adjustable length data buffer storage queue pre-set, and utilize DOL Data Output Line journey to sequentially read data from described data buffer storage queue, make to cause loss of data because of the spilling of buffer zone, also can not there is the data cover in Buffer Pool, thus effectively improve the reliability that serial interface data reads process.
5th embodiment
Present embodiments provide a kind of technical scheme to the device that the data of serial line interface transmission process.See Fig. 5, in this technical scheme, the device that the described data transmitted serial line interface process comprises: queue arranges module 51, Data write. module 52 and data reading module 53.
Described queue arranges module 51 for arranging the data buffer storage queue with variable-length.
Described Data write. module 52 is for receiving data to be written during when serial line interface, utilize Data In-Line journey that described data to be written are put the afterbody to described data buffer storage queue.
Described data reading module 53 sequentially reads data for utilizing DOL Data Output Line journey from described data buffer storage queue, and, between described DOL Data Output Line journey and described Data In-Line journey, keep the exclusive reference to described data buffer storage queue by cross-thread synchronization mechanism.
Further, described Data write. module 52 comprises: reading submodule and queue write submodule by turn.
Described reading submodule by turn for utilize described Data In-Line journey by the data on serial line interface by turn read to the buffer zone pre-set.
The mode that data in buffer zone add with afterbody is write to described data buffer storage queue for utilizing described Data In-Line journey by described queue write submodule.
Further, described Data write. module 52 also comprises: syndrome module and check bit remove submodule.
Described syndrome module be used for utilize described Data In-Line journey by the data in buffer zone with afterbody add mode write to described data buffer storage queue before, cyclic redundancy check (CRC) is carried out to the data in described buffer zone.
Described check bit is removed submodule and is used for, utilizing before the data in buffer zone write to described data buffer storage queue in the mode that afterbody adds by described Data In-Line journey, removing the cyclic redundancy check (CRC) position in described buffer zone in data.
Further, described data reading module 53 comprises: check that submodule, reading submodule and buffer memory empty submodule.
Whether described inspection submodule is used for every fixed time interval, utilize described DOL Data Output Line journey to check in described data buffer storage queue with data.
Described reading submodule to be used in described data buffer storage queue, with when data, utilizing described DOL Data Output Line journey, and reading the data in described data buffer storage queue in first-in first-out mode.
Described buffer memory empties submodule and empties described data buffer storage queue for utilizing described DOL Data Output Line journey.
Further, described cross-thread synchronization mechanism comprises: incompatible lock mechanism or conditional-variable mechanism.
Those of ordinary skill in the art should be understood that, above-mentioned of the present invention each module or each step can realize with general calculation element, they can concentrate on single calculation element, or be distributed on network that multiple calculation element forms, alternatively, they can realize with the executable program code of computer installation, thus they storages can be performed by calculation element in the storage device, or they are made into each integrated circuit modules respectively, or the multiple module in them or step are made into single integrated circuit module to realize.Like this, the present invention is not restricted to the combination of any specific hardware and software.
Each embodiment in this instructions all adopts the mode of going forward one by one to describe, and what each embodiment stressed is the difference with other embodiments, the same or analogous part between each embodiment mutually see.
The foregoing is only the preferred embodiments of the present invention, be not limited to the present invention, to those skilled in the art, the present invention can have various change and change.All do within spirit of the present invention and principle any amendment, equivalent replacement, improvement etc., all should be included within protection scope of the present invention.