[go: up one dir, main page]

WO2018165900A1 - Communication control method and control apparatus - Google Patents

Communication control method and control apparatus Download PDF

Info

Publication number
WO2018165900A1
WO2018165900A1 PCT/CN2017/076760 CN2017076760W WO2018165900A1 WO 2018165900 A1 WO2018165900 A1 WO 2018165900A1 CN 2017076760 W CN2017076760 W CN 2017076760W WO 2018165900 A1 WO2018165900 A1 WO 2018165900A1
Authority
WO
WIPO (PCT)
Prior art keywords
serial port
data
slave
virtual
node
Prior art date
Application number
PCT/CN2017/076760
Other languages
French (fr)
Chinese (zh)
Inventor
黄健
景强
汪德暖
Original Assignee
深圳中兴力维技术有限公司
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 深圳中兴力维技术有限公司 filed Critical 深圳中兴力维技术有限公司
Priority to PCT/CN2017/076760 priority Critical patent/WO2018165900A1/en
Priority to CN201780002445.5A priority patent/CN108235802A/en
Publication of WO2018165900A1 publication Critical patent/WO2018165900A1/en

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L12/00Data switching networks
    • H04L12/28Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
    • H04L12/40Bus networks
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F13/00Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F13/38Information transfer, e.g. on bus
    • G06F13/42Bus transfer protocol, e.g. handshake; Synchronisation
    • G06F13/4282Bus transfer protocol, e.g. handshake; Synchronisation on a serial bus, e.g. I2C bus, SPI bus

Definitions

  • the present invention relates to the field of communications technologies, and in particular, to a communication control method and a control device.
  • a host that manages data is connected to several slaves via RS485.
  • Each slave has several serial ports to connect with the front-end collection terminal to realize communication between the host and the front-end collection terminal.
  • an object of the present invention is to provide a communication control method and control apparatus, which are intended to effectively improve communication efficiency between a host and a slave serial port.
  • the present invention provides a communication control method for implementing communication between a host and each serial port of each slave.
  • the communication control method includes the following steps:
  • the creating a virtual serial port node corresponding to each of the serial ports of each of the slaves includes:
  • the step of performing addressing mapping on the virtual serial port node and the corresponding serial port includes: [0014] encoding a handle of the virtual serial port node and a corresponding address of the slave port And corresponding address encoding of the serial port, and mapping of the virtual serial port node.
  • the host after receiving the data write request to the virtual serial port node, the host obtains an address code of the serial port from the virtual serial port node, and according to the address
  • the step of encoding the data into the corresponding serial port includes:
  • the data write request after receiving the data write request sent by the host to the virtual serial port node, determining the type of the data write request; the data write request includes a serial port parameter setting request and a serial port data write request ;
  • the data write request is a serial port data write request
  • obtaining an address code of the corresponding serial port from the virtual serial port node and writing the serial port data into a corresponding one according to the address code.
  • the serial port
  • the step of sequentially reading data of each of the serial ports of each of the slaves, and storing the obtained data in a buffer of the corresponding virtual serial port node includes:
  • the present invention further provides a communication control apparatus, configured to implement communication between a host and each serial port of each slave, and the communication control apparatus includes a creation module, a data writing module, and data. Reading module
  • the creating module is configured to create a virtual serial port node corresponding to each of the serial ports of each of the slaves
  • the data writing module is configured to: after receiving a data write request sent by the host to the virtual serial port node, obtain an address code of the serial port from the virtual serial port node, and Writing the data to the corresponding serial port according to the address encoding;
  • the data reading module is configured to sequentially read data of each serial port of each of the slaves, and store the acquired data in a buffer of a corresponding virtual serial port node, The host can read the data of the corresponding serial port from the buffer of each virtual serial port node.
  • the creating module includes an acquiring unit, a creating unit, and a mapping unit.
  • the obtaining unit is configured to acquire an address code of the slave and an address code of each serial port of the slave;
  • the creating unit is configured to create a virtual serial port node corresponding to each of the serial ports
  • mapping unit is configured to perform addressing mapping on the virtual serial port node and the corresponding serial port.
  • the mapping unit is specifically configured to: code a handle of the virtual serial port node, address code of the corresponding slave device, address code of the corresponding serial port, and the virtual serial port node The code is mapped.
  • the data writing module includes a determining unit, a serial port parameter setting unit, and a serial port data writing unit;
  • the determining unit is configured to: after receiving the data write request sent by the host to the virtual serial port node, determine a type of the data write request; the data write request includes a serial port parameter setting Request and serial data write request;
  • the serial port parameter setting unit is configured to: after the data write request is a serial port parameter setting request, obtain an address code of the corresponding serial port from the virtual serial port node, and according to the address code Writing, by the serial port setting parameter, the corresponding serial port;
  • the serial port data writing unit is configured to: after the data writing request is a serial port data writing request, obtain an address code of the serial port from the virtual serial port node, and according to the address The encoding writes the serial port data to the corresponding serial port.
  • the data reading module includes a sending unit and a control unit;
  • the sending unit is configured to send a serial port data read request to the slave device
  • control unit is configured to: when the slave responds to the serial port data read request in a preset response time, store data of each serial port of the slave in a corresponding Virtual serial port node buffer
  • control unit is further configured to: when the slave does not respond to the serial port data read request in a preset response time, control the sending unit to send serial port data to the slave device Read the request.
  • the address serial code of the corresponding serial port can be obtained through the virtual serial port node, so as to implement data writing to the serial port.
  • the data of the corresponding serial port can be directly obtained by obtaining the data of the corresponding serial port from the buffer area of the virtual serial port node; the technical solution of the invention improves the communication mechanism between the serial port of the host and the slave, and effectively improves The communication efficiency and accuracy of the serial port between the host and the slave.
  • FIG. 1 is a flowchart of an embodiment of a communication control method according to the present invention.
  • FIG. 2 is a flow chart showing a first embodiment of creating a virtual serial port node corresponding to each of the serial ports of each of the slaves in FIG. 1;
  • FIG. 3 is a diagram showing the address code of the serial port obtained from the virtual serial port node after receiving the data write request sent by the host to the virtual serial port node in FIG.
  • Address code is a flowchart of an embodiment of the step of writing the data into the corresponding serial port;
  • FIG. 5 is a schematic block diagram of an embodiment of a communication control apparatus according to the present invention.
  • FIG. 6 is a schematic block diagram of an embodiment of creating a module in FIG. 5;
  • FIG. 7 is a block diagram of an embodiment of the data writing module of FIG. 5;
  • FIG. 8 is a block diagram of an embodiment of the data reading module of FIG. 5.
  • a communication control method includes the following steps: [0052] Step S100: creating a one-to-one correspondence with each of the serial ports of each of the slaves a virtual serial port node; [0053] step S200, after receiving a data write request sent by the host to the virtual serial port node, obtaining a corresponding address code of the serial port from the virtual serial port node, and according to The address encoding writes the data to the corresponding serial port;
  • step S300 sequentially reading data of each serial port of each of the slaves, and storing the obtained data in a buffer of the corresponding virtual serial port node, so that the host can The buffer of each virtual serial port node reads the data of the corresponding serial port.
  • Steps S200 and S300 are in no particular order and can be interchanged.
  • the host sequentially sends a serial port information scanning request to each slave. Then, according to the serial port information returned by the slave, a corresponding virtual serial port node is established in the communication control device (the virtual terminal clone device used in the present invention is /dev/ptmx), and the file directory and name of the virtual serial port node can be specified (for example, , /dev/vtseriall) , and number the virtual serial port nodes, and the actual slave serial port is bound with the struct structure to achieve one-to-one mapping.
  • the communication control device the virtual terminal clone device used in the present invention is /dev/ptmx
  • the file directory and name of the virtual serial port node can be specified (for example, , /dev/vtseriall)
  • number the virtual serial port nodes and the actual slave serial port is bound with the struct structure to achieve one-to-one mapping.
  • the handle of each created virtual serial port node is added to the read/write listening queue, and the event is triggered to trigger the reading and writing of the virtual serial port node.
  • the host and the slave are connected by RS485 communication; the slave and the front-end data collection terminal collect the unit.
  • the communication control device disposed on the host side sequentially sends a scan request to all connected slaves according to the address code of the slave.
  • the slave device responds to the communication control device with each serial port information of the slave.
  • the communication control device locally creates a virtual serial port section corresponding to each of the serial ports according to each serial port information. Point, and perform addressing mapping processing on the virtual serial port node and the corresponding serial port.
  • the host needs to write data to the serial port, the host sends a data write request.
  • the communication control device searches for the address code of the corresponding serial port in the mapping relationship between the corresponding virtual serial port node and the serial port according to the data write request.
  • the write data included in the data write request is then written to the serial port via RS485.
  • the communication control device reads the data of the serial port from the serial port and stores the read data to a corresponding virtual serial port node. In the buffer, the host can directly read the data of the corresponding serial port from the buffer of the virtual serial port.
  • the address serial code of the corresponding serial port can be obtained through the virtual serial port node, so as to implement data to the serial port.
  • the data can be read from the serial port of the virtual serial port to obtain the data of the serial port.
  • the step of creating a virtual serial port node corresponding to each of the serial ports of each of the slaves includes:
  • Step S110 Acquire an address code of the slave and an address code of each serial port of the slave.
  • Step S120 Create a virtual serial port node corresponding to each of the serial ports.
  • Step S130 performing addressing mapping on the virtual serial port node and the corresponding serial port; specifically, the handle of the virtual serial port node, the address of the corresponding slave device, and the corresponding serial port.
  • the address code, and the code of the virtual serial port node are mapped.
  • the address of each slave device needs to be encoded in sequence; and the address of each serial port of each of the slave devices is encoded. For example, if there are N slaves, each slave has M serial ports, then the address codes of the slaves are sequentially set to 0, 1, 2, ..., N; the address is encoded as 0. The address encoding of the serial port of the slave is set to 1, 2, 3, ..., M; the address code is
  • the address of the slave serial port of 1 is M+l, M+2, M+3, ..., M+M; the address of the serial port of the slave with address code 2 is 2M+1. 2M+2, 2M+3, 2M+M; ; The address code of the serial port whose address code is N slave is N*M+1, N*M+2, N*M+3, N*M+M . Then, corresponding to N*M+M serial ports, N*M+M virtual serial port nodes are created.
  • the virtual serial port node After addressing the corresponding serial port, the name of the virtual serial port node (named vt Se rial+ code, such as vtseriall), the file descriptor generated by the virtual serial port node, corresponding file identifier
  • the address encoding of the slave, and the encoding of the serial port corresponding to the slave are bound together using a C language struct structure to form an internal mapping of virtual serial node information, and then, the structure of all serial ports
  • the body information is stored in a list of linked lists.
  • the communication control device can find the virtual device from the list list according to the file descriptor of the virtual serial port node.
  • the structure information of the serial port node parses out the address code of the slave corresponding to the virtual serial port node and the address code of the serial port of the corresponding slave device, and makes correct serial port addressing, thereby effectively improving communication efficiency.
  • the slave when the scan of the slave does not respond within a certain time, the slave is added to the scan failure queue, and the slave follows the preset in the subsequent scan failure queue. Inter-turn interval training scan. After the mapping relationship is established, the handle is added to the select I/O listening list, and the virtual serial port node is read and written.
  • Step S210 Receive a data write request sent by the host to the virtual serial port node.
  • Step S220 Determine whether the data write request is a serial port parameter setting request; if yes, execute step 230; if no, execute step S240.
  • Step 230 Obtain an address code of the corresponding serial port from the virtual serial port node, and write the serial port setting parameter to the corresponding serial port according to the address code.
  • Step 240 Obtain an address code of the corresponding serial port from the virtual serial port node, and write the serial port data to the corresponding serial port according to the address code.
  • the application of the host accesses the virtual serial port node (for example, open (vtseriall, 0_RDWR)) through the open function of the system standard I/O, and accesses the virtual serial port node through the standard write function of the Linux system.
  • the data write request is sent to the communication control device through the virtual drive layer, and the communication control device parses the type of the data write request according to the data frame format defined in Table 1 below and Table 2 below.
  • the virtual serial port node When the data write request is a serial port parameter setting request, the virtual serial port node is queried from the virtual serial port node list table of the virtual serial port node. Point the corresponding slave serial port, and send the parsed serial communication parameters to the corresponding slave according to the internally defined master-slave communication protocol, so that the slave can set the corresponding serial port.
  • the data write request is a serial port data write request
  • the virtual serial port node list is addressed to the slave serial port corresponding to the virtual serial port node, and the parsed serial port data is sent according to the internally defined master-slave communication protocol. Go to the corresponding serial port on the slave to write data to the serial port.
  • the data of each serial port of each of the slaves is sequentially read, and the obtained data is stored in a buffer of a corresponding virtual serial port node.
  • the steps include:
  • step S310 sending a serial port data read request to a slave device
  • Step S320 determining whether the slave responds to the read request within a preset response time; if yes, executing step S330, and if no, executing step S340.
  • Step S330 storing data of each serial port of the slave device in a buffer area of the corresponding virtual serial port node
  • Step S340 Send a serial port data read request to the next slave.
  • the optimization principle of the training interval is: after sending a request to the slave to read all the serial port data on the slave, if the slave responds to the request within the preset response time, The data of each of the serial ports of the slave is stored in a buffer of the corresponding virtual serial port node; if the slave does not respond to the request within a preset response time, directly to the slave Send a serial data read request.
  • the integrity of the obtained serial port data can also be verified. After the integrity verification is passed, the data of each of the serial ports of the slave is stored in a buffer of the corresponding virtual serial port node. After the integrity verification fails, the obtained serial port data is discarded, and then the serial port data read request is sent to the slave.
  • a communication control apparatus configured to implement communication between a host and each serial port of each slave.
  • the communication control apparatus The creating module 410 is configured to create a virtual serial port node corresponding to each of the serial ports of each of the slaves; the data a writing module 420, configured to: after receiving a data write request sent by the host to the virtual serial port node, obtain an address code of the serial port from the virtual serial port node, and encode according to the address Write the data to the corresponding serial port; the data reading module 430 is configured to sequentially read data of each serial port of each of the slaves, and store the acquired data in the data. Corresponding buffers of the virtual serial port nodes, so that the host can read data of the corresponding serial port from the buffer of each virtual serial port node.
  • the host sequentially sends a serial port information scanning request to each slave. Then, according to the serial port information returned by the slave, a corresponding virtual serial port node is established in the communication control device (the virtual terminal clone device used in the present invention is /dev/ptmx), and the file directory and name of the virtual serial port node can be specified (for example, , /dev/vtseriall) , and number the virtual serial port nodes, and the actual slave serial port is bound with the struct structure to achieve one-to-one mapping.
  • the communication control device the virtual terminal clone device used in the present invention is /dev/ptmx
  • the file directory and name of the virtual serial port node can be specified (for example, , /dev/vtseriall)
  • number the virtual serial port nodes and the actual slave serial port is bound with the struct structure to achieve one-to-one mapping.
  • the handle of each created virtual serial port node is added to the read/write listening queue, and the event is triggered to trigger the reading and writing of the virtual serial port node.
  • the host and the slave are connected by RS485 communication.
  • the communication control device on the host side sequentially transmits a scan request to all connected slaves in accordance with the address code of the slave.
  • the slave device responds to the communication control device with each serial port information of the slave.
  • the communication control device locally creates a virtual serial port node corresponding to each of the serial ports in a local manner according to each of the serial port information, and performs address mapping processing on the virtual serial port node and the corresponding serial port.
  • the host needs to write data to the serial port, the host sends a data write request.
  • the communication control device searches for the address code of the corresponding serial port in the mapping relationship between the corresponding virtual serial port node and the serial port according to the data write request.
  • the write data contained in the data write request is then written to the serial port via R S485.
  • the communication control device reads the data of the serial port from the serial port and stores the read data to a corresponding virtual serial port node. In the buffer, the host can directly read the data of the corresponding serial port from the buffer of the virtual serial port.
  • the address serial code of the corresponding serial port can be obtained through the virtual serial port node, so as to implement data to the serial port.
  • the data can be read from the serial port of the virtual serial port to obtain the data of the serial port.
  • the creating module 410 includes an obtaining unit 412, a creating unit 414, and a mapping unit 416.
  • the obtaining unit 412 is configured to acquire an address code of the slave and the slave. The address of each of the serial ports of the machine is encoded; the creating unit 414 is configured to create a virtual serial port node corresponding to each of the serial ports; the mapping unit 416 is configured to the virtual serial port node and the corresponding The serial port does the addressing mapping.
  • the mapping unit 416 is specifically configured to map the handle of the virtual serial port node, the address encoding of the corresponding slave, the address encoding of the corresponding serial port, and the encoding of the virtual serial port node.
  • the address of each slave device needs to be encoded in sequence; and the address of each serial port of each of the slave devices is encoded. For example, if there are N slaves, each slave has M serial ports, then the address codes of the slaves are sequentially set to 0, 1, 2, ..., N; the address is encoded as 0. The address encoding of the serial port of the slave is set to 1, 2, 3, ..., M; the address code is
  • the address of the serial port of the slave is 1 M+l, M+2, M+3, ..., M+M; the address code is 2
  • the address code of the serial port of the slave is 2M+1, 2M+2, 2M+3, 2M+M;
  • the address code of the serial port whose address code is N slave is N*M+1, N*M+2 N*M+3, , N*M+M.
  • N*M+M virtual serial port nodes are created. After the virtual serial port node is mapped to the corresponding serial port, the name of the virtual serial port node (named vt Se rial+ code, such as vtseriall), and the virtual serial port node are generated.
  • a file descriptor, a corresponding address encoding of the slave, and an encoding of the serial port corresponding to the slave are bound together in a form of a C language struct structure to form an internal mapping of virtual serial port node information, and then , store all serial port structure information in a list linked list.
  • the communication control device can find the virtual device from the list list according to the file descriptor of the virtual serial port node.
  • the structure information of the serial port node parses out the address code of the slave corresponding to the virtual serial port node and the address code of the serial port of the corresponding slave device, and makes correct serial port addressing, thereby effectively improving communication efficiency.
  • the slave when the scan of the slave does not respond within a certain time, the slave is added to the scan failure queue, and the slave follows the preset in the subsequent scan failure queue. Inter-turn interval training scan. After the mapping relationship is established, the handle is added to the select I/O listening list, and the virtual serial port node is read and written.
  • the data writing module 420 includes a determining unit 422, a serial port parameter setting unit 424, and a serial port data writing unit 426.
  • the determining unit 422 is configured to receive the Determining, by the host, a data write request to the virtual serial port node, determining a type of the data write request; the data write request includes a serial port parameter setting request and a serial port data write request; and the serial port parameter setting unit 424 And configured to: after the data write request is a serial port parameter setting request, obtain an address code of the serial port from the virtual serial port node, and write the serial port setting parameter into a corresponding one according to the address code.
  • the serial port data writing unit 426 is configured to: after the data write request is a serial port data write request, obtain the address code of the serial port from the virtual serial port node, and according to the The address code writes the serial port data to the corresponding serial port.
  • the application of the host accesses the virtual serial port node (for example: open (vtseriall, 0_RDWR)) through the open function of the system standard I/O, and accesses the virtual function through the standard write function of the Linux system.
  • Serial port node and send data write request to communication control device through virtual drive layer
  • the communication control device parses out the type of the data write request according to the data frame format defined in Table 1 below and Table 2 below.
  • the virtual serial port node list table of the virtual serial port node is queried to the slave serial port corresponding to the virtual serial port node, and the parsed serial port communication parameter is determined according to the internally defined master-slave The communication protocol is sent to the corresponding slave, so that the slave can set the corresponding serial port.
  • the data write request is a serial port data write request
  • the virtual serial port node list is addressed to the slave serial port corresponding to the virtual serial port node, and the parsed serial port data is sent according to the internally defined master-slave communication protocol. Go to the corresponding serial port on the slave to write data to the serial port.
  • the data reading module 430 includes a sending unit 432 and a control unit 434.
  • the sending unit 432 is configured to send a serial port data read request to the slave.
  • the control unit 43 4 is configured to: when the slave responds to the serial port data read request in a preset response time, store data of each serial port of the slave in a corresponding virtual serial port node
  • the control unit 434 is further configured to: when the slave does not respond to the serial port data read request in a preset response time, control the sending unit 432 to the next slave Send a serial data read request.
  • the host and each slave communicate with each other through RS485, due to the electrical characteristics of the RS 485, the communication is prevented from conflicting, and the slaves cannot actively report the information to the host.
  • the application can only wait for the host to read.
  • the host sends a request to read the serial port data to all the slaves in turn by means of rotation training.
  • the optimization principle of the training interval is: after sending a request to the slave to read all the serial port data on the slave, if the slave responds to the request within the preset response time, The data of each of the serial ports of the slave is stored in a buffer of the corresponding virtual serial port node; if the slave does not respond to the request within a preset response time, directly to the slave Send a serial data read request.
  • the integrity of the obtained serial port data can also be verified. After the integrity verification is passed, the data of each of the serial ports of the slave is stored in a buffer of the corresponding virtual serial port node. After the integrity verification fails, the obtained serial port data is discarded, and then the serial port data read request is sent to the slave.
  • the foregoing method can be implemented by means of software plus a necessary general hardware platform, and can also be implemented by hardware, but in many cases.
  • the former is a better implementation.
  • the technical solution of the present invention which is essential or contributes to the prior art, may be embodied in the form of a software product stored in a storage medium (such as ROM/RAM, disk,
  • the optical disc includes a number of instructions for causing a terminal device (which may be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to perform the methods described in various embodiments of the present invention.
  • the address serial code of the corresponding serial port can be obtained through the virtual serial port node, so as to implement data writing to the serial port;
  • the data of the corresponding serial port can be directly obtained by obtaining the data of the corresponding serial port from the buffer area of the virtual serial port node; the technical solution of the invention improves the communication mechanism between the serial port of the host and the slave machine, and effectively improves the host and the The communication efficiency and accuracy of the serial port of the slave.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Transfer Systems (AREA)
  • Communication Control (AREA)

Abstract

Disclosed are a communication control method and control apparatus, belonging to the field of communications. The method comprises: creating a virtual serial port node corresponding to each serial port of each slave on a one-to-one basis; when a data write request sent by a host to the virtual serial port node is received, acquiring, from the virtual serial port node, an address code of a corresponding serial port, and writing, according to the address code, data into the corresponding serial port; and reading data of each serial port of each slave in sequence, and storing the acquired data in a buffer region of a corresponding virtual serial port node, so that the host can read, from the buffer region of each virtual serial port node, the data of the corresponding serial port. The technical solution of the present invention improves a mechanism of communication between a host and a serial port of a slave, thus effectively improving the efficiency and accuracy of communication between the host and the serial port of a slave.

Description

通信控制方法与控制装置 技术领域  Communication control method and control device
[0001] 本发明涉及通信技术领域, 尤其涉及一种通信控制方法与控制装置。  [0001] The present invention relates to the field of communications technologies, and in particular, to a communication control method and a control device.
背景技术  Background technique
[0002] 在实际应用中, 一个作为数据管理的主机通过 RS485与数个从机通信连接。 每 一从机设有数个串口以与前端采集终端连接, 以实现主机与前端采集终端之间 的通信。  [0002] In practical applications, a host that manages data is connected to several slaves via RS485. Each slave has several serial ports to connect with the front-end collection terminal to realize communication between the host and the front-end collection terminal.
[0003] 然而, 随着数据需求量的不断增加, 所需要的从机数量也会逐渐增多, 这就导 致主机与从机的串口通信控制管理越来越复杂, 而且主机和前端采集终端通信 (也即, 主机与从机的串口的通信) 的实吋性也会大大降低, 严重影响了主机 与从机的串口的通信效率。  [0003] However, as the demand for data continues to increase, the number of slaves required will gradually increase, which results in more and more complicated serial port communication control management of the master and the slave, and communication between the host and the front-end acquisition terminal ( That is, the actual communication between the host and the slave's serial port is greatly reduced, which seriously affects the communication efficiency between the host and the slave's serial port.
技术问题  technical problem
[0004] 有鉴于此, 本发明的目的在于提供一种通信控制方法与控制装置, 旨在有效提 高主机与从机的串口的通信效率。  In view of the above, an object of the present invention is to provide a communication control method and control apparatus, which are intended to effectively improve communication efficiency between a host and a slave serial port.
问题的解决方案  Problem solution
技术解决方案  Technical solution
[0005] 为实现上述目的, 本发明提供一种通信控制方法, 用于实现主机与每一从机的 每一串口的通信, 所述通信控制方法包括如下步骤:  [0005] In order to achieve the above object, the present invention provides a communication control method for implementing communication between a host and each serial port of each slave. The communication control method includes the following steps:
[0006] 创建与每一所述从机的每一所述串口一一对应的虚拟串口节点; [0006] creating a virtual serial port node corresponding to each of the serial ports of each of the slaves;
[0007] 在接收到所述主机向所述虚拟串口节点发送的数据写入请求吋, 从所述虚拟串 口节点中获取对应的所述串口的地址编码, 并根据所述地址编码将所述数据写 入对应的所述串口; After receiving the data write request sent by the host to the virtual serial port node, obtaining the address code of the corresponding serial port from the virtual serial port node, and encoding the data according to the address code. Write the corresponding serial port;
[0008] 依次读取每一所述从机的每一所述串口的数据, 并将获取到的所述数据存储于 对应的虚拟串口节点的缓冲区, 以使得所述主机能从每一虚拟串口节点的缓冲 区读取到对应的所述串口的数据。  [0008] sequentially reading data of each of the serial ports of each of the slaves, and storing the obtained data in a buffer of a corresponding virtual serial port node, so that the host can be virtualized from each The buffer of the serial port node reads the data of the corresponding serial port.
[0009] 可选的, 所述创建与每一所述从机的每一所述串口一一对应的虚拟串口节点的 步骤包括: [0009] Optionally, the creating a virtual serial port node corresponding to each of the serial ports of each of the slaves The steps include:
[0010] 获取所述从机的地址编码与所述从机的每一所述串口的地址编码;  [0010] acquiring an address code of the slave and address coding of each of the serial ports of the slave;
[0011] 对应每一所述串口创建一虚拟串口节点;  [0011] creating a virtual serial port node corresponding to each of the serial ports;
[0012] 对所述虚拟串口节点与对应的所述串口做寻址映射。  [0012] performing addressing mapping on the virtual serial port node and the corresponding serial port.
[0013] 可选的, 所述对所述虚拟串口节点与对应的所述串口做寻址映射的步骤包括: [0014] 将所述虚拟串口节点的句柄、 对应的所述从机的地址编码、 对应的所述串口的 地址编码, 以及所述虚拟串口节点的编码进行映射。  [0013] Optionally, the step of performing addressing mapping on the virtual serial port node and the corresponding serial port includes: [0014] encoding a handle of the virtual serial port node and a corresponding address of the slave port And corresponding address encoding of the serial port, and mapping of the virtual serial port node.
[0015] 可选的, 所述在接收到所述主机向所述虚拟串口节点发送数据写入请求吋, 从 所述虚拟串口节点中获取对应的所述串口的地址编码, 并根据所述地址编码将 所述数据写入对应的所述串口的步骤包括: [0015] Optionally, after receiving the data write request to the virtual serial port node, the host obtains an address code of the serial port from the virtual serial port node, and according to the address The step of encoding the data into the corresponding serial port includes:
[0016] 在接收到所述主机向所述虚拟串口节点发送的数据写入请求吋, 判断所述数据 写入请求的类型; 所述数据写入请求包括串口参数设置请求与串口数据写入请 求; [0016] after receiving the data write request sent by the host to the virtual serial port node, determining the type of the data write request; the data write request includes a serial port parameter setting request and a serial port data write request ;
[0017] 当所述数据写入请求为串口参数设置请求吋, 从所述虚拟串口节点中获取对应 的所述串口的地址编码, 并根据所述地址编码将所述串口设置参数写入对应的 所述串口;  [0017] when the data write request is a serial port parameter setting request, obtaining an address code of the corresponding serial port from the virtual serial port node, and writing the serial port setting parameter according to the address code The serial port;
[0018] 当所述数据写入请求为串口数据写入请求吋, 从所述虚拟串口节点中获取对应 的所述串口的地址编码, 并根据所述地址编码将所述串口数据写入对应的所述 串口。  [0018] when the data write request is a serial port data write request, obtaining an address code of the corresponding serial port from the virtual serial port node, and writing the serial port data into a corresponding one according to the address code. The serial port.
[0019] 可选的, 所述依次读取每一所述从机的每一所述串口的数据, 并将获取到的所 述数据存储于对应的虚拟串口节点的缓冲区的步骤包括:  [0019] Optionally, the step of sequentially reading data of each of the serial ports of each of the slaves, and storing the obtained data in a buffer of the corresponding virtual serial port node, includes:
[0020] 向一所述从机发送串口数据读取请求; [0020] sending a serial port data read request to the slave device;
[0021] 当所述从机在预设的响应吋间内响应所述串口数据读取请求吋, 将所述从机的 每一所述串口的数据存储于对应的虚拟串口节点的缓冲区;  [0021] when the slave responds to the serial port data read request in a preset response time, storing data of each serial port of the slave in a buffer of a corresponding virtual serial port node;
[0022] 当所述从机在预设的响应吋间内未响应所述串口数据读取请求吋, 向下一所述 从机发送串口数据读取请求。  [0022] when the slave does not respond to the serial port data read request within a preset response time, send a serial port data read request to the slave.
[0023] 为了实现上述目的, 本发明还提出一种通信控制装置, 用于实现主机与每一从 机的每一串口的通信, 所述通信控制装置包括创建模块、 数据写入模块与数据 读取模块; [0023] In order to achieve the above object, the present invention further provides a communication control apparatus, configured to implement communication between a host and each serial port of each slave, and the communication control apparatus includes a creation module, a data writing module, and data. Reading module
[0024] 所述创建模块, 用于创建与每一所述从机的每一所述串口一一对应的虚拟串口 节点;  [0024] the creating module is configured to create a virtual serial port node corresponding to each of the serial ports of each of the slaves;
[0025] 所述数据写入模块, 用于在接收到所述主机向所述虚拟串口节点发送的数据写 入请求吋, 从所述虚拟串口节点中获取对应的所述串口的地址编码, 并根据所 述地址编码将所述数据写入对应的所述串口;  [0025] the data writing module is configured to: after receiving a data write request sent by the host to the virtual serial port node, obtain an address code of the serial port from the virtual serial port node, and Writing the data to the corresponding serial port according to the address encoding;
[0026] 所述数据读取模块, 用于依次读取每一所述从机的每一所述串口的数据, 并将 获取到的所述数据存储于对应的虚拟串口节点的缓冲区, 以使得所述主机能从 每一虚拟串口节点的缓冲区读取到对应的所述串口的数据。  [0026] the data reading module is configured to sequentially read data of each serial port of each of the slaves, and store the acquired data in a buffer of a corresponding virtual serial port node, The host can read the data of the corresponding serial port from the buffer of each virtual serial port node.
[0027] 可选的, 所述创建模块包括获取单元、 创建单元与映射单元;  [0027] Optionally, the creating module includes an acquiring unit, a creating unit, and a mapping unit.
[0028] 所述获取单元, 用于获取所述从机的地址编码与所述从机的每一所述串口的地 址编码;  [0028] the obtaining unit is configured to acquire an address code of the slave and an address code of each serial port of the slave;
[0029] 所述创建单元, 用于对应每一所述串口创建一虚拟串口节点;  [0029] the creating unit is configured to create a virtual serial port node corresponding to each of the serial ports;
[0030] 所述映射单元, 用于对所述虚拟串口节点与对应的所述串口做寻址映射。  [0030] the mapping unit is configured to perform addressing mapping on the virtual serial port node and the corresponding serial port.
[0031] 可选的, 所述映射单元, 具体用于将所述虚拟串口节点的句柄、 对应的所述从 机的地址编码、 对应的所述串口的地址编码, 以及所述虚拟串口节点的编码进 行映射。  [0031] Optionally, the mapping unit is specifically configured to: code a handle of the virtual serial port node, address code of the corresponding slave device, address code of the corresponding serial port, and the virtual serial port node The code is mapped.
[0032] 可选的, 所述数据写入模块包括判断单元、 串口参数设置单元与串口数据写入 单元;  [0032] Optionally, the data writing module includes a determining unit, a serial port parameter setting unit, and a serial port data writing unit;
[0033] 所述判断单元, 用于在接收到所述主机向所述虚拟串口节点发送的数据写入请 求吋, 判断所述数据写入请求的类型; 所述数据写入请求包括串口参数设置请 求与串口数据写入请求;  [0033] the determining unit is configured to: after receiving the data write request sent by the host to the virtual serial port node, determine a type of the data write request; the data write request includes a serial port parameter setting Request and serial data write request;
[0034] 所述串口参数设置单元, 用于在所述数据写入请求为串口参数设置请求吋, 从 所述虚拟串口节点中获取对应的所述串口的地址编码, 并根据所述地址编码将 所述串口设置参数写入对应的所述串口;  [0034] the serial port parameter setting unit is configured to: after the data write request is a serial port parameter setting request, obtain an address code of the corresponding serial port from the virtual serial port node, and according to the address code Writing, by the serial port setting parameter, the corresponding serial port;
[0035] 所述串口数据写入单元, 用于在所述数据写入请求为串口数据写入请求吋, 从 所述虚拟串口节点中获取对应的所述串口的地址编码, 并根据所述地址编码将 所述串口数据写入对应的所述串口。 [0036] 可选的, 所述数据读取模块包括发送单元与控制单元; [0035] the serial port data writing unit is configured to: after the data writing request is a serial port data writing request, obtain an address code of the serial port from the virtual serial port node, and according to the address The encoding writes the serial port data to the corresponding serial port. [0036] Optionally, the data reading module includes a sending unit and a control unit;
[0037] 所述发送单元, 用于向所述从机发送串口数据读取请求; [0037] the sending unit is configured to send a serial port data read request to the slave device;
[0038] 所述控制单元, 用于在所述从机在预设的响应吋间内响应所述串口数据读取请 求吋, 将所述从机的每一所述串口的数据存储于对应的虚拟串口节点的缓冲区  [0038] the control unit is configured to: when the slave responds to the serial port data read request in a preset response time, store data of each serial port of the slave in a corresponding Virtual serial port node buffer
[0039] 所述控制单元, 还用于在所述从机在预设的响应吋间内未响应所述串口数据读 取请求吋, 控制所述发送单元向下一所述从机发送串口数据读取请求。 [0039] the control unit is further configured to: when the slave does not respond to the serial port data read request in a preset response time, control the sending unit to send serial port data to the slave device Read the request.
发明的有益效果  Advantageous effects of the invention
有益效果  Beneficial effect
[0040] 本发明的技术方案, 通过创建与每一从机的每一所述串口一一对应的虚拟串口 节点, 可以通过虚拟串口节点获取对应的串口的地址编码, 以实现向串口的数 据写入; 还可以通过从虚拟串口节点的缓存区直接获取对应的串口的数据, 以 实现对串口的数据读取; 本发明的技术方案改善了主机与从机的串口之间的通 信机制, 有效提升了主机与从机的串口的通信效率与准确性。  [0040] In the technical solution of the present invention, by creating a virtual serial port node corresponding to each of the serial ports of each slave machine, the address serial code of the corresponding serial port can be obtained through the virtual serial port node, so as to implement data writing to the serial port. The data of the corresponding serial port can be directly obtained by obtaining the data of the corresponding serial port from the buffer area of the virtual serial port node; the technical solution of the invention improves the communication mechanism between the serial port of the host and the slave, and effectively improves The communication efficiency and accuracy of the serial port between the host and the slave.
对附图的简要说明  Brief description of the drawing
附图说明  DRAWINGS
[0041] 图 1为本发明通信控制方法一实施例的流程图;  1 is a flowchart of an embodiment of a communication control method according to the present invention;
[0042] 图 2为图 1中创建与每一所述从机的每一所述串口一一对应的虚拟串口节点的步 骤一实施例的流程图;  2 is a flow chart showing a first embodiment of creating a virtual serial port node corresponding to each of the serial ports of each of the slaves in FIG. 1;
[0043] 图 3为图 1中在接收到所述主机向所述虚拟串口节点发送的数据写入请求吋, 从 所述虚拟串口节点中获取对应的所述串口的地址编码, 并根据所述地址编码将 所述数据写入对应的所述串口的步骤一实施例的流程图;  [0043] FIG. 3 is a diagram showing the address code of the serial port obtained from the virtual serial port node after receiving the data write request sent by the host to the virtual serial port node in FIG. Address code is a flowchart of an embodiment of the step of writing the data into the corresponding serial port;
[0044] 图 4为图 1中依次读取每一所述从机的每一所述串口的数据, 并将获取到的所述 数据存储于对应的虚拟串口节点的缓冲区的步骤一实施例的流程图;  4 is a first step of reading the data of each of the serial ports of each of the slaves in FIG. 1 and storing the acquired data in a buffer of the corresponding virtual serial port node. Flow chart
[0045] 图 5为本发明通信控制装置一实施例的模块示意图;  5 is a schematic block diagram of an embodiment of a communication control apparatus according to the present invention;
[0046] 图 6为图 5中创建模块一实施例的模块示意图;  6 is a schematic block diagram of an embodiment of creating a module in FIG. 5;
[0047] 图 7为图 5中数据写入模块一实施例的模块示意图;  7 is a block diagram of an embodiment of the data writing module of FIG. 5;
[0048] 图 8为图 5中数据读取模块一实施例的模块示意图。 [0049] 本发明目的的实现、 功能特点及优点将结合实施例, 参照附图做进一步说明。 8 is a block diagram of an embodiment of the data reading module of FIG. 5. [0049] The implementation, functional features, and advantages of the present invention will be further described with reference to the accompanying drawings.
本发明的实施方式 Embodiments of the invention
[0050] 在此处键入本发明的实施方式描述段落。 为了使本发明所要解决的技术问题、 技术方案及工业实用性更加清楚、 明白, 以下结合附图和实施例, 对本发明进 行进一步详细说明。 应当理解, 此处所描述的具体实施例仅仅用以解释本发明 [0050] The description paragraphs of the embodiments of the invention are entered here. In order to make the technical problems, technical solutions and industrial applicability of the present invention more clear and clear, the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention.
, 并不用于限定本发明。 It is not intended to limit the invention.
[0051] 如图 1所示, 本发明第一实施例提出的一种通信控制方法, 包括以下步骤: [0052] 步骤 S100、 创建与每一所述从机的每一所述串口一一对应的虚拟串口节点; [0053] 步骤 S200、 在接收到所述主机向所述虚拟串口节点发送的数据写入请求吋, 从 所述虚拟串口节点中获取对应的所述串口的地址编码, 并根据所述地址编码将 所述数据写入对应的所述串口; [0051] As shown in FIG. 1, a communication control method according to a first embodiment of the present invention includes the following steps: [0052] Step S100: creating a one-to-one correspondence with each of the serial ports of each of the slaves a virtual serial port node; [0053] step S200, after receiving a data write request sent by the host to the virtual serial port node, obtaining a corresponding address code of the serial port from the virtual serial port node, and according to The address encoding writes the data to the corresponding serial port;
[0054] 步骤 S300、 依次读取每一所述从机的每一所述串口的数据, 并将获取到的所述 数据存储于对应的虚拟串口节点的缓冲区, 以使得所述主机能从每一虚拟串口 节点的缓冲区读取到对应的所述串口的数据。 [0054] step S300, sequentially reading data of each serial port of each of the slaves, and storing the obtained data in a buffer of the corresponding virtual serial port node, so that the host can The buffer of each virtual serial port node reads the data of the corresponding serial port.
[0055] 其中, 步骤 S200与 S300不分先后, 可以互换。 [0055] Steps S200 and S300 are in no particular order and can be interchanged.
[0056] 在本实施例中, 根据定制的扫描协议, 主机依次向每个从机发送串口信息扫描 请求。 然后根据所述从机返回的串口信息在通信控制装置建立对应的虚拟串口 节点 (本发明中使用的虚拟终端克隆设备是 /dev/ptmx) , 可以指定虚拟串口节 点所在的文件目录和名称 (如, /dev/vtseriall) , 并在对虚拟串口节点进行编号 , 与实际的从机串口使用 struct结构体绑定在一起, 做到一对一的映射。 使用 linu X系统的 i/o异步读写机制 (本发明使用的是 select方法) , 把每个创建的虚拟串口 节点的句柄加入到读写监听队列, 等待事件触发虚拟串口节点的读写。  [0056] In this embodiment, according to the customized scanning protocol, the host sequentially sends a serial port information scanning request to each slave. Then, according to the serial port information returned by the slave, a corresponding virtual serial port node is established in the communication control device (the virtual terminal clone device used in the present invention is /dev/ptmx), and the file directory and name of the virtual serial port node can be specified (for example, , /dev/vtseriall) , and number the virtual serial port nodes, and the actual slave serial port is bound with the struct structure to achieve one-to-one mapping. Using the i/o asynchronous read/write mechanism of the linu X system (the select method is used in the present invention), the handle of each created virtual serial port node is added to the read/write listening queue, and the event is triggered to trigger the reading and writing of the virtual serial port node.
[0057] 具体的, 所述主机与所述从机通过 RS485通信连接; 从机与前端数据采集终端 端采集单元。 当所述主机启动吋, 设置在所述主机侧的通信控制装置按照所述 从机的地址编码依次向连接的所有从机发送扫描请求。 所述从机接收到所述扫 描请求后, 将所述从机的各串口信息响应给所述通信控制装置。 所述通信控制 装置根据各所述串口信息, 在本地创建与每一所述串口一一对应的虚拟串口节 点, 并对所述虚拟串口节点和对应的串口做寻址映射处理。 当所述主机需要对 所述串口进行数据写入吋, 所述主机发送数据写入请求。 所述通信控制装置根 据所述数据写入请求, 在对应的所述虚拟串口节点与所述串口的映射关系中査 找到对应的串口的地址编码。 然后通过 RS485将所述数据写入请求中包含的写入 数据写入所述串口。 当所述主机需要读取所述串口的数据吋, 由于所述通信控 制装置实吋从所述串口中读取所述串口的数据并将读取到的所述数据存储至对 应的虚拟串口节点的缓冲区内, 因此所述主机可以直接从所述虚拟串口的缓冲 区中读取到对应的所述串口的数据。 [0057] Specifically, the host and the slave are connected by RS485 communication; the slave and the front-end data collection terminal collect the unit. When the host is started, the communication control device disposed on the host side sequentially sends a scan request to all connected slaves according to the address code of the slave. After receiving the scan request, the slave device responds to the communication control device with each serial port information of the slave. The communication control device locally creates a virtual serial port section corresponding to each of the serial ports according to each serial port information. Point, and perform addressing mapping processing on the virtual serial port node and the corresponding serial port. When the host needs to write data to the serial port, the host sends a data write request. The communication control device searches for the address code of the corresponding serial port in the mapping relationship between the corresponding virtual serial port node and the serial port according to the data write request. The write data included in the data write request is then written to the serial port via RS485. When the host needs to read the data of the serial port, the communication control device reads the data of the serial port from the serial port and stores the read data to a corresponding virtual serial port node. In the buffer, the host can directly read the data of the corresponding serial port from the buffer of the virtual serial port.
[0058] 本实施例的技术方案, 通过创建与每一从机的每一所述串口一一对应的虚拟串 口节点, 可以通过虚拟串口节点获取对应的串口的地址编码, 以实现向串口的 数据写入; 还可以通过从虚拟串口节点的缓存区直接获取对应的串口的数据, 以实现对串口的数据读取; 本实施例的技术方案改善了主机与从机的串口之间 的通信机制, 有效提升了主机与从机的串口的通信效率与准确性。  [0058] In the technical solution of the embodiment, by creating a virtual serial port node corresponding to each of the serial ports of each slave machine, the address serial code of the corresponding serial port can be obtained through the virtual serial port node, so as to implement data to the serial port. The data can be read from the serial port of the virtual serial port to obtain the data of the serial port. The technical solution of the embodiment improves the communication mechanism between the host and the serial port of the slave. It effectively improves the communication efficiency and accuracy of the serial port between the host and the slave.
[0059] 进一步的, 如图 2所示, 所述创建与每一所述从机的每一所述串口一一对应的 虚拟串口节点的步骤包括:  [0059] Further, as shown in FIG. 2, the step of creating a virtual serial port node corresponding to each of the serial ports of each of the slaves includes:
[0060] 步骤 S110、 获取所述从机的地址编码与所述从机的每一所述串口的地址编码。  [0060] Step S110: Acquire an address code of the slave and an address code of each serial port of the slave.
[0061] 步骤 S120、 对应每一所述串口创建一虚拟串口节点; [0061] Step S120: Create a virtual serial port node corresponding to each of the serial ports.
[0062] 步骤 S130、 对所述虚拟串口节点与对应的所述串口做寻址映射; 具体为将所述 虚拟串口节点的句柄、 对应的所述从机的地址编码、 对应的所述串口的地址编 码, 以及所述虚拟串口节点的编码进行映射。  [0062] Step S130, performing addressing mapping on the virtual serial port node and the corresponding serial port; specifically, the handle of the virtual serial port node, the address of the corresponding slave device, and the corresponding serial port. The address code, and the code of the virtual serial port node are mapped.
[0063] 在本实施例中, 在创建虚拟串口节点之前, 需要依次对每一从机的地址进行编 码; 再对每一所述从机的每一串口的地址进行编码。 比如, 有 N个从机, 每个从 机有 M个串口, 那么, 将所述从机的地址编码依次设置为 0、 1、 2、 ......、 N; 将地址编码为 0的从机的串口的地址编码设置为 1、 2、 3、 ......、 M; 地址编码为 [0063] In this embodiment, before creating a virtual serial port node, the address of each slave device needs to be encoded in sequence; and the address of each serial port of each of the slave devices is encoded. For example, if there are N slaves, each slave has M serial ports, then the address codes of the slaves are sequentially set to 0, 1, 2, ..., N; the address is encoded as 0. The address encoding of the serial port of the slave is set to 1, 2, 3, ..., M; the address code is
1的从机的串口的地址编码为 M+l、 M+2、 M+3、 ......、 M+M; 地址编码为 2的 从机的串口的地址编码为 2M+1、 2M+2、 2M+3、 、 2M+M; ; 地址编 码为 N从机的串口的地址编码为 N*M+1、 N*M+2、 N*M+3、 、 N*M+M。 然 后, 对应 N*M+M个串口, 创建 N*M+M个虚拟串口节点。 对所述虚拟串口节点 与对应的所述串口做寻址映射吋, 可以把所述虚拟串口节点的名称 (命名方式 为 vtSerial+编码, 如 vtseriall) 、 打幵所述虚拟串口节点吋产生的文件描述符、 对 应的所述从机的地址编码, 以及对应所述从机的所述串口的编码使用 C语言 struct 结构体的形式绑定到一起, 形成一个虚拟串口节点信息的内部映射, 然后, 把 所有串口的结构体信息存储到一个 list链表中。 当所述主机的应用程序在通过所 述寻串口节点的名称操作对应的所述串口吋, 通信控制装置就可以根据打幵所 述虚拟串口节点的文件描述符从 list链表中找到该所述虚拟串口节点的结构体信 息, 解析出所述虚拟串口节点对应的从机的地址编码和对应从机的串口的地址 编码, 做出正确的串口寻址, 有效提升了通信效率。 The address of the slave serial port of 1 is M+l, M+2, M+3, ..., M+M; the address of the serial port of the slave with address code 2 is 2M+1. 2M+2, 2M+3, 2M+M; ; The address code of the serial port whose address code is N slave is N*M+1, N*M+2, N*M+3, N*M+M . Then, corresponding to N*M+M serial ports, N*M+M virtual serial port nodes are created. The virtual serial port node After addressing the corresponding serial port, the name of the virtual serial port node (named vt Se rial+ code, such as vtseriall), the file descriptor generated by the virtual serial port node, corresponding file identifier The address encoding of the slave, and the encoding of the serial port corresponding to the slave are bound together using a C language struct structure to form an internal mapping of virtual serial node information, and then, the structure of all serial ports The body information is stored in a list of linked lists. When the application of the host operates the corresponding serial port through the name of the serial port node, the communication control device can find the virtual device from the list list according to the file descriptor of the virtual serial port node. The structure information of the serial port node parses out the address code of the slave corresponding to the virtual serial port node and the address code of the serial port of the corresponding slave device, and makes correct serial port addressing, thereby effectively improving communication efficiency.
[0064] 值得一提的是, 当对所述从机的扫描在一定的吋间内没有响应吋, 将该从机加 入扫描失败队列, 并在后续对扫描失败队列中从机按照预设的吋间间隔轮训扫 描。 在映射关系建立完成后, 把句柄加入 select I/O监听列表, 幵始监听虚拟串口 节点的读写操作。 [0064] It is worth mentioning that when the scan of the slave does not respond within a certain time, the slave is added to the scan failure queue, and the slave follows the preset in the subsequent scan failure queue. Inter-turn interval training scan. After the mapping relationship is established, the handle is added to the select I/O listening list, and the virtual serial port node is read and written.
[0065] 进一步的, 如图 3所示, 所述在接收到所述主机向所述虚拟串口节点发送的数 据写入请求吋, 从所述虚拟串口节点中获取对应的所述串口的地址编码, 并根 据所述地址编码将所述数据写入对应的所述串口的步骤包括:  [0065] Further, as shown in FIG. 3, after receiving the data write request sent by the host to the virtual serial port node, obtaining the address code of the corresponding serial port from the virtual serial port node And the step of writing the data to the corresponding serial port according to the address code includes:
[0066] 步骤 S210、 接收所述主机向所述虚拟串口节点发送的数据写入请求。  [0066] Step S210: Receive a data write request sent by the host to the virtual serial port node.
[0067] 步骤 S220、 判断所述数据写入请求是否为串口参数设置请求; 如果是, 则执行 步骤 230; 如果否, 则执行步骤 S240。  [0067] Step S220: Determine whether the data write request is a serial port parameter setting request; if yes, execute step 230; if no, execute step S240.
[0068] 步骤 230、 从所述虚拟串口节点中获取对应的所述串口的地址编码, 并根据所 述地址编码将所述串口设置参数写入对应的所述串口。  [0068] Step 230: Obtain an address code of the corresponding serial port from the virtual serial port node, and write the serial port setting parameter to the corresponding serial port according to the address code.
[0069] 步骤 240、 从所述虚拟串口节点中获取对应的所述串口的地址编码, 并根据所 述地址编码将所述串口数据写入对应的所述串口。 在本实施例中, 所述主机的 应用程序通过系统标准 I/O的 open函数打幵虚拟串口节点 (比如: open (vtseriall , 0_RDWR) ) 后, 通过 Linux系统标准的 write函数访问虚拟串口节点, 并通过 虚拟驱动层将数据写入请求发送给通信控制装置, 通信控制装置根据下表 1与下 表 2定义的数据帧格式, 解析出数据写入请求的类型。 当所述数据写入请求为串 口参数设置请求吋, 从虚拟串口节点的虚拟串口节点 list表中査询到虚拟串口节 点对应的从机串口, 把解析后的串口通信参数按照内部定义的主从式通信协议 发给相应的从机上, 以便从机对相应的串口进行设置。 当所述数据写入请求为 串口数据写入请求吋, 从虚拟串口节点 list表中寻址到虚拟串口节点对应的从机 串口, 把解析出来的串口数据按照内部定义的主从式通信协议发送到从机上的 对应的串口, 以便对串口进行数据写入。 [0069] Step 240: Obtain an address code of the corresponding serial port from the virtual serial port node, and write the serial port data to the corresponding serial port according to the address code. In this embodiment, the application of the host accesses the virtual serial port node (for example, open (vtseriall, 0_RDWR)) through the open function of the system standard I/O, and accesses the virtual serial port node through the standard write function of the Linux system. And the data write request is sent to the communication control device through the virtual drive layer, and the communication control device parses the type of the data write request according to the data frame format defined in Table 1 below and Table 2 below. When the data write request is a serial port parameter setting request, the virtual serial port node is queried from the virtual serial port node list table of the virtual serial port node. Point the corresponding slave serial port, and send the parsed serial communication parameters to the corresponding slave according to the internally defined master-slave communication protocol, so that the slave can set the corresponding serial port. When the data write request is a serial port data write request, the virtual serial port node list is addressed to the slave serial port corresponding to the virtual serial port node, and the parsed serial port data is sent according to the internally defined master-slave communication protocol. Go to the corresponding serial port on the slave to write data to the serial port.
[0070] 表 1  Table 1
[] []
通 1  Pass 1
 嶋
德 i  De i
m m
 Blue
Figure imgf000010_0001
Figure imgf000010_0001
[0071] 表 2  Table 2
[] 1 纖逑 [] 1 逑
戮纖麵 1后國賴獰:数攝錄《度^  戮 面 1 1 After the country Lai 狞: number of recordings "degree ^
1 ! φ寧祷  1 ! φ宁祈
攀》靈鏺 " 零養攀 ¾ 鐘東雜 ; Climb "Ling Po" zero-raising climb ¾ bell east miscellaneous;
[0072] 进一步的, 如图 4所示, 所述依次读取每一所述从机的每一所述串口的数据, 并将获取到的所述数据存储于对应的虚拟串口节点的缓冲区的步骤包括: [0072] Further, as shown in FIG. 4, the data of each serial port of each of the slaves is sequentially read, and the obtained data is stored in a buffer of a corresponding virtual serial port node. The steps include:
[0073] 步骤 S310、 向一所述从机发送串口数据读取请求;  [0073] step S310, sending a serial port data read request to a slave device;
[0074] 步骤 S320、 判断从机是否在预设的响应吋间内响应该读取请求; 如果是, 则执 行步骤 S330, 如果否, 则执行步骤 S340。 [0074] Step S320: determining whether the slave responds to the read request within a preset response time; if yes, executing step S330, and if no, executing step S340.
[0075] 步骤 S330、 将所述从机的每一所述串口的数据存储于对应的虚拟串口节点的缓 冲区;  [0075] Step S330, storing data of each serial port of the slave device in a buffer area of the corresponding virtual serial port node;
[0076] 步骤 S340、 向下一所述从机发送串口数据读取请求。  [0076] Step S340: Send a serial port data read request to the next slave.
[0077] 在本实施例中, 由于主机和各个从机之间是通过 RS485实现通信连接, 由于 RS 485的电气特性, 防止通信出现冲突冒险, 各个从机不能主动上报信息给主机的 应用程序, 只能等待主机读取, 主机通过轮训的方式对所有的从机依次下发读 取串口数据的请求。 为了提高轮训效率, 这里对轮训间隔的优化原则是: 当向 从机发送读取从机上所有串口数据的请求后, 如果所述从机在预设的响应吋间 内响应了该请求, 则将所述从机的每一所述串口的数据存储于对应的虚拟串口 节点的缓冲区; 如果所述从机在预设的响应吋间内未响应该请求, 则直接向下 一所述从机发送串口数据读取请求。 [0077] In this embodiment, since the host and each slave communicate with each other through RS485, due to the electrical characteristics of the RS 485, the communication is prevented from conflicting, and the slaves cannot actively report the information to the host. The application can only wait for the host to read. The host sends a request to read the serial port data to all the slaves in turn by means of rotation training. In order to improve the efficiency of the rotation training, the optimization principle of the training interval is: after sending a request to the slave to read all the serial port data on the slave, if the slave responds to the request within the preset response time, The data of each of the serial ports of the slave is stored in a buffer of the corresponding virtual serial port node; if the slave does not respond to the request within a preset response time, directly to the slave Send a serial data read request.
[0078] 值得一提的是, 在从机响应了串口数据读取请求后, 还可以对获取到的串口数 据的完整性进行验证。 在完整性验证通过吋, 将所述从机的每一所述串口的数 据存储于对应的虚拟串口节点的缓冲区。 在完整性验证不通过吋, 将获取到的 串口数据丢弃, 然后向下一所述从机发送串口数据读取请求。  [0078] It is worth mentioning that after the slave responds to the serial port data read request, the integrity of the obtained serial port data can also be verified. After the integrity verification is passed, the data of each of the serial ports of the slave is stored in a buffer of the corresponding virtual serial port node. After the integrity verification fails, the obtained serial port data is discarded, and then the serial port data read request is sent to the slave.
[0079] 如图 5所示, 本发明第一实施例提出的一种通信控制装置, 用于实现主机与每 一从机的每一串口的通信, 在本实施例中, 所述通信控制装置包括创建模块 410 、 数据写入模块 420与数据读取模块 430; 所述创建模块 410, 用于创建与每一所 述从机的每一所述串口一一对应的虚拟串口节点; 所述数据写入模块 420, 用于 在接收到所述主机向所述虚拟串口节点发送的数据写入请求吋, 从所述虚拟串 口节点中获取对应的所述串口的地址编码, 并根据所述地址编码将所述数据写 入对应的所述串口; 所述数据读取模块 430, 用于依次读取每一所述从机的每一 所述串口的数据, 并将获取到的所述数据存储于对应的虚拟串口节点的缓冲区 , 以使得所述主机能从每一虚拟串口节点的缓冲区读取到对应的所述串口的数 据。  [0079] As shown in FIG. 5, a communication control apparatus according to a first embodiment of the present invention is configured to implement communication between a host and each serial port of each slave. In this embodiment, the communication control apparatus The creating module 410 is configured to create a virtual serial port node corresponding to each of the serial ports of each of the slaves; the data a writing module 420, configured to: after receiving a data write request sent by the host to the virtual serial port node, obtain an address code of the serial port from the virtual serial port node, and encode according to the address Write the data to the corresponding serial port; the data reading module 430 is configured to sequentially read data of each serial port of each of the slaves, and store the acquired data in the data. Corresponding buffers of the virtual serial port nodes, so that the host can read data of the corresponding serial port from the buffer of each virtual serial port node.
[0080] 在本实施例中, 根据定制的扫描协议, 主机依次向每个从机发送串口信息扫描 请求。 然后根据所述从机返回的串口信息在通信控制装置建立对应的虚拟串口 节点 (本发明中使用的虚拟终端克隆设备是 /dev/ptmx) , 可以指定虚拟串口节 点所在的文件目录和名称 (如, /dev/vtseriall) , 并在对虚拟串口节点进行编号 , 与实际的从机串口使用 struct结构体绑定在一起, 做到一对一的映射。 使用 linu X系统的 i/o异步读写机制 (本发明使用的是 select方法) , 把每个创建的虚拟串口 节点的句柄加入到读写监听队列, 等待事件触发虚拟串口节点的读写。  [0080] In this embodiment, according to the customized scanning protocol, the host sequentially sends a serial port information scanning request to each slave. Then, according to the serial port information returned by the slave, a corresponding virtual serial port node is established in the communication control device (the virtual terminal clone device used in the present invention is /dev/ptmx), and the file directory and name of the virtual serial port node can be specified (for example, , /dev/vtseriall) , and number the virtual serial port nodes, and the actual slave serial port is bound with the struct structure to achieve one-to-one mapping. Using the i/o asynchronous read/write mechanism of the linu X system (the select method is used in the present invention), the handle of each created virtual serial port node is added to the read/write listening queue, and the event is triggered to trigger the reading and writing of the virtual serial port node.
[0081] 具体的, 所述主机与所述从机通过 RS485通信连接。 当所述主机启动吋, 设置 在所述主机侧的通信控制装置按照所述从机的地址编码依次向连接的所有从机 发送扫描请求。 所述从机接收到所述扫描请求后, 将所述从机的各串口信息响 应给所述通信控制装置。 所述通信控制装置根据各所述串口信息, 在本地创建 与每一所述串口一一对应的虚拟串口节点, 并对所述虚拟串口节点和对应的串 口做寻址映射处理。 当所述主机需要对所述串口进行数据写入吋, 所述主机发 送数据写入请求。 所述通信控制装置根据所述数据写入请求, 在对应的所述虚 拟串口节点与所述串口的映射关系中査找到对应的串口的地址编码。 然后通过 R S485将所述数据写入请求中包含的写入数据写入所述串口。 当所述主机需要读 取所述串口的数据吋, 由于所述通信控制装置实吋从所述串口中读取所述串口 的数据并将读取到的所述数据存储至对应的虚拟串口节点的缓冲区内, 因此所 述主机可以直接从所述虚拟串口的缓冲区中读取到对应的所述串口的数据。 [0081] Specifically, the host and the slave are connected by RS485 communication. When the host is started, set The communication control device on the host side sequentially transmits a scan request to all connected slaves in accordance with the address code of the slave. After receiving the scan request, the slave device responds to the communication control device with each serial port information of the slave. The communication control device locally creates a virtual serial port node corresponding to each of the serial ports in a local manner according to each of the serial port information, and performs address mapping processing on the virtual serial port node and the corresponding serial port. When the host needs to write data to the serial port, the host sends a data write request. The communication control device searches for the address code of the corresponding serial port in the mapping relationship between the corresponding virtual serial port node and the serial port according to the data write request. The write data contained in the data write request is then written to the serial port via R S485. When the host needs to read the data of the serial port, the communication control device reads the data of the serial port from the serial port and stores the read data to a corresponding virtual serial port node. In the buffer, the host can directly read the data of the corresponding serial port from the buffer of the virtual serial port.
[0082] 本实施例的技术方案, 通过创建与每一从机的每一所述串口一一对应的虚拟串 口节点, 可以通过虚拟串口节点获取对应的串口的地址编码, 以实现向串口的 数据写入; 还可以通过从虚拟串口节点的缓存区直接获取对应的串口的数据, 以实现对串口的数据读取; 本实施例的技术方案改善了主机与从机的串口之间 的通信机制, 有效提升了主机与从机的串口的通信效率与准确性。  [0082] In the technical solution of the embodiment, by creating a virtual serial port node corresponding to each of the serial ports of each slave machine, the address serial code of the corresponding serial port can be obtained through the virtual serial port node, so as to implement data to the serial port. The data can be read from the serial port of the virtual serial port to obtain the data of the serial port. The technical solution of the embodiment improves the communication mechanism between the host and the serial port of the slave. It effectively improves the communication efficiency and accuracy of the serial port between the host and the slave.
[0083] 进一步的, 如图 6所示, 所述创建模块 410包括获取单元 412、 创建单元 414与映 射单元 416; 所述获取单元 412, 用于获取所述从机的地址编码与所述从机的每 一所述串口的地址编码; 所述创建单元 414, 用于对应每一所述串口创建一虚拟 串口节点; 所述映射单元 416, 用于对所述虚拟串口节点与对应的所述串口做寻 址映射。 所述映射单元 416, 具体用于将所述虚拟串口节点的句柄、 对应的所述 从机的地址编码、 对应的所述串口的地址编码, 以及所述虚拟串口节点的编码 进行映射。  [0083] Further, as shown in FIG. 6, the creating module 410 includes an obtaining unit 412, a creating unit 414, and a mapping unit 416. The obtaining unit 412 is configured to acquire an address code of the slave and the slave. The address of each of the serial ports of the machine is encoded; the creating unit 414 is configured to create a virtual serial port node corresponding to each of the serial ports; the mapping unit 416 is configured to the virtual serial port node and the corresponding The serial port does the addressing mapping. The mapping unit 416 is specifically configured to map the handle of the virtual serial port node, the address encoding of the corresponding slave, the address encoding of the corresponding serial port, and the encoding of the virtual serial port node.
[0084] 在本实施例中, 在创建虚拟串口节点之前, 需要依次对每一从机的地址进行编 码; 再对每一所述从机的每一串口的地址进行编码。 比如, 有 N个从机, 每个从 机有 M个串口, 那么, 将所述从机的地址编码依次设置为 0、 1、 2、 ......、 N; 将地址编码为 0的从机的串口的地址编码设置为 1、 2、 3、 ......、 M; 地址编码为 [0084] In this embodiment, before creating a virtual serial port node, the address of each slave device needs to be encoded in sequence; and the address of each serial port of each of the slave devices is encoded. For example, if there are N slaves, each slave has M serial ports, then the address codes of the slaves are sequentially set to 0, 1, 2, ..., N; the address is encoded as 0. The address encoding of the serial port of the slave is set to 1, 2, 3, ..., M; the address code is
1的从机的串口的地址编码为 M+l、 M+2、 M+3、 ......、 M+M; 地址编码为 2的 从机的串口的地址编码为 2M+1、 2M+2、 2M+3、 、 2M+M; ; 地址编 码为 N从机的串口的地址编码为 N*M+1、 N*M+2、 N*M+3、 、 N*M+M。 然 后, 对应 N*M+M个串口, 创建 N*M+M个虚拟串口节点。 对所述虚拟串口节点 与对应的所述串口做寻址映射吋, 可以把所述虚拟串口节点的名称 (命名方式 为 vtSerial+编码, 如 vtseriall) 、 打幵所述虚拟串口节点吋产生的文件描述符、 对 应的所述从机的地址编码, 以及对应所述从机的所述串口的编码使用 C语言 struct 结构体的形式绑定到一起, 形成一个虚拟串口节点信息的内部映射, 然后, 把 所有串口的结构体信息存储到一个 list链表中。 当所述主机的应用程序在通过所 述寻串口节点的名称操作对应的所述串口吋, 通信控制装置就可以根据打幵所 述虚拟串口节点的文件描述符从 list链表中找到该所述虚拟串口节点的结构体信 息, 解析出所述虚拟串口节点对应的从机的地址编码和对应从机的串口的地址 编码, 做出正确的串口寻址, 有效提升了通信效率。 The address of the serial port of the slave is 1 M+l, M+2, M+3, ..., M+M; the address code is 2 The address code of the serial port of the slave is 2M+1, 2M+2, 2M+3, 2M+M; The address code of the serial port whose address code is N slave is N*M+1, N*M+2 N*M+3, , N*M+M. Then, corresponding to N*M+M serial ports, N*M+M virtual serial port nodes are created. After the virtual serial port node is mapped to the corresponding serial port, the name of the virtual serial port node (named vt Se rial+ code, such as vtseriall), and the virtual serial port node are generated. a file descriptor, a corresponding address encoding of the slave, and an encoding of the serial port corresponding to the slave are bound together in a form of a C language struct structure to form an internal mapping of virtual serial port node information, and then , store all serial port structure information in a list linked list. When the application of the host operates the corresponding serial port through the name of the serial port node, the communication control device can find the virtual device from the list list according to the file descriptor of the virtual serial port node. The structure information of the serial port node parses out the address code of the slave corresponding to the virtual serial port node and the address code of the serial port of the corresponding slave device, and makes correct serial port addressing, thereby effectively improving communication efficiency.
[0085] 值得一提的是, 当对所述从机的扫描在一定的吋间内没有响应吋, 将该从机加 入扫描失败队列, 并在后续对扫描失败队列中从机按照预设的吋间间隔轮训扫 描。 在映射关系建立完成后, 把句柄加入 select I/O监听列表, 幵始监听虚拟串口 节点的读写操作。 [0085] It is worth mentioning that when the scan of the slave does not respond within a certain time, the slave is added to the scan failure queue, and the slave follows the preset in the subsequent scan failure queue. Inter-turn interval training scan. After the mapping relationship is established, the handle is added to the select I/O listening list, and the virtual serial port node is read and written.
[0086] 进一步的, 如图 7所示, 所述数据写入模块 420包括判断单元 422、 串口参数设 置单元 424与串口数据写入单元 426; 所述判断单元 422, 用于在接收到所述主机 向所述虚拟串口节点发送的数据写入请求吋, 判断所述数据写入请求的类型; 所述数据写入请求包括串口参数设置请求与串口数据写入请求; 所述串口参数 设置单元 424, 用于在所述数据写入请求为串口参数设置请求吋, 从所述虚拟串 口节点中获取对应的所述串口的地址编码, 并根据所述地址编码将所述串口设 置参数写入对应的所述串口; 所述串口数据写入单元 426, 用于在所述数据写入 请求为串口数据写入请求吋, 从所述虚拟串口节点中获取对应的所述串口的地 址编码, 并根据所述地址编码将所述串口数据写入对应的所述串口。  [0086] Further, as shown in FIG. 7, the data writing module 420 includes a determining unit 422, a serial port parameter setting unit 424, and a serial port data writing unit 426. The determining unit 422 is configured to receive the Determining, by the host, a data write request to the virtual serial port node, determining a type of the data write request; the data write request includes a serial port parameter setting request and a serial port data write request; and the serial port parameter setting unit 424 And configured to: after the data write request is a serial port parameter setting request, obtain an address code of the serial port from the virtual serial port node, and write the serial port setting parameter into a corresponding one according to the address code. The serial port data writing unit 426 is configured to: after the data write request is a serial port data write request, obtain the address code of the serial port from the virtual serial port node, and according to the The address code writes the serial port data to the corresponding serial port.
[0087] 在本实施例中, 所述主机的应用程序通过系统标准 I/O的 open函数打幵虚拟串 口节点 (比如: open (vtseriall , 0_RDWR) ) 后, 通过 Linux系统标准的 write 函数访问虚拟串口节点, 并通过虚拟驱动层将数据写入请求发送给通信控制装 置, 通信控制装置根据下表 1与下表 2定义的数据帧格式, 解析出数据写入请求 的类型。 当所述数据写入请求为串口参数设置请求吋, 从虚拟串口节点的虚拟 串口节点 list表中査询到虚拟串口节点对应的从机串口, 把解析后的串口通信参 数按照内部定义的主从式通信协议发给相应的从机上, 以便从机对相应的串口 进行设置。 当所述数据写入请求为串口数据写入请求吋, 从虚拟串口节点 list表 中寻址到虚拟串口节点对应的从机串口, 把解析出来的串口数据按照内部定义 的主从式通信协议发送到从机上的对应的串口, 以便对串口进行数据写入。 [0087] In this embodiment, the application of the host accesses the virtual serial port node (for example: open (vtseriall, 0_RDWR)) through the open function of the system standard I/O, and accesses the virtual function through the standard write function of the Linux system. Serial port node, and send data write request to communication control device through virtual drive layer The communication control device parses out the type of the data write request according to the data frame format defined in Table 1 below and Table 2 below. When the data write request is a serial port parameter setting request, the virtual serial port node list table of the virtual serial port node is queried to the slave serial port corresponding to the virtual serial port node, and the parsed serial port communication parameter is determined according to the internally defined master-slave The communication protocol is sent to the corresponding slave, so that the slave can set the corresponding serial port. When the data write request is a serial port data write request, the virtual serial port node list is addressed to the slave serial port corresponding to the virtual serial port node, and the parsed serial port data is sent according to the internally defined master-slave communication protocol. Go to the corresponding serial port on the slave to write data to the serial port.
[0088] 表 1  [0088] Table 1
Figure imgf000014_0001
Figure imgf000014_0001
[0089]  [0089]
"  "
[] 應纖数握鶴儘 j寧节< [] Should count the number of cranes
4  4
从稱變續儀 ,«續¾寧 :数鸛 I '个寧街  From the continuation of the instrument, «Continue 3⁄4 Ning: Number 鹳 I 'Ning Street
I率賺鑣隱 T 請寧 <包麵雜:  I rate earned a hidden T Please Ning
[0090] 进一步的, 如图 8所示, 所述数据读取模块 430包括发送单元 432与控制单元 434 ; 所述发送单元 432, 用于向所述从机发送串口数据读取请求; 所述控制单元 43 4, 用于在所述从机在预设的响应吋间内响应所述串口数据读取请求吋, 将所述 从机的每一所述串口的数据存储于对应的虚拟串口节点的缓冲区; 所述控制单 元 434, 还用于在所述从机在预设的响应吋间内未响应所述串口数据读取请求吋 , 控制所述发送单元 432向下一所述从机发送串口数据读取请求。 [0090] Further, as shown in FIG. 8, the data reading module 430 includes a sending unit 432 and a control unit 434. The sending unit 432 is configured to send a serial port data read request to the slave. The control unit 43 4 is configured to: when the slave responds to the serial port data read request in a preset response time, store data of each serial port of the slave in a corresponding virtual serial port node The control unit 434 is further configured to: when the slave does not respond to the serial port data read request in a preset response time, control the sending unit 432 to the next slave Send a serial data read request.
[0091] 在本实施例中, 由于主机和各个从机之间是通过 RS485实现通信连接, 由于 RS 485的电气特性, 防止通信出现冲突冒险, 各个从机不能主动上报信息给主机的 应用程序, 只能等待主机读取, 主机通过轮训的方式对所有的从机依次下发读 取串口数据的请求。 为了提高轮训效率, 这里对轮训间隔的优化原则是: 当向 从机发送读取从机上所有串口数据的请求后, 如果所述从机在预设的响应吋间 内响应了该请求, 则将所述从机的每一所述串口的数据存储于对应的虚拟串口 节点的缓冲区; 如果所述从机在预设的响应吋间内未响应该请求, 则直接向下 一所述从机发送串口数据读取请求。 [0091] In this embodiment, since the host and each slave communicate with each other through RS485, due to the electrical characteristics of the RS 485, the communication is prevented from conflicting, and the slaves cannot actively report the information to the host. The application can only wait for the host to read. The host sends a request to read the serial port data to all the slaves in turn by means of rotation training. In order to improve the efficiency of the rotation training, the optimization principle of the training interval is: after sending a request to the slave to read all the serial port data on the slave, if the slave responds to the request within the preset response time, The data of each of the serial ports of the slave is stored in a buffer of the corresponding virtual serial port node; if the slave does not respond to the request within a preset response time, directly to the slave Send a serial data read request.
[0092] 值得一提的是, 在从机响应了串口数据读取请求后, 还可以对获取到的串口数 据的完整性进行验证。 在完整性验证通过吋, 将所述从机的每一所述串口的数 据存储于对应的虚拟串口节点的缓冲区。 在完整性验证不通过吋, 将获取到的 串口数据丢弃, 然后向下一所述从机发送串口数据读取请求。  [0092] It is worth mentioning that after the slave responds to the serial port data read request, the integrity of the obtained serial port data can also be verified. After the integrity verification is passed, the data of each of the serial ports of the slave is stored in a buffer of the corresponding virtual serial port node. After the integrity verification fails, the obtained serial port data is discarded, and then the serial port data read request is sent to the slave.
[0093] 需要说明的是, 在本文中, 术语"包括"、 "包含 "或者其任何其他变体意在涵盖 非排他性的包含, 从而使得包括一系列要素的过程、 方法、 物品或者装置不仅 包括那些要素, 而且还包括没有明确列出的其他要素, 或者是还包括为这种过 程、 方法、 物品或者装置所固有的要素。 在没有更多限制的情况下, 由语句 "包 括一个 ...... "限定的要素, 并不排除在包括该要素的过程、 方法、 物品或者装置 中还存在另外的相同要素。  [0093] It is to be understood that the terms "comprising", "comprising", or any other variations thereof are intended to encompass a non-exclusive inclusion, such that a process, method, article or device comprising a Those elements, but also other elements not explicitly listed, or elements that are inherent to such a process, method, item or device. An element defined by the phrase "comprises a ..." without further restrictions does not exclude the presence of additional elements in the process, method, article, or device that comprises the element.
[0094] 通过以上的实施方式的描述, 本领域的技术人员可以清楚地了解到上述实施例 方法可借助软件加必需的通用硬件平台的方式来实现, 当然也可以通过硬件来 实现, 但很多情况下前者是更佳的实施方式。 基于这样的理解, 本发明的技术 方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来 , 该计算机软件产品存储在一个存储介质 (如 ROM/RAM、 磁碟、 光盘) 中, 包 括若干指令用以使得一台终端设备 (可以是手机, 计算机, 服务器, 空调器, 或者网络设备等) 执行本发明各个实施例所述的方法。  Through the description of the above embodiments, those skilled in the art can clearly understand that the foregoing method can be implemented by means of software plus a necessary general hardware platform, and can also be implemented by hardware, but in many cases. The former is a better implementation. Based on such understanding, the technical solution of the present invention, which is essential or contributes to the prior art, may be embodied in the form of a software product stored in a storage medium (such as ROM/RAM, disk, The optical disc includes a number of instructions for causing a terminal device (which may be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to perform the methods described in various embodiments of the present invention.
[0095] 以上参照附图说明了本发明的优选实施例, 并非因此局限本发明的权利范围。  The preferred embodiments of the present invention have been described above with reference to the drawings, and are not intended to limit the scope of the invention.
上述本发明实施例序号仅仅为了描述, 不代表实施例的优劣。 另外, 虽然在流 程图中示出了逻辑顺序, 但是在某些情况下, 可以以不同于此处的顺序执行所 示出或描述的步骤。  The serial numbers of the embodiments of the present invention are merely for the description, and do not represent the advantages and disadvantages of the embodiments. In addition, although the logical order is shown in the flowchart, in some cases the steps shown or described may be performed in a different order than the ones described herein.
[0096] 本领域技术人员不脱离本发明的范围和实质, 可以有多种变型方案实现本发明 , 比如作为一个实施例的特征可用于另一实施例而得到又一实施例。 凡在运用 本发明的技术构思之内所作的任何修改、 等同替换和改进, 均应在本发明的权 利范围之内。 [0096] Those skilled in the art can implement the present invention in various variants without departing from the scope and spirit of the invention. For example, features that are one embodiment may be used in another embodiment to yield yet another embodiment. Any modifications, equivalent substitutions and improvements made within the technical concept of the invention are intended to be included within the scope of the invention.
工业实用性 Industrial applicability
本发明的技术方案, 通过创建与每一从机的每一所述串口一一对应的虚拟串口 节点, 可以通过虚拟串口节点获取对应的串口的地址编码, 以实现向串口的数 据写入; 还可以通过从虚拟串口节点的缓存区直接获取对应的串口的数据, 以 实现对串口的数据读取; 本发明的技术方案改善了主机与从机的串口之间的通 信机制, 有效提升了主机与从机的串口的通信效率与准确性。  According to the technical solution of the present invention, by creating a virtual serial port node corresponding to each of the serial ports of each slave machine, the address serial code of the corresponding serial port can be obtained through the virtual serial port node, so as to implement data writing to the serial port; The data of the corresponding serial port can be directly obtained by obtaining the data of the corresponding serial port from the buffer area of the virtual serial port node; the technical solution of the invention improves the communication mechanism between the serial port of the host and the slave machine, and effectively improves the host and the The communication efficiency and accuracy of the serial port of the slave.

Claims

权利要求书 Claim
[权利要求 1] 一种通信控制方法, 用于实现主机与每一从机的每一串口的通信, 所 述通信控制方法包括如下步骤:  [Claim 1] A communication control method for implementing communication between a host and each serial port of each slave, the communication control method comprising the following steps:
创建与每一所述从机的每一所述串口一一对应的虚拟串口节点; 在接收到所述主机向所述虚拟串口节点发送的数据写入请求吋, 从所 述虚拟串口节点中获取对应的所述串口的地址编码, 并根据所述地址 编码将所述数据写入对应的所述串口;  Creating a virtual serial port node corresponding to each of the serial ports of each of the slaves; and receiving a data write request sent by the host to the virtual serial port node, acquiring from the virtual serial port node Corresponding address encoding of the serial port, and writing the data to the corresponding serial port according to the address encoding;
依次读取每一所述从机的每一所述串口的数据, 并将获取到的所述数 据存储于对应的虚拟串口节点的缓冲区, 以使得所述主机能从每一虚 拟串口节点的缓冲区读取到对应的所述串口的数据。  And sequentially reading data of each of the serial ports of each of the slaves, and storing the obtained data in a buffer of a corresponding virtual serial port node, so that the host can be from each virtual serial port node. The buffer reads the data of the corresponding serial port.
[权利要求 2] 如权利要求 1所述的通信控制方法, 其中, 所述创建与每一所述从机 的每一所述串口一一对应的虚拟串口节点的步骤包括:  [Claim 2] The communication control method according to claim 1, wherein the step of creating a virtual serial port node corresponding to each of the serial ports of each of the slaves comprises:
获取所述从机的地址编码与所述从机的每一所述串口的地址编码; 对应每一所述串口创建一虚拟串口节点;  Obtaining an address code of the slave and an address code of each serial port of the slave; creating a virtual serial port node corresponding to each of the serial ports;
对所述虚拟串口节点与对应的所述串口做寻址映射。  Performing addressing mapping on the virtual serial port node and the corresponding serial port.
[权利要求 3] 如权利要求 2所述的通信控制方法, 其中, 所述对所述虚拟串口节点 与对应的所述串口做寻址映射的步骤包括:  [Claim 3] The communication control method according to claim 2, wherein the step of performing addressing mapping on the virtual serial port node and the corresponding serial port includes:
将所述虚拟串口节点的句柄、 对应的所述从机的地址编码、 对应的所 述串口的地址编码, 以及所述虚拟串口节点的编码进行映射。  And mapping the handle of the virtual serial port node, the address code of the corresponding slave, the address code of the corresponding serial port, and the code of the virtual serial port node.
[权利要求 4] 如权利要求 1所述的通信控制方法, 其中, 所述在接收到所述主机向 所述虚拟串口节点发送数据写入请求吋, 从所述虚拟串口节点中获取 对应的所述串口的地址编码, 并根据所述地址编码将所述数据写入对 应的所述串口的步骤包括: 在接收到所述主机向所述虚拟串口节点发送的数据写入请求吋, 判断 所述数据写入请求的类型; 所述数据写入请求包括串口参数设置请求 与串口数据写入请求; [Claim 4] The communication control method according to claim 1, wherein, after receiving the data write request to the virtual serial port node, the host obtains a corresponding location from the virtual serial port node The step of encoding the address of the serial port and writing the data to the corresponding serial port according to the address code includes: after receiving the data write request sent by the host to the virtual serial port node, determining the The type of the data write request; the data write request includes a serial port parameter setting request and a serial port data write request;
当所述数据写入请求为串口参数设置请求吋, 从所述虚拟串口节点中 获取对应的所述串口的地址编码, 并根据所述地址编码将所述串口设 置参数写入对应的所述串口; When the data write request is a serial port parameter setting request, obtaining an address code of the corresponding serial port from the virtual serial port node, and setting the serial port according to the address code Setting a parameter to write the corresponding serial port;
当所述数据写入请求为串口数据写入请求吋, 从所述虚拟串口节点中 获取对应的所述串口的地址编码, 并根据所述地址编码将所述串口数 据写入对应的所述串口。  After the data write request is a serial port data write request, obtaining the address code of the corresponding serial port from the virtual serial port node, and writing the serial port data to the corresponding serial port according to the address code .
[权利要求 5] 如权利要求 1所述的通信控制方法, 其中, 所述依次读取每一所述从 机的每一所述串口的数据, 并将获取到的所述数据存储于对应的虚拟 串口节点的缓冲区的步骤包括:  [Claim 5] The communication control method according to claim 1, wherein the data of each of the serial ports of each of the slaves is sequentially read, and the acquired data is stored in a corresponding The steps of the buffer of the virtual serial port node include:
向一所述从机发送串口数据读取请求;  Sending a serial port data read request to a slave;
当所述从机在预设的响应吋间内响应所述串口数据读取请求吋, 将所 述从机的每一所述串口的数据存储于对应的虚拟串口节点的缓冲区; 当所述从机在预设的响应吋间内未响应所述串口数据读取请求吋, 向 下一所述从机发送串口数据读取请求。  And when the slave responds to the serial port data read request in a preset response time, storing data of each serial port of the slave in a buffer of a corresponding virtual serial port node; After the slave does not respond to the serial port data read request within the preset response time, the slave sends a serial port data read request to the slave.
[权利要求 6] —种通信控制装置, 用于实现主机与每一从机的每一串口的通信, 所 述通信控制装置包括创建模块、 数据写入模块与数据读取模块; 所述创建模块, 用于创建与每一所述从机的每一所述串口一一对应的 虚拟串口节点; [Claim 6] a communication control device, configured to implement communication between a host and each serial port of each slave, the communication control device comprising a creation module, a data writing module, and a data reading module; , configured to create a virtual serial port node corresponding to each of the serial ports of each of the slaves;
所述数据写入模块, 用于在接收到所述主机向所述虚拟串口节点发送 的数据写入请求吋, 从所述虚拟串口节点中获取对应的所述串口的地 址编码, 并根据所述地址编码将所述数据写入对应的所述串口; 所述数据读取模块, 用于依次读取每一所述从机的每一所述串口的数 据, 并将获取到的所述数据存储于对应的虚拟串口节点的缓冲区, 以 使得所述主机能从每一虚拟串口节点的缓冲区读取到对应的所述串口 的数据。  The data writing module is configured to: after receiving a data write request sent by the host to the virtual serial port node, obtain an address code of the serial port from the virtual serial port node, and according to the The address code writes the data to the corresponding serial port; the data reading module is configured to sequentially read data of each serial port of each of the slaves, and store the acquired data. And a buffer of the corresponding virtual serial port node, so that the host can read data of the corresponding serial port from a buffer of each virtual serial port node.
[权利要求 7] 如权利要求 6所述的通信控制装置, 其中, 所述创建模块包括获取单 元、 创建单元与映射单元;  [Claim 7] The communication control device according to claim 6, wherein the creation module includes an acquisition unit, a creation unit, and a mapping unit;
所述获取单元, 用于获取所述从机的地址编码与所述从机的每一所述 串口的地址编码;  The obtaining unit is configured to obtain an address code of the slave and an address code of each serial port of the slave;
所述创建单元, 用于对应每一所述串口创建一虚拟串口节点; 所述映射单元, 用于对所述虚拟串口节点与对应的所述串口做寻址映 射。 The creating unit is configured to create a virtual serial port node corresponding to each of the serial ports; The mapping unit is configured to perform addressing mapping on the virtual serial port node and the corresponding serial port.
[权利要求 8] 如权利要求 7所述的通信控制装置, 其中, 所述映射单元, 具体用于 将所述虚拟串口节点的句柄、 对应的所述从机的地址编码、 对应的所 述串口的地址编码, 以及所述虚拟串口节点的编码进行映射。  [Claim 8] The communication control device according to claim 7, wherein the mapping unit is configured to: encode a handle of the virtual serial port node, encode an address of the corresponding slave, and correspond to the serial port The address code, and the encoding of the virtual serial port node are mapped.
[权利要求 9] 如权利要求 6所述的通信控制装置, 其中, 所述数据写入模块包括判 断单元、 串口参数设置单元与串口数据写入单元; 所述判断单元, 用于在接收到所述主机向所述虚拟串口节点发送的数 据写入请求吋, 判断所述数据写入请求的类型; 所述数据写入请求包 括串口参数设置请求与串口数据写入请求;  [Claim 9] The communication control device according to claim 6, wherein the data writing module includes a determining unit, a serial port parameter setting unit, and a serial port data writing unit; and the determining unit is configured to receive the Determining, by the host, a data write request sent to the virtual serial port node, determining a type of the data write request; the data write request includes a serial port parameter setting request and a serial port data write request;
所述串口参数设置单元, 用于在所述数据写入请求为串口参数设置请 求吋, 从所述虚拟串口节点中获取对应的所述串口的地址编码, 并根 据所述地址编码将所述串口设置参数写入对应的所述串口; 所述串口数据写入单元, 用于在所述数据写入请求为串口数据写入请 求吋, 从所述虚拟串口节点中获取对应的所述串口的地址编码, 并根 据所述地址编码将所述串口数据写入对应的所述串口。  The serial port parameter setting unit is configured to: after the data write request is a serial port parameter setting request, obtain an address code of the serial port from the virtual serial port node, and code the serial port according to the address code Setting a parameter to write the corresponding serial port; the serial port data writing unit is configured to obtain, according to the serial port data write request, the corresponding serial port address from the virtual serial port node Encoding, and writing the serial port data to the corresponding serial port according to the address code.
[权利要求 10] 如权利要求 6所述的通信控制装置, 其中, 所述数据读取模块包括发 送单元与控制单元; [Claim 10] The communication control device according to claim 6, wherein the data reading module includes a transmitting unit and a control unit;
所述发送单元, 用于向所述从机发送串口数据读取请求;  The sending unit is configured to send a serial port data read request to the slave device;
所述控制单元, 用于在所述从机在预设的响应吋间内响应所述串口数 据读取请求吋, 将所述从机的每一所述串口的数据存储于对应的虚拟 串口节点的缓冲区;  The control unit is configured to: when the slave responds to the serial port data read request in a preset response time, store data of each serial port of the slave in a corresponding virtual serial port node Buffer
所述控制单元, 还用于在所述从机在预设的响应吋间内未响应所述串 口数据读取请求吋, 控制所述发送单元向下一所述从机发送串口数据 读取请求。  The control unit is further configured to: when the slave does not respond to the serial port data read request in a preset response time, control the sending unit to send a serial port data read request to the slave device .
PCT/CN2017/076760 2017-03-15 2017-03-15 Communication control method and control apparatus WO2018165900A1 (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
PCT/CN2017/076760 WO2018165900A1 (en) 2017-03-15 2017-03-15 Communication control method and control apparatus
CN201780002445.5A CN108235802A (en) 2017-03-15 2017-03-15 Communication control method and control device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2017/076760 WO2018165900A1 (en) 2017-03-15 2017-03-15 Communication control method and control apparatus

Publications (1)

Publication Number Publication Date
WO2018165900A1 true WO2018165900A1 (en) 2018-09-20

Family

ID=62643253

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2017/076760 WO2018165900A1 (en) 2017-03-15 2017-03-15 Communication control method and control apparatus

Country Status (2)

Country Link
CN (1) CN108235802A (en)
WO (1) WO2018165900A1 (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111443928B (en) * 2020-03-24 2023-04-14 四川众合智控科技有限公司 Beacon flashing method and system based on serial port communication
CN112527720A (en) * 2020-12-05 2021-03-19 青岛鼎信通讯股份有限公司 Data communication method applied to rack-mounted plant station terminal
CN115695073B (en) * 2022-10-13 2025-06-03 Tcl空调器(中山)有限公司 Communication method, device, equipment and storage medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101945031A (en) * 2010-10-21 2011-01-12 广州数控设备有限公司 Method for implementing mutual communication of slave stations of high-speed field bus
US20140089918A1 (en) * 2012-09-27 2014-03-27 Oracle International Corporation Method and system for logging into a virtual environment executing on a host
CN106126452A (en) * 2016-06-17 2016-11-16 北京大学 The method that (SuSE) Linux OS based on IIC agreement communicates with bare machine

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN2715431Y (en) * 2004-01-15 2005-08-03 北京北纬通信科技股份有限公司 Split type data acquisition and transmission device
CN101621440B (en) * 2009-05-22 2011-08-10 浙江天正电气股份有限公司 Remote multi-path serial port communication mapping system
CN101894041A (en) * 2010-07-15 2010-11-24 中兴通讯股份有限公司 Multi-virtual serial port system and its communication method
CN105512063A (en) * 2014-09-24 2016-04-20 中兴通讯股份有限公司 Method and system for data transmission

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101945031A (en) * 2010-10-21 2011-01-12 广州数控设备有限公司 Method for implementing mutual communication of slave stations of high-speed field bus
US20140089918A1 (en) * 2012-09-27 2014-03-27 Oracle International Corporation Method and system for logging into a virtual environment executing on a host
CN106126452A (en) * 2016-06-17 2016-11-16 北京大学 The method that (SuSE) Linux OS based on IIC agreement communicates with bare machine

Also Published As

Publication number Publication date
CN108235802A (en) 2018-06-29

Similar Documents

Publication Publication Date Title
US6973506B2 (en) Position identifier management apparatus and method, mobile computer, and position identifier processing method
CN103888358B (en) Routing method, device, system and gateway equipment
JP4940304B2 (en) Database management in wireless communication systems
WO2019144742A1 (en) Binding method for user terminal and device, apparatus, and system
WO2018165900A1 (en) Communication control method and control apparatus
CN105657000A (en) Message transmission method and device
CN107968848B (en) A method, terminal device and storage medium for obtaining IP address
CN109857553A (en) EMS memory management process and device
CN103703474B (en) The data of processing unit generation
WO2021223247A1 (en) Device upgrading method, smart device, and computer readable storage medium
CN107623555A (en) Implementation method and device of a general-purpose communication simulation platform
CN110109848B (en) DSP hardware abstraction layer and DSP processor
CN104426816A (en) Virtual machine communication method and device
CN112818265B (en) Interaction method and mobile terminal
CN101572871B (en) Multimedia message issuing method, device and system
CN113986995A (en) Request distribution method, device, storage medium and electronic device
CN114185804A (en) Interface testing method and device and terminal equipment
CN113965360A (en) Intelligent device cloud server access method, device, medium, device and system
CN113347115B (en) Message processing method and device, electronic equipment and medium
CN113497764B (en) Service routing method, system, computer storage medium and electronic device
CN114007200A (en) A method, device, device and storage medium for sending scheduling command information
KR20180061885A (en) Apparatus and system for providing modbus communication shortening polling time and method thereof
CN112528333A (en) User privacy protection method, MEC server, terminal, device and medium
CN109391914B (en) A method and device for session addressing
US9794197B2 (en) Method and apparatus for transmitting can frame

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 17900856

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 17900856

Country of ref document: EP

Kind code of ref document: A1