CN111104361B - Serial port number query method and device, computer equipment and storage medium - Google Patents

Serial port number query method and device, computer equipment and storage medium Download PDF

Info

Publication number
CN111104361B
CN111104361B CN201911220827.2A CN201911220827A CN111104361B CN 111104361 B CN111104361 B CN 111104361B CN 201911220827 A CN201911220827 A CN 201911220827A CN 111104361 B CN111104361 B CN 111104361B
Authority
CN
China
Prior art keywords
serial port
port
port number
query
serial
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201911220827.2A
Other languages
Chinese (zh)
Other versions
CN111104361A (en
Inventor
袁伟勋
廖进英
申芬芬
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hitachi Building Technology Guangzhou Co Ltd
Original Assignee
Hitachi Building Technology Guangzhou Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Hitachi Building Technology Guangzhou Co Ltd filed Critical Hitachi Building Technology Guangzhou Co Ltd
Priority to CN201911220827.2A priority Critical patent/CN111104361B/en
Publication of CN111104361A publication Critical patent/CN111104361A/en
Application granted granted Critical
Publication of CN111104361B publication Critical patent/CN111104361B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR 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
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/903Querying

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computational Linguistics (AREA)
  • Data Mining & Analysis (AREA)
  • Information Transfer Systems (AREA)

Abstract

The invention relates to a method and a device for inquiring a port number of a serial port, computer equipment and a storage medium. The method comprises the following steps: when receiving an inquiry trigger instruction, sending communication data through a predetermined sending serial port; determining a first serial port corresponding to the first port number; the first port number is a port number selected from a query array; if the first serial port does not receive the communication data, selecting a second port number from the query array; and when the second serial port corresponding to the second port number receives the communication data, determining the second port number of the second serial port as the inquired port number. By adopting the method, the port number query efficiency of the serial port can be improved.

Description

Serial port number query method and device, computer equipment and storage medium
Technical Field
The invention relates to the field of industrial control application, in particular to a method and a device for querying a port number of a serial port, computer equipment and a storage medium.
Background
In the field of industrial control, when an upper computer and a lower computer perform communication interaction to realize the control of the upper computer on the lower computer, a serial port of the upper computer needs to be connected with the corresponding lower computer (a COM port). The premise of the communication interaction between the upper computer and the lower computer is that the port number of the serial port selected/configured by the upper computer software of the upper computer is consistent with the port number of the serial port of the actual physical connection between the upper computer and the lower computer, for example, the port number selected/configured by the upper computer software is COM1, so that when the actual physical connection is performed between the upper computer and the lower computer, the serial port of which the port number is COM1 should be connected with the lower computer.
However, when the upper computer has a plurality of serial ports with non-different appearances, the operator cannot directly obtain the port number of the serial port where the upper computer is actually physically connected with the lower computer, and the operator needs to try to query the port number one by one, so that the query efficiency of the port number of the serial port is reduced.
Disclosure of Invention
Therefore, it is necessary to provide a serial port number query method, an apparatus, a computer device, and a storage medium, which can improve the efficiency of querying the port number of a serial port, in order to solve the above technical problems.
In a first aspect, a method for querying a port number of a serial port is provided, including:
when receiving an inquiry trigger instruction, sending communication data through a predetermined sending serial port;
determining a first serial port corresponding to the first port number; the first port number is a port number selected from a query array;
if the first serial port does not receive the communication data, selecting a second port number from the query array;
and when the second serial port corresponding to the second port number receives the communication data, determining the second port number of the second serial port as the inquired port number.
In a second aspect, an apparatus for querying a port number of a serial port is provided, including:
the communication data sending module is used for sending communication data through a predetermined sending serial port when receiving the inquiry triggering instruction;
the first serial port determining module is used for determining a first serial port corresponding to the first port number; the first port number is a port number selected from a query array;
a second port number determination module, configured to select a second port number from the query array if the first port does not receive the communication data;
and the query port number determining module is used for determining the second port number of the second serial port as the queried port number when the second serial port corresponding to the second port number receives the communication data.
In a third aspect, a computer device is provided, comprising a memory and a processor, the memory storing a computer program, the processor implementing the following steps when executing the computer program:
when receiving an inquiry trigger instruction, sending communication data through a predetermined sending serial port;
determining a first serial port corresponding to the first port number; the first port number is a port number selected from a query array;
if the first serial port does not receive the communication data, selecting a second port number from the query array;
and when the second serial port corresponding to the second port number receives the communication data, determining the second port number of the second serial port as the inquired port number.
In a fourth aspect, there is provided a computer readable storage medium having stored thereon a computer program which, when executed by a processor, performs the steps of:
when receiving an inquiry trigger instruction, sending communication data through a predetermined sending serial port;
determining a first serial port corresponding to the first port number; the first port number is a port number selected from a query array;
if the first serial port does not receive the communication data, selecting a second port number from the query array;
and when the second serial port corresponding to the second port number receives the communication data, determining the second port number of the second serial port as the inquired port number.
According to the serial port number query method, the device, the computer equipment and the storage medium, when a query trigger instruction is received, communication data are sent through a predetermined sending serial port, a first port number is selected from a query array, after the first serial port corresponding to the first port number is determined to be the received communication data, a second port number is selected from the query array, and when the second serial port corresponding to the second port number receives the communication data, the second port number is determined to be the queried port number, so that the computer equipment can automatically select the port number through the query array, judge whether the serial port corresponding to the port number receives the communication data, realize automatic query of the port number of the serial port of the computer equipment, and improve query efficiency.
Drawings
FIG. 1 is a diagram illustrating an internal structure of a computer device according to an embodiment;
fig. 2 is a schematic flowchart of a port number query method of a serial port in an embodiment;
fig. 3 is a schematic flowchart of a port number query method for a serial port in another embodiment;
FIG. 4 is a schematic diagram illustrating pin connections of an RS232 serial port in one embodiment;
FIG. 5 is a schematic diagram illustrating pin connections of an RS422 serial port according to an embodiment;
fig. 6 is a schematic flowchart of a port number query method for a serial port in yet another embodiment;
FIG. 7 is a schematic diagram illustrating pin connections of an RS485 serial port in one embodiment;
FIG. 8 is a schematic diagram of a pin connection of a CAN serial port in one embodiment;
FIG. 9 is a diagram illustrating a trigger run interface displayed after running a port number program in one embodiment;
fig. 10 is an interface diagram of an operation result displayed after the upper computer runs the port number query program in one embodiment;
fig. 11 is a block diagram illustrating a configuration of a serial port number query device in an embodiment.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further 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 and are not intended to limit the invention.
Reference herein to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of the invention. The appearances of the phrase in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. It is explicitly and implicitly understood by one skilled in the art that the embodiments described herein can be combined with other embodiments.
The method for inquiring the port number of the serial port can be applied to computer equipment shown in figure 1. The internal structure of the computer device may be as shown in fig. 1. The computer device includes a processor, a memory, a network interface, a display screen, and an input device connected by a system bus. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device comprises a nonvolatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of an operating system and computer programs in the non-volatile storage medium. The network interface of the computer device is used for communicating with an external terminal through a network connection. The computer program is executed by a processor to implement a method for port number lookup of a serial port. The display screen of the computer equipment can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer equipment can be a touch layer covered on the display screen, a key, a track ball or a touch pad arranged on the shell of the computer equipment, an external keyboard, a touch pad or a mouse and the like.
Those skilled in the art will appreciate that the architecture shown in fig. 1 is merely a block diagram of some of the structures associated with the inventive arrangements and is not intended to limit the computing devices to which the inventive arrangements may be applied, as a particular computing device may include more or less components than those shown, or may combine certain components, or have a different arrangement of components.
In an embodiment, as shown in fig. 2, a serial port number query method is provided, which is described by taking an example that the method is applied to a computer device, and includes the following steps:
step S201, when receiving the query trigger instruction, sending the communication data through a predetermined sending serial port.
The query trigger command may be used to trigger the computer device to start a method for implementing port number query, and in an event-driven case, the computer device may receive the query trigger command, for example, in an event-driven case of clicking the query control CMD, the computer device receives the query trigger command; then the computer equipment can obtain a predetermined sending end port number, so as to determine a sending serial port corresponding to the sending end port number, and send communication data through the sending serial port; the communication data may be a simple data such as byte type or string type data.
Step S202, determining a first serial port corresponding to the first port number; the first port number is a port number selected from the query array.
In this step, the computer device selects a port number from the query array as a first port number, and determines a first serial port corresponding to the first port number.
In one embodiment, the computer device determining the first string corresponding to the first port number may be implemented by querying a pointer: according to the pre-established corresponding relation between the query pointer and the port number, after the computer equipment obtains the first query pointer, the first port number corresponding to the first query pointer is determined. Further, the pre-established correspondence between the query pointer and the port number may be implemented as follows: the computer equipment acquires two or more port numbers and assigns the port numbers to the query array, namely, the port numbers are respectively assigned to different elements in the query array, the different elements correspond to different query pointers, so that the different port numbers correspond to the different query pointers, and the one-to-one correspondence relationship between the port numbers and the query pointers in the query array is established. In the following, the query array is exemplified as a (i), where i can be understood as a query pointer. The 4 port numbers of the computer device are assigned to the query array a (i), that is, the 4 port numbers are assigned to the 4 elements a (1), a (2), a (3) and a (4), respectively, and different query pointers i correspond to different port numbers because different elements correspond to different query pointers i. When the first query pointer i acquired by the computer device is 1, at this time, the computer device may determine that the corresponding first port number is a (1) by using the first query pointer i is 1.
In step S203, if the first serial port does not receive the communication data, the second port number is selected from the query array.
The computer device determines whether the first serial port has received the communication data after transmitting the communication data through the transmitting serial port and determining the first serial port. The computer device may determine the following as a case where the first serial port does not receive the communication data: (1) the first serial port does not receive any data; (2) under the condition that the sending serial port and the first serial port are both serial ports of the computer equipment, the data received by the first serial port is different from the communication data; (3) when the sending serial port and the first serial port do not belong to the same computer equipment, the data received by the first serial port does not correspond to the communication data transmitted based on the communication protocol; the communication protocol is a communication protocol between the device to which the sending serial port belongs and the device to which the first serial port belongs. After reading that the first port does not receive the communication data, the computer device selects other port numbers except the first port number from the query array, and takes the selected other port numbers as second port numbers.
In another embodiment, the computer device may determine the second port number from the lookup array by querying for pointer jumps when the first port does not receive communication data. Specifically, the computer device obtains a preset pointer increment, and adds a first query pointer corresponding to the first port number and the pointer increment to obtain a second query pointer, that is, at this time, jumps from the first query pointer to the second query pointer; and the computer equipment determines a second port number corresponding to the second query pointer according to the pre-established corresponding relation between the query pointer and the port number.
Step S204, when the second serial port corresponding to the second port number receives the communication data, determining the second port number of the second serial port as the inquired port number.
After the computer equipment obtains the second port number, determining a second serial port corresponding to the second port number, and judging whether the second serial port receives communication data; if the second serial port receives the communication data, the computer device takes the second port number as the queried port number, and at this moment, the second serial port is a serial port connected with the sending serial port, that is, the second serial port is a serial port to be queried, and the port number of the second serial port is the port number of the serial port to be queried.
Further, the computer device may output query success information after querying the port number, such as "report: the port number of the serial port to be queried currently connected with the sending serial port is xxx'.
In another embodiment, if there is no second port number corresponding to the second query pointer in the query array, outputting port number query failure information; specifically, after the computer device jumps to the second query pointer in the query pointer jump manner, if the second query pointer i is greater than the number of elements of the query array, the query array does not have a port number corresponding to the second query pointer. Taking the elements of the query array as a (1), a (2), a (3) and a (4) for example, when the elements of the query array are a (1), a (2), a (3) and a (4), the number n of the elements of the query array is 4, if the first query pointer i is 4 and the preset query increment is 1, the second query pointer i is 5, that is, the second query pointer i is 5 is greater than the number n of the elements of the query array by 4, so that, in the query array, there is no port number corresponding to i is 5, and the computer device may output query failure information, such as "report: no port number of the current serial port is queried ".
According to the serial port number query method, when a query trigger instruction is received, communication data are sent through a predetermined sending serial port, a first port number is selected from a query array, a second port number is selected from the query array after the first serial port corresponding to the first port number is determined to be the received communication data, and when the second serial port corresponding to the second port number receives the communication data, the second port number is determined to be the queried port number, so that the computer equipment can automatically select the port number through querying the array, and judge whether the serial port corresponding to the port number receives the communication data, the automatic query of the computer equipment is realized, and the query efficiency is improved. Further, under event driving, receiving an inquiry triggering instruction can enable relevant personnel to drive an event in an actual scene, so that the computer equipment receives the inquiry triggering instruction and runs a program for inquiring the port number. In addition, the computer device assigns the port number to the query array, that is, by querying the array storage port number, it is ensured that the space required for storing the port number can be dynamically allocated under the condition that the port numbers of different devices are different, the method is suitable for the scene of querying the port numbers of different devices, and the flexibility of querying the port numbers is improved. And determining the port number by querying the pointer, and jumping to the next port number by pointer increment, and adding the pointer increment to the current port number to obtain the next port number.
In one embodiment, when a serial port of a computer device supports a full-duplex communication mode, the serial port may send data through a sending pin of the serial port and receive the data through a receiving pin of the serial port, at this time, the sending serial port may be determined by a selected port number, that is, the computer device determines a corresponding serial port according to the selected port number, and when the communication data is sent through the sending pin of the serial port, the serial port may be understood as a sending serial port; under the condition of receiving communication data through a receiving pin of the serial port, the serial port can be understood as a receiving serial port; when a sending pin and a receiving pin of a certain serial port are short-circuited, the communication data received by the serial port is the communication data sent by the serial port.
In this embodiment, if a port number of a serial port supporting a full-duplex communication mode is to be queried, a receiving pin and a sending pin of the serial port may be shorted, and then, a method for querying a port number of a computer device is described by taking a first port number and a second port number as a (1) and a (2), respectively. After receiving an inquiry trigger instruction, the computer equipment selects a first port number A (1) from the inquiry array, determines a first serial port corresponding to the first port number A (1), sends communication data from a sending pin of the first serial port, reads data received by a receiving pin of the first serial port, and if the data received by the receiving pin of the first serial port is the communication data, the sending pin and the receiving pin of the first serial port are in short circuit, namely the first serial port is a serial port to be inquired, and correspondingly, the port number to be inquired is the first port number A (1); if the data received by the receiving pin of the first serial port is not communication data, the computer device selects a second port number A (2) from the query array, determines a second serial port corresponding to the second port number A (2), sends the communication data from the sending pin of the second serial port, reads the data received by the receiving pin of the second serial port, and if the data received by the receiving pin of the second serial port is communication data, the sending pin of the second serial port is in short circuit with the receiving pin, namely, the second serial port is a serial port to be queried, and correspondingly, the port number of the serial port to be queried is the second port number A (2).
In this embodiment, when the serial port supports a full-duplex communication mode, the sending pin and the receiving pin of the serial port to be queried are directly shorted, and the computer device can execute the method of the embodiment, so as to automatically query the port number, and relevant personnel do not need to determine the port number to be queried through other devices such as a lower computer, thereby reducing the operation of the relevant personnel in determining the communication protocol between the other devices such as the lower computer and the computer device, and improving the query efficiency of the port number.
In an embodiment, if the port number of the serial port supporting the full-duplex communication mode needs to be queried, the related personnel can be reminded to short-circuit the receiving pin and the sending pin of the serial port in a mode of outputting the first connection information, for example, if the port number of the RS232 serial port needs to be queried, "short-circuit the pins 2 and 3 of the RS232 serial port" can be displayed on the display window control.
In this embodiment, the sending pin and the receiving pin of the serial port to be queried are prompted to be short-circuited by outputting the first connection information, so that related personnel can directly prepare for automatically querying the port number for the computer device according to the first connection information.
In one embodiment, under the condition that the serial port of the computer device supports a full-duplex communication mode, the port number of one serial port of the computer device can be determined through other ways, and the serial port corresponding to the port number is used as a sending serial port; other approaches may be to use third party software, such as computer device query software or a serial assistant, to perform a manual traversal query. After the computer equipment determines one port number through other ways, the serial port corresponding to the port number is used as a sending serial port, and further, second connection information is output to remind related personnel to connect one serial port of the computer equipment with the sending serial port.
In this embodiment, the serial port to be queried and the predetermined sending serial port are prompted to be connected by outputting the second connection information, so that related personnel can directly prepare for automatic port number query of the computer device according to the second connection information.
In order to better understand the above method, an application example of the serial port number query method of the present invention is described in detail below. In the field of industrial control, an upper computer such as a PC is required to control other lower computers. The port number query method of the serial port can be embedded into the upper computer industrial control software of the equipment such as the upper computer and the like to operate, and can also be used as independent software to operate on the equipment such as the upper computer and the like.
The method can be used in computer equipment of an upper computer such as a PC (personal computer), and can be used for inquiring a certain serial port on the PC, and the method is introduced by dividing the serial port supporting a full-duplex communication mode and the serial port supporting a half-duplex communication mode.
1. Serial ports supporting full duplex communication modes (RS232 and RS 422):
referring to fig. 3, the steps for querying a serial port supporting a full duplex communication mode are as follows:
step S301, after a sending end (namely a sending pin) and a receiving end (namely a receiving pin) of the serial port to be queried are short-circuited, the upper computer receives a query trigger instruction under the drive of an event that a query control CMD is clicked;
step S302, the upper computer reads port numbers of n serial ports on the PC, assigns the port numbers to a query array A (i), wherein the number of elements of the query array A (i) is n, and the upper computer obtains an initial query pointer i as 1;
step S303, assigning the value A (i) to COMX, and sending communication data through a sending pin of a serial port corresponding to COMX;
step S304, after proper time delay, the upper computer reads data received by a receiving pin of a serial port corresponding to COMX;
step S305, judging whether the received data is communication data; if yes, go to step S306; if not, go to step S307;
step S306, outputting: "report: the port number of a serial port to be inquired connected with the current sending pin and the current receiving pin is A (i)';
step S307, adding a preset pointer increment to the query pointer i, wherein the pointer increment can be 1, and obtaining a next query pointer i;
step S308, judging whether the next query pointer i is larger than the number n of elements of the query array A (i); if yes, go to step S309; if not, returning to the step S303;
step S309, output: "report: no port number of the current serial port is queried ".
Referring to fig. 4, when the serial port to be queried is an RS232 serial port, a processing method of the RS232 serial port on hardware is as follows: and short-circuiting a transmitting end TX and a receiving end RX of the serial port to be queried. Referring to fig. 5, when the serial port to be queried is an RS422 serial port, a processing method of the RS422 serial port on hardware is as follows: and short-circuiting the Y pin and the A pin of the serial port to be inquired, and short-circuiting the Z pin and the B pin.
After short-circuiting the corresponding pins of the serial port, relevant personnel click the query control CMD, the upper computer runs a port number query program, and the port number of the serial port to be queried is automatically and quickly identified.
2. Serial ports supporting half-duplex communication modes (RS485 and CAN):
referring to fig. 6, the steps for querying a serial port supporting a half-duplex communication mode are as follows:
step S601, after the serial port to be queried is connected with the communication cable of the sending serial port with the known port number in a one-to-one correspondence manner, the upper computer receives a query trigger instruction under the drive of an event that the query control CMD is clicked;
step S602, the upper computer reads the port numbers of n serial ports on the PC, assigns n-1 port numbers except the known port number of the sending serial port to a query array A (i), wherein the number of elements of the query array A (i) is n-1, and the upper computer obtains an initial query pointer i which is 1;
step S603, assigning the A (i) to COMX, assigning a known port number of the sending serial port to COMY, and enabling the upper computer to send communication data through the sending serial port;
step S604, after appropriate time delay, the upper computer reads data received by a serial port corresponding to the COMX;
step S605, judging whether the received data is communication data sent by a sending serial port; if yes, go to step S606; if not, go to step S607;
step S606, output "report: the port number of the serial port to be inquired which is currently connected with the sending serial port is A (i)';
step S607, adding a preset pointer increment to the query pointer i, wherein the pointer increment can be 1, and obtaining a next query pointer i;
step S608, judging whether the next query pointer i is larger than the number n-1 of the elements of the query array A (i); if yes, go to step S609; if not, returning to the step S603;
step S609, output "report: no port number of the current serial port is queried ".
Referring to fig. 7, when the serial port to be queried is an RS486 serial port, a processing method of the RS486 serial port on hardware is as follows: and respectively connecting the pin A and the pin B of the serial port to be inquired with the pin A and the pin B of the sending serial port with known port numbers in a one-to-one correspondence manner. Referring to fig. 8, when the serial port to be queried is a CAN serial port, the processing method of the CAN serial port on hardware is as follows: and respectively connecting the H pins and the L pins of the serial port to be inquired with the H pins and the L pins of the sending serial port with known port numbers in a one-to-one correspondence manner.
After the pins of the serial port to be queried and the pins of the sending serial port with known port numbers are connected in a one-to-one correspondence mode, the related personnel click the query control CMD, the upper computer runs a port number query program, and the port number of the serial port to be queried is automatically and quickly identified.
The port number query method in the embodiment is run after the industrial control software is embedded, so that the trigger running interface diagram shown in fig. 9 can be obtained, and when relevant personnel short-circuit the pins 2 and 3 of the RS232 and click the query button according to the information in the trigger running interface diagram shown in fig. 9, the upper computer runs the port number query program, and obtains the running result interface diagram shown in fig. 10.
The program corresponding to the port number query method of the embodiment can be embedded into related industrial control software or independently compiled and run, so that the flexibility of the method is improved, one-key automatic and quick query can be realized by clicking the query control CMD, the query operation is simplified, the query efficiency is improved, and for related personnel, the query operation of the port number can be realized without knowing too much communication knowledge such as related communication protocols. Furthermore, in an application scene that a plurality of serial ports of the PC are connected with a plurality of lower computers, related personnel can quickly figure out the port numbers of the serial ports of the PC by the method so as to correctly complete the connection between the PC and the lower computer equipment; especially in practical application scenes such as factories and the like, if different lower computer devices such as function test instruments and intelligent fixtures are required to be connected with a plurality of serial ports of the PC, the problem of frequent wire replacement is avoided by the method, the port number of the PC is convenient to be quickly cleared, and the serial communication cable of the detection platform is correctly connected. It should be noted that, for the sake of simplicity, the foregoing method embodiments are described as a series of acts or combinations, but those skilled in the art should understand that the present invention is not limited by the described order of acts, as some steps may be performed in other orders or simultaneously according to the present invention.
Based on the same idea as the port number query method of the serial port in the above embodiment, the present invention further provides a port number query device of the serial port, which can be used to execute the port number query method of the serial port. For convenience of explanation, in the schematic structural diagram of the serial port number query device embodiment, only the part related to the embodiment of the present invention is shown, and those skilled in the art will understand that the illustrated structure does not constitute a limitation to the device, and may include more or less components than those illustrated, or combine some components, or arrange different components.
In one embodiment, as shown in fig. 11, there is provided a serial port number query device 110, including: a communication data sending module 111, a first port number determining module 112, a second port number determining module 113, and a query port number determining module 114, wherein:
and a communication data sending module 111, configured to send communication data through a predetermined sending serial port when receiving the query trigger instruction.
A first serial port determining module 112, configured to determine a first serial port corresponding to the first port number; the first port number is a port number selected from the query array;
a second port number determining module 113, configured to select a second port number from the query array if the first serial port does not receive the communication data;
the query port number determining module 114 is configured to determine, when the second serial port corresponding to the second port number receives communication data, the second port number of the second serial port as the queried port number.
In one embodiment, the first serial port determining module 112 is further configured to obtain a first query pointer in a query array; a first port number corresponding to the first query pointer is determined.
In an embodiment, the second port number determining module 113 is further configured to add the first query pointer to a preset pointer increment to obtain a second query pointer when the first serial port does not receive the communication data; from the query array, a second port number corresponding to the second query pointer is determined.
In one embodiment, if the serial port of the local terminal supports a full-duplex communication mode, the sending serial port is determined by the selected port number; the second port number determining module 113 is further configured to determine a second serial port corresponding to the second port number; the second serial port is used as a sending serial port to send communication data; and reading the data received by the second serial port.
A communication data transmission module 111 in one embodiment, further configured to output first connection information; the first connection information is used for indicating that a sending pin and a receiving pin of one serial port of the local terminal are short-circuited.
In one embodiment, if the serial port of the home terminal supports a half-duplex communication mode, the sending serial port is the serial port of the home terminal; the port number query device 110 of the serial port is further configured to output second connection information; the second connection information is used for indicating that one serial port of the local terminal is connected with the sending serial port.
In an embodiment, the serial port number query device 110 is further configured to obtain at least two port numbers, assign the at least two port numbers to the query array, and establish a one-to-one correspondence between the at least two port numbers and the query pointer of the query array.
It should be noted that the port number query device of the serial port of the present invention corresponds to the port number query method of the serial port of the present invention one to one, and the technical features and the advantageous effects described in the embodiments of the port number query method of the serial port are all applicable to the embodiments of the port number query device of the serial port, and specific contents may refer to the description in the embodiments of the method of the present invention, and are not described herein again, and thus, this statement is made.
In addition, in the above exemplary embodiment of the serial port number query device, the logical division of each program module is only an example, and in practical applications, the above function distribution may be completed by different program modules according to needs, for example, due to the configuration requirements of corresponding hardware or the convenience of implementation of software, that is, the internal structure of the serial port number query device is divided into different program modules to complete all or part of the above described functions.
In one embodiment, a computer device is provided, comprising a memory and a processor, the memory storing a computer program, the processor implementing the steps of the above-described method embodiments when executing the computer program.
In an embodiment, a computer-readable storage medium is provided, on which a computer program is stored, which computer program, when being executed by a processor, carries out the steps of the respective method embodiment as described above.
It will be understood by those skilled in the art that all or part of the processes of the methods of the above embodiments may be implemented by a computer program, which is stored in a computer readable storage medium and sold or used as a stand-alone product. More specific examples (a non-exhaustive list) of the computer-readable medium would include the following: an electrical connection component (electronic device) having one or more wires, a portable computer diskette (magnetic device), a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber device, and a portable compact disc read-only memory (CDROM). Additionally, the computer-readable medium could even be paper or another suitable medium upon which the program is printed, as the program can be electronically captured, via for instance optical scanning of the paper or other medium, then compiled, interpreted or otherwise processed in a suitable manner if necessary, and then stored in a computer memory.
It should be understood that portions of the present invention may be implemented in hardware, software, firmware, or a combination thereof. In the above embodiments, the various steps or methods may be implemented in software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, any one or combination of the following techniques, which are known in the art, may be used: a discrete logic circuit having a logic gate circuit for implementing a logic function on a data signal, an application specific integrated circuit having an appropriate combinational logic gate circuit, a Programmable Gate Array (PGA), a Field Programmable Gate Array (FPGA), or the like.
The terms "comprises" and "comprising," and any variations thereof, of embodiments of the present invention are intended to cover non-exclusive inclusions. For example, a process, method, system, article, or apparatus that comprises a list of steps or (module) elements is not limited to only those steps or elements but may alternatively include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
The technical features of the above embodiments can be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the above embodiments are not described, but should be considered as the scope of the present specification as long as there is no contradiction between the combinations of the technical features.
The above examples are only illustrative of several embodiments of the present invention, but should not be construed as limiting the scope of the invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the inventive concept, which falls within the scope of the present invention. Therefore, the protection scope of the present patent shall be subject to the appended claims.

Claims (10)

1. A serial port number query method is characterized in that if a serial port to be queried supports full duplex communication, a sending pin and a receiving pin of the serial port to be queried are connected; if the serial port to be inquired supports half-duplex communication, connecting the serial port to be inquired with a serial port with a known port number, wherein the serial port with the known port number and the serial port to be inquired belong to the same equipment; the method comprises the following steps:
when receiving an inquiry trigger instruction, sending communication data through a predetermined sending serial port;
determining a first serial port corresponding to the first port number; the first port number is a port number selected from a query array;
if the first serial port does not receive the communication data, selecting a second port number from the query array;
when a second serial port corresponding to the second port number receives the communication data, determining the second port number of the second serial port as the port number of the serial port to be inquired;
if the serial port to be inquired supports full-duplex communication, the sending serial port is determined by the selected port number; and if the serial port to be inquired supports half-duplex communication, the sending serial port is the serial port with the known port number.
2. The method of claim 1, further comprising, prior to the step of determining the first serial port corresponding to the first port number:
acquiring a first query pointer in the query array;
determining a first port number corresponding to the first query pointer.
3. The method of claim 2, wherein said step of selecting a second port number from said lookup array if said communication data is not received by said first port comprises:
when the first serial port does not receive the communication data, adding the first query pointer and a preset pointer to obtain a second query pointer;
determining a second port number corresponding to the second query pointer from the query array.
4. The method of claim 1,
after the step of selecting a second port number from the lookup array if the first port does not receive the communication data, further comprising:
determining a second serial port corresponding to the second port number;
the second serial port is used as the sending serial port to send the communication data;
and reading the data received by the second serial port.
5. The method of claim 4, wherein before the step of sending the communication data through a predetermined sending serial port when receiving the query triggering command, the method further comprises:
outputting the first connection information; the first connection information is used for indicating that a sending pin and a receiving pin of one serial port of the local terminal are in short circuit.
6. The method of claim 1,
the method further comprises the following steps:
outputting the second connection information; and the second connection information is used for indicating that one serial port of the local terminal is connected with the sending serial port.
7. The method of any one of claims 1 to 6, further comprising:
and acquiring at least two port numbers, assigning the at least two port numbers to the query array, and establishing a one-to-one correspondence relationship between the at least two port numbers and a query pointer of the query array.
8. A serial port number inquiry device is characterized in that if a serial port to be inquired supports full duplex communication, a sending pin and a receiving pin of the serial port to be inquired are connected; if the serial port to be inquired supports half-duplex communication, connecting the serial port to be inquired with a serial port with a known port number, wherein the serial port with the known port number and the serial port to be inquired belong to the same equipment; the device comprises:
the communication data sending module is used for sending communication data through a predetermined sending serial port when receiving the inquiry triggering instruction;
the first serial port determining module is used for determining a first serial port corresponding to the first port number; the first port number is a port number selected from a query array;
a second port number determination module, configured to select a second port number from the query array if the first port does not receive the communication data;
the query port number determining module is used for determining a second port number of a second serial port as the port number of the serial port to be queried when the second serial port corresponding to the second port number receives the communication data;
if the serial port to be inquired supports full-duplex communication, the sending serial port is determined by the selected port number; and if the serial port to be inquired supports half-duplex communication, the sending serial port is the serial port with the known port number.
9. A computer device comprising a memory and a processor, the memory storing a computer program, wherein the processor implements the steps of the method of any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of the method of any one of claims 1 to 7.
CN201911220827.2A 2019-12-03 2019-12-03 Serial port number query method and device, computer equipment and storage medium Active CN111104361B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911220827.2A CN111104361B (en) 2019-12-03 2019-12-03 Serial port number query method and device, computer equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911220827.2A CN111104361B (en) 2019-12-03 2019-12-03 Serial port number query method and device, computer equipment and storage medium

Publications (2)

Publication Number Publication Date
CN111104361A CN111104361A (en) 2020-05-05
CN111104361B true CN111104361B (en) 2021-07-06

Family

ID=70420932

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911220827.2A Active CN111104361B (en) 2019-12-03 2019-12-03 Serial port number query method and device, computer equipment and storage medium

Country Status (1)

Country Link
CN (1) CN111104361B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113761300A (en) * 2021-08-23 2021-12-07 杭州安恒信息技术股份有限公司 Message sampling method, device, equipment and medium based on bitmap calculation
CN116483751A (en) * 2023-04-06 2023-07-25 河南翔宇医疗设备股份有限公司 Method, device and medium for identifying serial numbers

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102722150A (en) * 2012-06-07 2012-10-10 中国东方电气集团有限公司 Multi-way waveform acquiring and displaying and data analyzing and processing system based on universal serial
CN109597779A (en) * 2018-11-21 2019-04-09 Oppo(重庆)智能科技有限公司 A kind of serial-port inquiring method and equipment and computer storage medium
CN209296825U (en) * 2018-09-26 2019-08-23 合肥博微田村电气有限公司 A kind of transformer performance automatic detection device

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101853224B (en) * 2010-04-21 2014-12-10 中兴通讯股份有限公司 Method and device for identifying port of data card device under Linux system
CN102629240B (en) * 2012-02-13 2015-04-22 上海创远仪器技术股份有限公司 Method and device for serial communication
CN109150641B (en) * 2017-06-15 2020-04-17 北京国双科技有限公司 Data acquisition and query method, device, storage medium and processor

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102722150A (en) * 2012-06-07 2012-10-10 中国东方电气集团有限公司 Multi-way waveform acquiring and displaying and data analyzing and processing system based on universal serial
CN209296825U (en) * 2018-09-26 2019-08-23 合肥博微田村电气有限公司 A kind of transformer performance automatic detection device
CN109597779A (en) * 2018-11-21 2019-04-09 Oppo(重庆)智能科技有限公司 A kind of serial-port inquiring method and equipment and computer storage medium

Also Published As

Publication number Publication date
CN111104361A (en) 2020-05-05

Similar Documents

Publication Publication Date Title
CN111104361B (en) Serial port number query method and device, computer equipment and storage medium
KR20080109043A (en) Usb connection
WO1985000260A1 (en) Multiplexer
CN107703375A (en) Mobile terminal antenna test system and method
CN112269086A (en) Charging cable identification method and device, charging cable and readable storage medium
CN108924908A (en) WiFi scan method, device and electronic device
CN117544259B (en) Medical telemetry monitoring communication method, system, electronic equipment and storage medium
CN111123728A (en) Unmanned vehicle simulation method, device, equipment and computer readable medium
CN105068967B (en) Control method, device and the terminal of I2C equipment
CN110750475A (en) Method and device for sharing one physical serial port by multiple CPUs, embedded equipment and medium
CN108055212B (en) Method and device compatible with PSE chip
CN103376369B (en) Communication load testing method and device
CN215375738U (en) Wire harness detection device and wire harness detection system
CN211149270U (en) Debugging circuit
CN208271170U (en) A kind of debugging serial ports connection equipment
KR20070109673A (en) Mobile terminal having function of plug and play and method thereof
CN207232759U (en) A kind of automatization test system
CN103795583A (en) Testing device
CN111064908B (en) Signal transmission method, device, equipment and readable storage medium
CN104866401B (en) Signal acquiring method and device in piece
KR102085731B1 (en) Interconnection Evaluation System for Switchboard
CN210954981U (en) Keyboard device with KVM
CN109936586A (en) Communication processing method and device
CN214954958U (en) Electronic device sharing universal sequence bus signal
CN109246203B (en) Data communication method, device, computer equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant