CN102929823A - Multiple serial port communication system and method based on thread pool - Google Patents

Multiple serial port communication system and method based on thread pool Download PDF

Info

Publication number
CN102929823A
CN102929823A CN2012103373048A CN201210337304A CN102929823A CN 102929823 A CN102929823 A CN 102929823A CN 2012103373048 A CN2012103373048 A CN 2012103373048A CN 201210337304 A CN201210337304 A CN 201210337304A CN 102929823 A CN102929823 A CN 102929823A
Authority
CN
China
Prior art keywords
serial
thread
thread pool
serial ports
port
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN2012103373048A
Other languages
Chinese (zh)
Inventor
何健明
蒋兴钢
汤湛成
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
PCI Suntek Technology Co Ltd
Original Assignee
PCI Suntek Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by PCI Suntek Technology Co Ltd filed Critical PCI Suntek Technology Co Ltd
Priority to CN2012103373048A priority Critical patent/CN102929823A/en
Publication of CN102929823A publication Critical patent/CN102929823A/en
Pending legal-status Critical Current

Links

Images

Abstract

The invention discloses a multiple serial port communication system and method based on a thread pool. The multiple serial port communication system comprises a terminal, equipment with a multiple-serial-port card and an application unit based on the thread pool, wherein the equipment with the multiple-serial-port card is used for communicating with the terminal and the application unit based on the thread pool; the multiple-serial-port card is used for expanding multiple serial ports for the terminal to connect; and the application unit based on the thread pool issues a control instruction or transfers data to the terminal through the equipment with the multiple-serial-port card and receives reply messages of the terminal. The multiple serial port communication system comprises the thread pool, a thread pool building module and a task performing allocation module, wherein the thread pool building module is used for building the thread pool according to task threads allocated by the task performing allocation module; and the task threads allocated by the task performing allocation module comprise a main thread, a serial port operation control thread and a serial port receiving-transmitting message performing thread, and the threads are subjected to asynchronous call.

Description

A kind of Mutli-Serial Communication System and method based on thread pool
Technical field
The present invention relates to Industry Control serial communication field, particularly relate to a kind of Mutli-Serial Communication System based on thread pool and method.
Background technology
At current industrial control field, serial communication is the method that computing machine and other equipment often use when carrying out data communication, have and use several advantages such as flexible, that data transmission is reliable, particularly in real-time monitoring system, be used widely, because the demand of industrial control field operation in enormous quantities, it is particularly important that the stability and high efficiency of multi-serial ports communication just seems.
For satisfying the demands, the multithreading that generally adopts thread pool to manage multi-serial ports communication is used.Yet, at present for the many serial ports of the single channel that utilizes multi-serial-port card to expand out, because each serial ports uses same communication port transceiving data, if application program unit can not be made rational synchronisation measures to each serial ports, passage very easily occurs and stop up, cause serial ports transceiving data success ratio on the low side.
Summary of the invention
Technical matters to be solved by this invention provides a kind of Mutli-Serial Communication System based on thread pool and method, during with solution single channel multi-serial ports communication, and the technical matters that serial ports transceiving data success ratio is on the low side.
For achieving the above object, the invention provides a kind of Mutli-Serial Communication System based on thread pool, comprise terminal, with the equipment of multi-serial-port card and based on the applying unit of thread pool;
Described equipment with multi-serial-port card is used for communicating with described terminal and described applying unit based on thread pool, and described multi-serial-port card is used for expanding multi-channel serial port, connects for described terminal, implements between the serial ports synchronously;
Described applying unit based on thread pool, be used for issuing steering order or transmitting data to described terminal by described equipment with multi-serial-port card, and receive the return information of described terminal, comprise that thread pool, thread pool make up module and the configuration module of executing the task, described thread pool makes up module and is used for making up thread pool according to described mission thread of executing the task the configuration module configuration, described mission thread of executing the task the configuration module configuration comprises main thread, operation of serial-port control thread and serial ports transmitting-receiving message execution thread, carries out asynchronous call between the various threads.
The present invention also provides a kind of multi-serial ports communication method based on thread pool, comprises the steps:
Setting up described terminal is connected with described serial ports with multi-serial-port card equipment;
The described configuration module configuration task thread of executing the task;
Described thread pool makes up module and makes up thread pool according to main thread;
Described applying unit based on thread pool starts the main thread of thread pool, is controlled the execution of other mission thread by main thread.
Preferably have, in the said method, also comprise: described terminal is connected to the serial ports of described equipment with multi-serial-port card by special-purpose Serial Port Line, described switching, the reading and writing data that carries out serial ports based on the applying unit of thread pool by serial ports program development tools bag, realize and the communication of described terminal that corresponding thread pool is realized a plurality of serial ports parallel work-flows.
Preferably have, in the said method, also comprise: described applying unit based on thread pool is opening and closing serial ports, during data read-write operation, each serial ports is being implemented synchronously;
Each serial ports is implemented to refer to synchronously: after all serial ports that are connected with terminal are all opened, carry out reading and writing data again, after the reading and writing data of all serial ports is all finished, finally just close each serial ports.
Preferably have, in the said method, also comprise: before other all serial ports were finished same operation, the corresponding thread of this serial ports got clogged, and treated that other all serial ports also finish after the same operation, could begin next step operation.
Preferably have, in the said method, also comprise: three generic task threads described in the thread pool: main thread, operation of serial-port control thread and serial ports transmitting-receiving message execution thread, main thread is responsible for each serial ports and creates operation of serial-port control thread, operation of serial-port control thread is responsible for serial ports and is opened and closed, generates downward message and process the answer message, and serial ports transmitting-receiving message execution thread is responsible for specially by iostream to come downward message and receive to reply message;
There is the asynchronous call relation between the described three generic task threads, operation of serial-port control thread is asynchronous to obtain serial ports transmitting-receiving message execution thread returns issue successfully zone bit and reply message, main thread is asynchronous obtain that operation of serial-port control thread returns issue the complement mark position.
Can be found out have two kinds of mechanism to guarantee multi-serial ports communication based on thread pool among the present invention by such scheme, efficiently simultaneously also can be in order, stablize.The first, when doing same operation, implement synchronously between each serial ports, only have when all serial ports are all finished this operation, could carry out together next operation; Second, mission thread in the thread pool is divided three classes: main thread, operation of serial-port control thread and serial ports transmitting-receiving message execution thread, not only separately function but also Existence dependency of complete independently between this three generic tasks thread, main thread creates the operation of serial-port control thread of respective amount according to the quantity of described terminal, operation of serial-port control thread is responsible for opening of serial ports, close, and the generation of serial ports downward message, reply the processing of message, and serial ports transceiving data execution thread only is used for issuing and receive message data by iostream, mutual between the three generic task threads, adopt the asynchronous call pattern, like this, both clear definiton of powers, aobvious efficient again.
Description of drawings
In order to be illustrated more clearly in the embodiment of the invention or technical scheme of the prior art, the below will do simple the introduction to the accompanying drawing of required use in embodiment or the description of the Prior Art, apparently, accompanying drawing in the following describes only is some embodiments of the present invention, for those of ordinary skills, under the prerequisite of not paying creative work, can also obtain according to these accompanying drawings other accompanying drawing.
Fig. 1 is system architecture synoptic diagram of the present invention;
Fig. 2 is applying unit structural representation of the present invention;
Fig. 3 is schematic flow sheet in the embodiment of the invention.
Embodiment
For above-mentioned purpose of the present invention, feature and advantage can be become apparent more, the present invention is further detailed explanation below in conjunction with the drawings and specific embodiments.Obviously, described embodiment only is the present invention's part embodiment, rather than whole embodiment.Based on the embodiment among the present invention, those of ordinary skills belong to the scope of protection of the invention not making the every other embodiment that obtains under the creative work prerequisite.
Such as Fig. 1, shown in Figure 2, the invention provides a kind of Mutli-Serial Communication System based on thread pool, comprise terminal, with the equipment of multi-serial-port card and based on the applying unit of thread pool, wherein:
Described equipment with multi-serial-port card is used for communicating with described terminal and described applying unit based on thread pool, and described multi-serial-port card is used for expanding multi-channel serial port, connects for described terminal, implements between the serial ports synchronously;
Described applying unit based on thread pool, be used for issuing steering order or transmitting data to described terminal by described equipment with multi-serial-port card, and receive the return information of described terminal, comprise that thread pool, thread pool make up module and the configuration module of executing the task, described thread pool makes up module and is used for making up thread pool according to described mission thread of executing the task the configuration module configuration, described mission thread of executing the task the configuration module configuration comprises main thread, operation of serial-port control thread and serial ports transmitting-receiving message execution thread, carries out asynchronous call between the various threads.
The course of work of said system is referring to Fig. 3, a plurality of described terminals are connected to described equipment with multi-serial-port card by special-purpose Serial Port Line after, described applying unit job step based on thread pool concrete as below:
Step S301, thread pool make up module according to the main thread of the configuration module configuration of executing the task, and make up thread pool, and start main thread;
The operation of serial-port control thread of step S302, main thread establishment and startup and terminal equal number in thread pool;
Step S303 creates and starts corresponding serial ports among the online Cheng Chi of each operation of serial-port control thread and receives and dispatches the message execution thread;
Step S304, main thread determine whether the sign of receiving that all operation of serial-port control threading operations are finished; If also do not receive all signs, then carry out S305; Otherwise, the processing procedure of end whole system;
Step S305, the serial ports of opening that each operation of serial-port is controlled thread parallel carries out synchro control herein, only has after all serial ports are all opened, and just begins to generate the downward message data, and passes to corresponding serial ports transmitting-receiving message execution thread;
Step S306, each serial ports transmitting-receiving message execution thread downward message data, and receive the answer data;
Step S307 will reply the asynchronous operation of serial-port control thread that returns to correspondence of data;
Step S308, the asynchronous complement mark that returns of each operation of serial-port control thread are to main thread, and after all complement mark positions were all returned, operation of serial-port control thread was closed each serial ports, and the processing procedure of whole system finishes.
The above only is the specific embodiment of the present invention; should be pointed out that for those skilled in the art, under the prerequisite that does not break away from the principle of the invention; can also make some improvements and modifications, these improvements and modifications also should be considered as protection scope of the present invention.

