A method and system for controlling multiple devices through a set of serial connections
By optimizing the serial port connection method and data processing, the main control device can efficiently control multiple devices, solving the problems of limited device quantity and increased connection load, and reducing the risk of device damage.
Patent Information
- Application Number
- CN202411231705.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-04
- Publication Date
- 2026-01-13
- Estimated Expiration
- 2044-09-04
AI Technical Summary
When the main control device controls multiple devices via serial port connection, the number of devices is limited by the number of serial ports. More connection cables will increase the load and may cause damage.
This method controls multiple devices via serial port connection, employing half-duplex or single-channel connection modes to optimize channel occupancy and data transmission. It utilizes a communication resource optimization model for data processing, enabling relay transmission of data within the controlled device cluster.
Reduce the connection load on the main control equipment, avoid equipment damage, and improve equipment control efficiency.
Smart Images

Figure CN119135466B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of serial port connection, and in particular to a method and system for controlling multiple devices through a group of serial ports. BACKGROUND
[0002] When a master device is connected through communication transmission, one master device needs to use a serial port to control multiple devices, wherein the master device needs to have multiple serial ports, and each controlled device needs a serial port connection of the master device. The connection lines connected to the master device end are relatively many, which makes the complexity of the master device high. Meanwhile, the number of devices that can be controlled by the master device is limited by the number of serial ports of the master device end. After the connection lines connected to the master device end are relatively many, the connection load of the master device is increased, which further causes damage to the master device. Therefore, a method for controlling multiple devices through a group of serial ports is needed to solve the above problems. SUMMARY
[0003] The present application aims to provide a method and system for controlling multiple devices through a group of serial ports to solve the technical problems proposed in the background.
[0004] To achieve the above-mentioned purpose, the present application provides the following technical solutions:
[0005] A method for controlling multiple devices through a group of serial ports, comprising:
[0006] A control device acquires starting serial port transmission information and sends the starting serial port transmission information to a first controlled device, wherein the control device and the first controlled device are connected in series through a serial port, and the starting serial port transmission information includes serial port baud rate, serial port data bits and serial port stop bits.
[0007] The first controlled device determines whether to start a half-duplex connection mode according to the starting serial port transmission information.
[0008] If the half-duplex connection mode is started, the first controlled device acquires multiple channel occupation data and multiple first transmission data connected to the control device through the serial port, and optimizes the multiple channel occupation data and the multiple first transmission data to obtain multiple optimized data.
[0009] The first controlled device sends the multiple optimized data to a controlled device cluster connected in series therewith, wherein the controlled device cluster includes multiple second controlled devices connected in series, and any one second controlled device in the controlled device cluster is connected in series with the first controlled device as a first target controlled device and receives the multiple optimized data.
[0010] The target controlled device transmits multiple optimized data to each second controlled device in the controlled device cluster in a relay manner according to the connection order of the controlled device cluster, until the last second controlled device receives the optimized data and the connection transmission ends. Each second controlled device, after receiving the optimized data, obtains the corresponding first start instruction based on the optimized data, and establishes a controlled connection for each second controlled device according to multiple first start instructions.
[0011] Preferably, after the step of the first controlled device determining whether to enable half-duplex connection mode based on the initial serial port transmission information, the method further includes:
[0012] If half-duplex connection mode is not enabled, the first controlled device determines whether to enable single-channel connection mode based on the initial serial port transmission information.
[0013] If single-channel connection mode is enabled, the first controlled device obtains the target configuration address;
[0014] The first controlled device obtains the address information of multiple third controlled devices in the second controlled device cluster connected in series with it, and traverses all third controlled devices according to the target configuration address so that the target configuration address can be successfully matched with the address information of any third controlled device in the second controlled device cluster.
[0015] Any third controlled device corresponding to a successful match establishes a communication connection with the first controlled device through the target configuration address;
[0016] The control device sends a control command to any third controlled device that has been successfully matched through the first controlled device, in order to establish a controlled connection.
[0017] Preferably, the step of the first controlled device determining whether to enable half-duplex connection mode based on the initial serial port transmission information includes:
[0018] The first controlled device obtains the corresponding number of data bits based on the serial port data bits;
[0019] The first controlled device obtains the constant serial communication output based on the serial port data bits and serial port baud rate;
[0020] The first controlled device obtains the interval time of the serial port stop bit based on the serial port stop bit;
[0021] The first controlled device obtains the total communication transmission volume based on the constant serial port communication output and interval time, and determines whether the total communication transmission volume is less than the preset communication transmission volume.
[0022] If the total communication transmission volume is less than the preset communication transmission volume, the first controlled device will activate the half-duplex connection mode.
[0023] Preferably, the step of optimizing the multiple channel occupancy data and the multiple first transmission data to obtain multiple optimized data includes:
[0024] The first controlled device obtains the corresponding maximum load transmission rate and transmission delay rate based on multiple first transmission data;
[0025] The first controlled device obtains multiple transmission bit counts corresponding to multiple first transmission data;
[0026] The first controlled device obtains multiple occupied bit counts based on multiple first channel occupancy data;
[0027] The first controlled device sequentially inputs multiple transmission bit counts, multiple occupied bit counts, maximum load transmission rate, and transmission delay rate into the communication resource optimization model for training, thereby obtaining multiple first optimized bit counts. The function formula of the communication resource optimization model is:
[0028]
[0029] Where b(i…n) represents the number of first optimized bits from the i-th to the n-th, STD i FZ represents the i-th first transmitted data. MAXi s represents the i-th maximum load transfer rate. i ZY represents the i-th transmission delay rate. i STD represents the data occupied by the i-th first channel. n FZ represents the nth first transmitted data. MAXn s represents the nth maximum load transfer rate. n ZY represents the nth transmission delay rate. n This represents the nth data segment occupied by the first channel, where i represents the number of first transmitted data segments and the number of data segments occupied by the first channel, i = 1, 2, 3...n;
[0030] The first controlled device uses the first optimized bit count from the i-th to the n-th bit count as multiple optimized data.
[0031] Preferably, the step of the first controlled device acquiring multiple channel occupancy data and multiple first transmission data connected to the serial port of the control device further includes:
[0032] The first controlled device obtains multiple corresponding transmission times based on multiple first transmission data, and divides each transmission time into several time slots according to a preset fixed length;
[0033] The first controlled device sorts several time slots to obtain a time slot sorting table;
[0034] The first controlled device classifies the time slot sorting table according to the odd and even numbers in the sorting, resulting in multiple odd time slots and multiple even time slots;
[0035] The first controlled device acquires the first transmission channel corresponding to the half-duplex connection mode, and divides the first transmission channel into multiple odd time slots and multiple even time slots to obtain multiple odd channels and multiple even channels;
[0036] The first controlled device obtains the total number of channels based on the plurality of odd-numbered channels and the plurality of even-numbered channels;
[0037] The first controlled device obtains the total channel occupancy data based on the first transmission channel;
[0038] The first controlled device divides the total channel occupancy data according to the total number of channels to obtain multiple first channel occupancy data.
[0039] Preferably, the step of traversing all third-controlled devices according to the target configuration address further includes:
[0040] The first controlled device obtains the number of data bits occupied by the second channel in the single-channel connection mode;
[0041] The first controlled device obtains the number of bits of the configuration address number information;
[0042] The first controlled device acquires the preset transmission time of the configuration address number information in single-channel connection mode;
[0043] The first controlled device calculates the rated transmission rate based on the second channel occupancy data, the number of bits in the configured address number, and the preset transmission time. The calculation formula is as follows:
[0044]
[0045] P represents the rated transmission rate, D(e) represents the number of data bits occupied by the second channel, z(y) represents the number of bits for the configuration address number, and T represents the preset transmission time.
[0046] The first controlled device uses a preset transmission protocol to traverse all third controlled devices based on the configured address number information and the rated transmission rate.
[0047] This application also provides a system for controlling multiple devices via a set of serial ports, including:
[0048] The first acquisition module is used to control the device to acquire the initial serial port transmission information and send the initial serial port transmission information to the first controlled device. The control device and the first controlled device are connected in series via a serial port. The initial serial port transmission information includes the serial port baud rate, serial port data bits and serial port stop bits.
[0049] The first judgment module is used by the first controlled device to determine whether to enable half-duplex connection mode based on the initial serial port transmission information.
[0050] If half-duplex connection mode is enabled, the first controlled device acquires multiple channel occupancy data and multiple first transmission data connected to the serial port of the control device, and optimizes the multiple channel occupancy data and multiple first transmission data to obtain multiple optimized data;
[0051] A first sending module is used for a first controlled device to send multiple optimized data to a cluster of controlled devices connected in series with it, wherein the cluster of controlled devices includes multiple second controlled devices connected in sequence, and any one of the second controlled devices in the cluster serves as a first target controlled device connected in series with the first controlled device and receives the multiple optimized data;
[0052] The first transmission module is used to transmit multiple optimized data to each second controlled device in the controlled device cluster in a relay manner according to the connection order of the controlled device cluster, until the last second controlled device receives the optimized data and the connection transmission ends. Each second controlled device, after receiving the optimized data, obtains a corresponding first start instruction based on the optimized data and establishes a controlled connection for each second controlled device according to multiple first start instructions.
[0053] Preferably, the first determining module further includes:
[0054] The first judgment unit is used to determine whether to enable the single-channel connection mode based on the initial serial port transmission information if the half-duplex connection mode is not enabled.
[0055] The first acquisition unit is used to acquire the target configuration address of the first controlled device if the single-channel connection mode is enabled.
[0056] The second acquisition unit is used for the first controlled device to acquire the address information of multiple third controlled devices in the second controlled device cluster connected in series with it, and to traverse all third controlled devices according to the target configuration address so that the target configuration address can be successfully matched with the address information of any third controlled device in the second controlled device cluster.
[0057] The second communication connection unit is used for any third controlled device corresponding to a successful match to establish a communication connection with the first controlled device through the target configuration address;
[0058] The first controlled connection unit is used to control the device to send control commands to any third controlled device that has been successfully matched, in order to establish a controlled connection.
[0059] The present invention also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the pre-employment testing method described above.
[0060] The present invention also provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the pre-employment testing method described above.
[0061] The beneficial effects of this application are as follows: In a half-duplex connection mode, the first controlled device sends multiple optimized data to a cluster of controlled devices connected in series with it. The cluster of controlled devices includes multiple second controlled devices connected in sequence. Any second controlled device in the cluster acts as a target controlled device, connected in series with the first controlled device, and receives multiple optimized data. In this way, the control device can transmit multiple first transmission data to any second controlled device in the cluster through the first controlled device. Each second controlled device obtains a corresponding first start command based on the optimized data and establishes a controlled connection for each second controlled device based on multiple first start commands. Each second controlled device is controlled by the first transmission data transmitted by the previous second controlled device. Thus, the control of the main control device is distributed to each second controlled device, thereby effectively reducing the connection load of the main control device and reducing the risk of damage to the main control device. Attached Figure Description
[0062] Fig. 1 This is a schematic diagram of a method flow according to an embodiment of this application.
[0063] Fig. 2 This is a schematic diagram of the system structure according to an embodiment of this application.
[0064] Fig. 3 This is a schematic diagram of the internal structure of a computer device according to an embodiment of this application.
[0065] The realization of the objective, functional features and advantages of the present invention will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0066] It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
[0067] like Figs. 1-3 As shown, this application provides a method for controlling multiple devices through a set of serial ports, including:
[0068] S1. The control device acquires the initial serial port transmission information and sends the initial serial port transmission information to the first controlled device. The control device and the first controlled device are connected in series via a serial port. The initial serial port transmission information includes the serial port baud rate, serial port data bits, and serial port stop bits.
[0069] S2. The first controlled device determines whether to enable half-duplex connection mode based on the initial serial port transmission information.
[0070] If half-duplex connection mode is enabled, the first controlled device acquires multiple channel occupancy data and multiple first transmission data connected to the serial port of the control device, and optimizes the multiple channel occupancy data and multiple first transmission data to obtain multiple optimized data;
[0071] S3. The first controlled device sends multiple optimized data to a cluster of controlled devices connected in series with it. The cluster of controlled devices includes multiple second controlled devices connected in sequence. Any one of the second controlled devices in the cluster of controlled devices is connected in series with the first controlled device as a first target controlled device and receives multiple optimized data.
[0072] S4. The target controlled device transmits multiple optimized data to each second controlled device in the controlled device cluster in a relay manner according to the connection order of the controlled device cluster, until the last second controlled device receives the optimized data and the connection transmission ends. Each second controlled device, after receiving the optimized data, obtains the corresponding first start instruction based on the optimized data and establishes a controlled connection for each second controlled device according to multiple first start instructions.
[0073] As described in steps S1-S4 above, when the master control device is connected via communication transmission, one master control device needs to use a serial port to control multiple devices. The master control device requires multiple serial ports, and each controlled device needs a serial port connection from the master control device. This results in a large number of connection cables connected to the master control device, increasing its complexity. Furthermore, the number of devices the master control device can control is limited by the number of serial ports on the master control device. A large number of connection cables on the master control device increases its connection load, potentially leading to damage. Therefore, it is necessary to transmit information via the initial serial port. The serial port baud rate, data bits, and stop bits are extracted, and the connection mode between the first controlled device and the controlled device cluster is determined based on these parameters. This connection mode selection provides the master control device with the optimal controlled connection, enabling efficient operation. When half-duplex connection mode is enabled, the first controlled device acquires multiple channel occupancy data and multiple first transmission data from the serial port connection with the control device, and optimizes these data to obtain optimized data. This pre-processes the channel occupancy data... Row elimination provides a real data transmission volume for the transmission of multiple optimized data. After the optimized data is sent to a cluster of controlled devices connected in series, where the controlled device cluster includes multiple second controlled devices connected sequentially, any one of the second controlled devices in the cluster acts as a first target controlled device, connected in series with the first controlled device and receiving the multiple optimized data. Then, the target controlled device transmits the multiple optimized data to each second controlled device in the cluster in a relay manner according to the connection order of the controlled device cluster, until the last second controlled device receives the optimized data and the connection transmission ends. Each second controlled device, upon receiving the optimized data, obtains a corresponding first start command based on the optimized data and establishes a controlled connection based on multiple first start commands. In this relay transmission control, each second controlled device is controlled by the first transmission data transmitted by the previous second controlled device, thus distributing the connection control of the main control device to each second controlled device, effectively reducing the connection load of the main control device and minimizing the risk of damage to the main control device.
[0074] In one embodiment, after step S2, where the first controlled device determines whether to enable half-duplex connection based on the initial serial port transmission information, the method further includes:
[0075] S21. If the half-duplex connection mode is not enabled, the first controlled device determines whether to enable the single-channel connection mode based on the initial serial port transmission information.
[0076] S22. If single-channel connection mode is enabled, the first controlled device obtains the target configuration address;
[0077] S23. The first controlled device obtains the address information of multiple third controlled devices in the second controlled device cluster connected in series with it, and traverses all third controlled devices according to the target configuration address so that the target configuration address matches the address information of any third controlled device in the second controlled device cluster.
[0078] S24. Any third controlled device corresponding to a successful match establishes a communication connection with the first controlled device through the target configuration address;
[0079] S25. The control device sends a control command to any third controlled device that has been successfully matched through the first controlled device to establish a controlled connection.
[0080] As described in steps S21-S25 above, when the connection method is a single-channel connection, the first controlled device obtains the target configuration address and the address information of multiple third controlled devices in the second controlled device cluster connected in series with it. It then iterates through all the third controlled devices according to the target configuration address to ensure that the target configuration address matches the address information of any third controlled device in the second controlled device cluster. A communication connection is established between the first controlled device and the third controlled device corresponding to the successful match via the target configuration address. The control device then sends a control command to the third controlled device corresponding to the successful match via the first controlled device to establish a controlled connection. This allows for directional control of the first target controlled device in a single-channel connection. Furthermore, in a single-channel connection, the first controlled device and the multiple third controlled devices serve as transmission media, and only one third controlled device is controlled at a time. This reduces the connection load on the main control device, while still enabling directional control of multiple devices and preventing damage to the main control device due to increased connection load.
[0081] In one embodiment, step S2, in which the first controlled device determines whether to enable half-duplex connection mode based on the initial serial port transmission information, includes:
[0082] S201, The first controlled device obtains the corresponding number of data bits according to the serial port data bits;
[0083] The first controlled device obtains the constant serial communication output based on the serial port data bits and serial port baud rate;
[0084] S202, the first controlled device obtains the interval time of the serial port stop bit according to the serial port stop bit;
[0085] S203. The first controlled device obtains the total communication transmission volume based on the constant serial port communication output and interval time, and determines whether the total communication transmission volume is less than the preset communication transmission volume.
[0086] If the total communication transmission volume is less than the preset communication transmission volume, the first controlled device will activate the half-duplex connection mode.
[0087] As described in steps S201-S203 above, when distinguishing between half-duplex and single-channel connection modes, the corresponding number of data bits is first obtained based on the serial port data bits. Single-channel data bits are typically 8 bits or less, while bits greater than 8 bits, as long as they are even multiples, are usually for half-duplex connection modes. Classifying the transmitted data allows for efficient transmission in different modes. Then, the rated first transmitted data, under the conditions of serial port data bits and serial port baud rate, can obtain a constant serial port communication output. This constant serial port communication output allows for initial data classification. Next, the interval time of the serial port stop bits is obtained based on the serial port stop bits, and then... The total communication transmission volume is obtained by using the constant serial port communication output and the interval time. The total communication transmission volume is calculated by multiplying the constant serial port communication output and the interval time. Since the transmission volume of the single-channel connection is faster than that of the half-duplex connection, if the total communication transmission volume transmitted within the preset time is greater than the preset communication transmission volume, it is a single-channel connection. Based on this, it is determined whether the total communication transmission volume is less than the preset communication transmission volume. If the total communication transmission volume is less than the preset communication transmission volume, the first controlled device starts the half-duplex connection mode; otherwise, the single-channel connection mode is started. Determining the connection mode helps to classify the instruction data during connection and can reduce resource allocation anomalies in the serial port during transmission.
[0088] In one embodiment, step S2, whereby the first controlled device acquires multiple channel occupancy data and multiple first transmission data connected to the serial port of the control device, further includes:
[0089] S204. The first controlled device obtains multiple corresponding transmission times based on multiple first transmission data, and divides each transmission time into several time slots according to a preset fixed length;
[0090] S205. The first controlled device sorts several time slots to obtain a time slot sorting table;
[0091] S206. The first controlled device classifies the time slot sorting table according to the odd and even numbers in the sorting, and obtains multiple odd time slots and multiple even time slots.
[0092] S207. The first controlled device acquires the first transmission channel corresponding to the half-duplex connection mode, and divides the first transmission channel into multiple odd time slots and multiple even time slots to obtain multiple odd channels and multiple even channels.
[0093] S208. The first controlled device obtains the total number of channels based on the plurality of odd-numbered channels and the plurality of even-numbered channels;
[0094] S209. The first controlled device obtains the total channel occupancy data according to the first transmission channel;
[0095] S2010, the first controlled device divides the total channel occupancy data according to the total number of channels to obtain multiple first channel occupancy data.
[0096] As described in steps S204-S2010 above, the first controlled device of the present invention obtains multiple transmission times corresponding to multiple first transmission data, and divides each transmission time into several time slots according to a preset fixed length. Then, the first controlled device sorts the several time slots to obtain a time slot sorting table. Here, time slots are mainly used in time-division multiplexing mode. Next, the first controlled device classifies the time slot sorting table according to the odd and even numbers in the sorting, obtaining multiple odd time slots and multiple even time slots. In this way, the channel under the half-duplex connection mode is split in advance, and the data is initially classified. After the initial classification, the confusion caused by multiple data connections can be reduced, and the split data can be sorted according to odd numbers. Even channels are transmitted alternately. Then, the first controlled device obtains the total number of channels based on the multiple odd channels and the multiple even channels. Each channel has a fixed amount of data, including the channel's transmission protocol and the data occupied by the channel medium. Based on this, the first controlled device can obtain the total channel occupancy data based on the first transmission channels. The first controlled device then divides the total channel occupancy data according to the total number of channels to obtain multiple first channel occupancy data. After obtaining the multiple first channel occupancy data, discarding them ensures that the calculation of the amount of data transmitted is correct, making the data calculation between the control device and the controlled device more accurate.
[0097] In one embodiment, step S2, which optimizes multiple channel occupancy data and multiple first transmission data to obtain multiple optimized data, includes:
[0098] S4011, The first controlled device obtains the corresponding maximum load transmission rate and transmission delay rate based on multiple first transmission data;
[0099] S4012, The first controlled device obtains a plurality of corresponding transmission bit counts based on a plurality of the first transmission data;
[0100] S4013, The first controlled device obtains multiple occupied bit counts based on multiple first channel occupied data;
[0101] S4014. The first controlled device sequentially inputs the multiple transmitted bit counts, the multiple occupied bit counts, the maximum load transmission rate, and the transmission delay rate into the communication resource optimization model for training, thereby obtaining multiple first optimized bit counts. The function formula of the communication resource optimization model is:
[0102]
[0103] Where b(i…n) represents the number of first optimized bits from the i-th to the n-th, STD i FZ represents the i-th first transmitted data. MAXi s represents the i-th maximum load transfer rate. i ZY represents the i-th transmission delay rate. i STD represents the data occupied by the i-th first channel. n FZ represents the nth first transmitted data. MAXn s represents the nth maximum load transfer rate. n ZY represents the nth transmission delay rate. n This represents the nth data segment occupied by the first channel, where i represents the number of first transmitted data segments and the number of data segments occupied by the first channel, i = 1, 2, 3...n;
[0104] S4015, The first controlled device uses the first optimized bit count from the i-th to the n-th bit count as multiple optimized data.
[0105] As described in steps S4011-S4015 above, the first controlled device of the present invention obtains the corresponding maximum load transmission rate and transmission delay rate based on multiple first transmission data, and then inputs the multiple first transmission data, multiple first channel occupancy data, maximum load transmission rate and transmission delay rate into the communication resource optimization model for training to obtain multiple first optimized data. In this way, after optimizing the data, the multiple first optimized data can remain stable during transmission connection, and the stable transmission connection can avoid the connection transmission between the control device and the controlled device from being disordered.
[0106] In one embodiment, step S23, which involves traversing all third controlled devices according to the target configuration address, further includes:
[0107] S231, The first controlled device obtains the number of data bits occupied by the second channel in the single-channel connection mode;
[0108] S232, The first controlled device obtains the number of bits of the configuration address number information;
[0109] S233. The first controlled device obtains the preset transmission time of the configuration address number information in the single-channel connection mode;
[0110] S234. The first controlled device calculates the rated transmission rate based on the second channel occupancy data, the number of bits in the configuration address number, and the preset transmission time. The calculation formula is as follows:
[0111]
[0112] P represents the rated transmission rate, D(e) represents the number of data bits occupied by the second channel, z(y) represents the number of bits for the configuration address number, and T represents the preset transmission time.
[0113] S235. The first controlled device uses a preset transmission protocol to traverse all third controlled devices according to the rated transmission rate and the configured address number information.
[0114] As described in steps S231-S235 above, the first controlled device in this application obtains the number of data bits occupied by the second channel in the single-channel connection mode. Then, the first controlled device obtains the number of configuration address number bits of the configuration address number information. Next, the first controlled device obtains the preset transmission time of the configuration address number information in the single-channel connection mode. Then, the first controlled device calculates the rated transmission rate based on the second channel occupied data, the number of configuration address number bits, and the preset transmission time. This allows the first controlled device to traverse all third controlled devices based on the preset transmission protocol and the rated transmission rate, thereby avoiding resource allocation abnormalities when the serial port provides connection and transmission between the control device and the controlled device.
[0115] This application also provides a system for controlling multiple devices via a set of serial ports, including:
[0116] The first acquisition module 1 is used to control the device to acquire the starting serial port transmission information and send the starting serial port transmission information to the first controlled device. The control device and the first controlled device are connected in series via a serial port. The starting serial port transmission information includes the serial port baud rate, serial port data bits and serial port stop bits.
[0117] The first judgment module 2 is used by the first controlled device to determine whether to enable half-duplex connection mode based on the initial serial port transmission information.
[0118] If half-duplex connection mode is enabled, the first controlled device acquires multiple channel occupancy data and multiple first transmission data connected to the serial port of the control device, and optimizes the multiple channel occupancy data and multiple first transmission data to obtain multiple optimized data;
[0119] The first sending module 3 is used for the first controlled device to send multiple optimized data to a cluster of controlled devices connected in series with it, wherein the cluster of controlled devices includes multiple second controlled devices connected in sequence, and any one of the second controlled devices in the cluster of controlled devices is connected in series with the first controlled device as a first target controlled device and receives multiple optimized data;
[0120] The first transmission module 4 is used to transmit multiple optimized data to each second controlled device in the controlled device cluster in a relay manner according to the connection order of the controlled device cluster, until the last second controlled device receives the optimized data and the connection transmission ends. Each second controlled device, after receiving the optimized data, obtains a corresponding first start instruction based on the optimized data and establishes a controlled connection for each second controlled device according to multiple first start instructions.
[0121] In one embodiment, the first determining module further includes:
[0122] The first judgment unit is used to determine whether to enable the single-channel connection mode based on the initial serial port transmission information if the half-duplex connection mode is not enabled.
[0123] The first acquisition unit is used to acquire the target configuration address of the first controlled device if the single-channel connection mode is enabled.
[0124] The second acquisition unit is used for the first controlled device to acquire the address information of multiple third controlled devices in the second controlled device cluster connected in series with it, and to traverse all third controlled devices according to the target configuration address so that the target configuration address can be successfully matched with the address information of any third controlled device in the second controlled device cluster.
[0125] The second communication connection unit is used for any third controlled device corresponding to a successful match to establish a communication connection with the first controlled device through the target configuration address;
[0126] The first controlled connection unit is used to control the device to send control commands to any third controlled device that has been successfully matched, in order to establish a controlled connection.
[0127] like Fig. 3 As shown, the present invention also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the above-described pre-employment testing method.
[0128] The present invention also provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the pre-employment testing method described above.
[0129] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media provided in this application and in the embodiments may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual-speed SDRAM (SSRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0130] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, apparatus, article, or method that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, apparatus, article, or method. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, apparatus, article, or method that includes that element.
[0131] The above description is merely a preferred embodiment of the present invention and does not limit the patent scope of the present invention. Any equivalent structural or procedural transformations made based on the content of the present invention's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of the present invention.
Claims
1. A method for controlling multiple devices via a set of serial ports, characterized in that, include: The control device acquires the initial serial port transmission information and sends the initial serial port transmission information to the first controlled device. The control device and the first controlled device are connected in series via a serial port. The initial serial port transmission information includes the serial port baud rate, serial port data bits, and serial port stop bits. The first controlled device determines whether to enable half-duplex connection mode based on the initial serial port transmission information. If half-duplex connection mode is enabled, the first controlled device acquires multiple channel occupancy data and multiple first transmission data connected to the serial port of the control device, and optimizes the multiple channel occupancy data and multiple first transmission data to obtain multiple optimized data; The first controlled device sends multiple optimized data to a cluster of controlled devices connected in series with it. The cluster of controlled devices includes multiple second controlled devices connected in sequence. Any one of the second controlled devices in the cluster serves as a first target controlled device, is connected in series with the first controlled device, and receives multiple optimized data. The target controlled device transmits multiple optimized data to each second controlled device in the controlled device cluster in a relay manner according to the connection order of the controlled device cluster, until the last second controlled device receives the optimized data and the connection transmission ends. Each second controlled device, after receiving the optimized data, obtains the corresponding first start instruction based on the optimized data, and establishes a controlled connection for each second controlled device according to multiple first start instructions.
2. The method for controlling multiple devices via a set of serial ports according to claim 1, characterized in that, After the first controlled device determines whether to enable half-duplex connection mode based on the initial serial port transmission information, the method further includes: If half-duplex connection mode is not enabled, the first controlled device determines whether to enable single-channel connection mode based on the initial serial port transmission information. If single-channel connection mode is enabled, the first controlled device obtains the target configuration address; The first controlled device obtains the address information of multiple third controlled devices in the second controlled device cluster connected in series with it, and traverses all third controlled devices according to the target configuration address so that the target configuration address can be successfully matched with the address information of any third controlled device in the second controlled device cluster. Any third controlled device corresponding to a successful match establishes a communication connection with the first controlled device through the target configuration address; The control device sends a control command to any third controlled device that has been successfully matched through the first controlled device, in order to establish a controlled connection.
3. The method for controlling multiple devices via a set of serial ports according to claim 1, characterized in that, The step of the first controlled device determining whether to enable half-duplex connection mode based on the initial serial port transmission information includes: The first controlled device obtains the corresponding number of data bits based on the serial port data bits; The first controlled device obtains the constant serial communication output based on the serial port data bits and serial port baud rate; The first controlled device obtains the interval time of the serial port stop bit based on the serial port stop bit; The first controlled device obtains the total communication transmission volume based on the constant serial port communication output and interval time, and determines whether the total communication transmission volume is less than the preset communication transmission volume. If the total communication transmission volume is less than the preset communication transmission volume, the first controlled device will activate the half-duplex connection mode.
4. The method for controlling multiple devices via a set of serial ports according to claim 1, characterized in that, The step of the first controlled device acquiring multiple channel occupancy data and multiple first transmission data connected to the serial port of the control device further includes: The first controlled device obtains multiple corresponding transmission times based on multiple first transmission data, and divides each transmission time into several time slots according to a preset fixed length; The first controlled device sorts several time slots to obtain a time slot sorting table; The first controlled device classifies the time slot sorting table according to the odd and even numbers in the sorting, resulting in multiple odd time slots and multiple even time slots; The first controlled device acquires the first transmission channel corresponding to the half-duplex connection mode, and divides the first transmission channel into multiple odd time slots and multiple even time slots to obtain multiple odd channels and multiple even channels; The first controlled device obtains the total number of channels based on the plurality of odd-numbered channels and the plurality of even-numbered channels; The first controlled device obtains the total channel occupancy data based on the first transmission channel; The first controlled device divides the total channel occupancy data according to the total number of channels to obtain multiple first channel occupancy data.
5. The method for controlling multiple devices via a set of serial ports according to claim 4, characterized in that, The step of optimizing multiple channel occupancy data and multiple first transmission data to obtain multiple optimized data includes: The first controlled device obtains the corresponding maximum load transmission rate and transmission delay rate based on multiple first transmission data; The first controlled device obtains multiple transmission bit counts corresponding to multiple first transmission data; The first controlled device obtains multiple occupied bit counts based on multiple first channel occupancy data; The first controlled device sequentially inputs multiple transmission bit counts, multiple occupied bit counts, maximum load transmission rate, and transmission delay rate into the communication resource optimization model for training, thereby obtaining multiple first optimized bit counts. The function formula of the communication resource optimization model is: ;....; ; Where b(i…n) represents the number of first optimized bits from the i-th to the n-th, STD i FZ represents the i-th first transmitted data. MAXi s represents the i-th maximum load transfer rate. i ZY represents the i-th transmission delay rate. i STD represents the data occupied by the i-th first channel. n FZ represents the nth first transmitted data. MAXn s represents the nth maximum load transfer rate. n ZY represents the nth transmission delay rate. n This represents the nth data segment occupied by the first channel, where i represents the number of first transmitted data segments and the number of data segments occupied by the first channel, i = 1, 2, 3...n; The first controlled device uses the first optimized bit count from the i-th to the n-th bit count as multiple optimized data.
6. The method for controlling multiple devices via a set of serial ports according to claim 2, characterized in that, The step of traversing all third-controlled devices according to the target configuration address further includes: The first controlled device obtains the number of data bits occupied by the second channel in the single-channel connection mode; The first controlled device obtains the number of bits of the configuration address number information; The first controlled device acquires the preset transmission time of the configuration address number information in single-channel connection mode; The first controlled device calculates the rated transmission rate based on the second channel occupancy data, the number of bits in the configured address number, and the preset transmission time. The calculation formula is as follows: ; P represents the rated transmission rate, D(e) represents the number of data bits occupied by the second channel, z(y) represents the number of bits for the configuration address number, and T represents the preset transmission time. The first controlled device uses a preset transmission protocol to traverse all third controlled devices based on the configured address number information and the rated transmission rate.
7. A system for controlling multiple devices via a set of serial ports, characterized in that, include: The first acquisition module is used to control the device to acquire the initial serial port transmission information and send the initial serial port transmission information to the first controlled device. The control device and the first controlled device are connected in series via a serial port. The initial serial port transmission information includes the serial port baud rate, serial port data bits and serial port stop bits. The first judgment module is used by the first controlled device to determine whether to enable half-duplex connection mode based on the initial serial port transmission information. If half-duplex connection mode is enabled, the first controlled device acquires multiple channel occupancy data and multiple first transmission data connected to the serial port of the control device, and optimizes the multiple channel occupancy data and multiple first transmission data to obtain multiple optimized data; A first sending module is used for a first controlled device to send multiple optimized data to a cluster of controlled devices connected in series with it, wherein the cluster of controlled devices includes multiple second controlled devices connected in sequence, and any one of the second controlled devices in the cluster serves as a first target controlled device connected in series with the first controlled device and receives the multiple optimized data; The first transmission module is used to transmit multiple optimized data to each second controlled device in the controlled device cluster in a relay manner according to the connection order of the controlled device cluster, until the last second controlled device receives the optimized data and the connection transmission ends. Each second controlled device, after receiving the optimized data, obtains a corresponding first start instruction based on the optimized data and establishes a controlled connection for each second controlled device according to multiple first start instructions.
8. A system for controlling multiple devices via a set of serial ports according to claim 7, characterized in that, The first determination module further includes: The first judgment unit is used to determine whether to enable the single-channel connection mode based on the initial serial port transmission information if the half-duplex connection mode is not enabled. The first acquisition unit is used to acquire the target configuration address of the first controlled device if the single-channel connection mode is enabled. The second acquisition unit is used for the first controlled device to acquire the address information of multiple third controlled devices in the second controlled device cluster connected in series with it, and to traverse all third controlled devices according to the target configuration address so that the target configuration address can be successfully matched with the address information of any third controlled device in the second controlled device cluster. The second communication connection unit is used for any third controlled device corresponding to a successful match to establish a communication connection with the first controlled device through the target configuration address; The first controlled connection unit is used to control the device to send control commands to any third controlled device that has been successfully matched, in order to establish a controlled connection.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the method according to any one of claims 1 to 6.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method of any one of claims 1 to 6.
Citation Information
Patent Citations
Serial port communication system and method
CN105243039A
Serial port one-to-many communication method and system and electrical equipment
CN117331877A