Claims (7)

1. Mutli-Serial Communication System based on thread pool, it is characterized in that, comprise terminal, with the equipment of multi-serial-port card and based on the applying unit of thread pool, described equipment with multi-serial-port card is used for communicating with described terminal and described applying unit based on thread pool, described multi-serial-port card is used for expanding multi-channel serial port, connect for described terminal, described applying unit based on thread pool issues steering order or transmits data to described terminal by described equipment with multi-serial-port card, and receive the return information of described terminal, comprise thread pool, thread pool makes up module and the configuration module of executing the task, described thread pool makes up module and is used for making up thread pool according to described mission thread of executing the task the configuration module configuration, and described mission thread of executing the task the configuration module configuration comprises main thread, operation of serial-port control thread and serial ports transmitting-receiving message execution thread.
2. the Mutli-Serial Communication System based on thread pool according to claim 1 is characterized in that, also comprises:
Described terminal can be the terminal of any support serial port of industrial control field, and described multi-serial-port card can be any multi-serial-port card that is inserted in the PCI slot, is not restricted among the present invention.
3. use the described multi-serial ports communication method based on thread pool of above-mentioned arbitrary claim for one kind, comprise the steps:
Setting up described terminal is connected with described serial ports with multi-serial-port card equipment;
The described configuration module configuration task thread of executing the task;
Described thread pool makes up module and makes up thread pool according to main thread;
Described applying unit based on thread pool starts the main thread of thread pool, is controlled the establishment of other mission thread by main thread and carries out.
4. method according to claim 3 is characterized in that, also comprises:
Described terminal is connected to the described multi-channel serial port that goes out with the device extension of multi-serial-port card by special-purpose Serial Port Line, described switching, the reading and writing data that carries out serial ports based on the applying unit of thread pool by serial ports program development tools bag, realize and the communication of described terminal that corresponding thread pool is realized a plurality of serial ports parallel work-flows.
5. method according to claim 3 is characterized in that, also comprises: described applying unit based on thread pool is opening and closing serial ports, during data read-write operation, each serial ports is being implemented synchronously;
Each serial ports is implemented to refer to synchronously: after all serial ports that are connected with described terminal are all opened, carry out reading and writing data again, after the reading and writing data of all serial ports is all finished, finally just close each serial ports.
6. method according to claim 3 is characterized in that, also comprises: before other all serial ports were finished same operation, the corresponding mission thread of this serial ports got clogged, and treated that other all serial ports also finish after the same operation, just began next step operation.
7. method according to claim 3, it is characterized in that, also comprise: three generic task threads described in the thread pool: main thread, operation of serial-port control thread and serial ports transmitting-receiving message execution thread, main thread is responsible for each serial ports and creates operation of serial-port control thread, operation of serial-port control thread is responsible for serial ports and is opened and closed, generates downward message and process the answer message, and serial ports transmitting-receiving message execution thread is responsible for specially by iostream to come downward message and receive to reply message;
There is the asynchronous call relation between the described three generic task threads, operation of serial-port control thread is asynchronous to obtain serial ports transmitting-receiving message execution thread returns issue successfully zone bit and reply message, main thread is asynchronous obtain that operation of serial-port control thread returns issue the complement mark position.
CN2012103373048A 2012-09-08 2012-09-08 Multiple serial port communication system and method based on thread pool Pending CN102929823A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN2012103373048A CN102929823A (en) 2012-09-08 2012-09-08 Multiple serial port communication system and method based on thread pool

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN2012103373048A CN102929823A (en) 2012-09-08 2012-09-08 Multiple serial port communication system and method based on thread pool

Publications (1)

Publication Number Publication Date
CN102929823A true CN102929823A (en) 2013-02-13

Family

ID=47644624

Family Applications (1)

Application Number Title Priority Date Filing Date
CN2012103373048A Pending CN102929823A (en) 2012-09-08 2012-09-08 Multiple serial port communication system and method based on thread pool

Country Status (1)

Country Link
CN (1) CN102929823A (en)

Cited By (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103701869A (en) * 2013-12-10 2014-04-02 深圳市航天泰瑞捷电子有限公司 Method for controlling communication of multiport electricity meter
CN105245372A (en) * 2015-10-12 2016-01-13 浪潮软件集团有限公司 Optimization method for loading network resources based on cache and asynchronous mechanism
CN105718388A (en) * 2016-01-20 2016-06-29 飞天诚信科技股份有限公司 USB device based asynchronous calling method and apparatus
CN106326785A (en) * 2015-06-18 2017-01-11 中兴通讯股份有限公司 Electronic barcode writing method and device
CN106502864A (en) * 2016-10-26 2017-03-15 厦门科灿信息技术有限公司 A kind of communication management method of data monitoring system
CN108021398A (en) * 2017-11-20 2018-05-11 河南思维轨道交通技术研究院有限公司 Serial ports priority evaluation method and call method, storage medium
CN109120486A (en) * 2018-08-28 2019-01-01 珠海格力电器股份有限公司 WiFi module data transmission method, Transmission system, intelligent appliance data transmission system
CN110018890A (en) * 2018-01-10 2019-07-16 武汉斗鱼网络科技有限公司 A kind of exchange method of cross-thread, electronic equipment and readable storage medium storing program for executing
CN111381889A (en) * 2018-12-27 2020-07-07 西安诺瓦星云科技股份有限公司 Multi-device system and programmable logic device loading method and device
CN111679815A (en) * 2020-06-04 2020-09-18 广州视源电子科技股份有限公司 Asynchronous operation method and device, storage medium and related equipment
CN116736002A (en) * 2023-05-24 2023-09-12 国家电网有限公司华东分部 Electric energy data acquisition method and system, storage medium and terminal

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1297198A (en) * 1999-11-18 2001-05-30 国际商业机器公司 Method, system and program product for managing computing environment thread pool to prevent dead-locking
US20040055002A1 (en) * 2002-09-17 2004-03-18 International Business Machines Corporation Application connector parallelism in enterprise application integration systems
CN101038487A (en) * 2007-05-09 2007-09-19 重庆交通大学 Bridge monitoring system

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1297198A (en) * 1999-11-18 2001-05-30 国际商业机器公司 Method, system and program product for managing computing environment thread pool to prevent dead-locking
US20040055002A1 (en) * 2002-09-17 2004-03-18 International Business Machines Corporation Application connector parallelism in enterprise application integration systems
CN101038487A (en) * 2007-05-09 2007-09-19 重庆交通大学 Bridge monitoring system

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
李勇: "一个多串口多线程数据采集系统软件的设计与实现", 《微计算机信息》 *
沈杨: "线程池技术的应用", 《软件导刊》 *
高翔: "基于线程池的多任务并行处理模型", 《指挥信息系统与技术》 *

Cited By (15)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103701869A (en) * 2013-12-10 2014-04-02 深圳市航天泰瑞捷电子有限公司 Method for controlling communication of multiport electricity meter
CN106326785A (en) * 2015-06-18 2017-01-11 中兴通讯股份有限公司 Electronic barcode writing method and device
CN105245372A (en) * 2015-10-12 2016-01-13 浪潮软件集团有限公司 Optimization method for loading network resources based on cache and asynchronous mechanism
CN105718388B (en) * 2016-01-20 2018-09-25 飞天诚信科技股份有限公司 A kind of asynchronous invoking method and device based on USB device
CN105718388A (en) * 2016-01-20 2016-06-29 飞天诚信科技股份有限公司 USB device based asynchronous calling method and apparatus
CN106502864A (en) * 2016-10-26 2017-03-15 厦门科灿信息技术有限公司 A kind of communication management method of data monitoring system
CN108021398A (en) * 2017-11-20 2018-05-11 河南思维轨道交通技术研究院有限公司 Serial ports priority evaluation method and call method, storage medium
CN110018890A (en) * 2018-01-10 2019-07-16 武汉斗鱼网络科技有限公司 A kind of exchange method of cross-thread, electronic equipment and readable storage medium storing program for executing
CN110018890B (en) * 2018-01-10 2021-07-30 武汉斗鱼网络科技有限公司 Interaction method between threads, electronic equipment and readable storage medium
CN109120486A (en) * 2018-08-28 2019-01-01 珠海格力电器股份有限公司 WiFi module data transmission method, Transmission system, intelligent appliance data transmission system
CN111381889A (en) * 2018-12-27 2020-07-07 西安诺瓦星云科技股份有限公司 Multi-device system and programmable logic device loading method and device
CN111381889B (en) * 2018-12-27 2024-04-05 西安诺瓦星云科技股份有限公司 Multi-device system and programmable logic device loading method and device
CN111679815A (en) * 2020-06-04 2020-09-18 广州视源电子科技股份有限公司 Asynchronous operation method and device, storage medium and related equipment
CN111679815B (en) * 2020-06-04 2024-02-09 广州视源电子科技股份有限公司 Asynchronous operation method and device, storage medium and related equipment
CN116736002A (en) * 2023-05-24 2023-09-12 国家电网有限公司华东分部 Electric energy data acquisition method and system, storage medium and terminal

Similar Documents

Publication Publication Date Title
CN102929823A (en) Multiple serial port communication system and method based on thread pool
CN104252378A (en) Virtual computer experience classroom system
CN108616610A (en) Address distribution method, host, slave and bus system
CN101447915A (en) Method for realizing automatic and smooth switch among different network topology structures and network device thereof
CN101464846B (en) Data card read-write method, interface control method and apparatus
CN102508799B (en) Automatic control method, system and USB (universal serial bus) device
CN103412796A (en) Stack allocation method and stack allocation unit for tasks in operating system
CN205320103U (en) Many interface communication networking system
CN104104594B (en) VSU protocol massages are sent and method of reseptance, equipment and system
CN101751324B (en) Non-contact type intelligent card simulator and a working mode switching method
CN205992868U (en) A kind of motor driver based on CPLD
CN201323593Y (en) Network device for automatic smooth switching between various network topology structures
CN204681280U (en) A kind of based on L6474 glove knitting machine step motor control system
CN203522329U (en) Power distribution terminal remote control system
CN106530023A (en) Tax supervising server and anti-suspension method of tax supervising core board
CN102623728A (en) Application structure of human machine interface in fuel cell system on basis of CAN (Controller Area Network) bus
CN104133788A (en) CAN bus data transmission method in active filter system
CN109801390B (en) PSAM card operation method, device and equipment
CN205920159U (en) A generic interface for electric energy meter
CN110288316A (en) The method and terminal device of transforming plant primary equipment work card arrangement
CN102520666B (en) Method and system for reprogramming electronic control unit (ECU)
CN105182895B (en) The terminal resistance automatic matching method and system of a kind of PLC expansion bus
CN204065790U (en) A kind of wireless teaching control device
CN211669535U (en) Connecting structure of PLC main control module and IO module
CN200996113Y (en) Washing machine with IC card

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C05 Deemed withdrawal (patent law before 1993)
WD01 Invention patent application deemed withdrawn after publication

Application publication date: 20130213