Serial port communication method and device and storage medium
By running the soft bus of the serial port in the bus scheduler, data transmission and scheduling between the upper computer and the node device is realized, the problem of communication complexity of multiple devices under the PC simulation serial port is solved, and data transmission is transparent and simplified.
Patent Information
- Application Number
- CN202311683925.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-07
- Publication Date
- 2025-06-10
AI Technical Summary
Under the PC simulation serial port, the communication of multiple devices is complicated, which affects the simulation process, especially when data transmission and reception state conversion is required.
By running the soft bus of the serial port in the bus scheduler, data transmission and scheduling between the host computer and each node device is realized without paying attention to the allocation of serial port control rights.
The data transfer process is simplified, making it transparent and simplified, and solving the communication complexity problem of multiple devices under the serial port.
Smart Images

Figure CN120123281A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of communication technology, and in particular to a serial communication method, device, and storage medium. Background Art
[0002] RS485 is a half-duplex bus. In practice, it generally uses host polling or token passing to allocate bus control rights, so it is necessary to switch between sending and receiving directions. A common practice is that each RS485 is in the receiving state at ordinary times, switching to the sending state only when it has data to send, and switching back to the receiving state after the data is sent.
[0003] However, when using a personal computer (PC) to emulate multiple devices connected to a serial port, the simulation software must implement multiple devices connected to a single serial port. When each device communicates with the host computer, and when the host computer issues protocols to the serial port, communication with the RS485 hardware becomes a challenge. If this common approach is still used, data transmission becomes complex, hindering the simulation process. Summary of the Invention
[0004] The present application provides a serial port communication method, apparatus and storage medium for solving the communication problem between a host computer and each device and the serial port when a PC emulates multiple devices under the serial port.
[0005] In a first aspect, the present application provides a serial port communication method, which is applied to a bus scheduler, wherein the bus scheduler runs a soft bus with a serial port, and the serial port is used for communication between a host computer and each node device; the method comprises:
[0006] receiving first data sent by a data sending device, where the data sending device is the host computer or any node device;
[0007] Obtaining a node address of the data sending device to determine a data receiving device according to the node address of the data sending device, wherein the data receiving device is the host computer or the host computer and each node device;
[0008] The data receiving function address of the data receiving device is called to send the first data to the data receiving device according to the data receiving function address of the data receiving device.
[0009] In one possible design, before receiving the first data sent by the data sending device, the method further includes:
[0010] Receive the respective node addresses and respective data receiving function addresses sent by the host computer and each node device, and send the corresponding data sending function addresses to the host computer and each node device to complete the registration of the host computer and each node device on the soft bus.
[0011] In a possible design, before receiving the respective node addresses and respective data receiving function addresses sent by the host computer and each node device, the method further includes:
[0012] A soft bus class is generated for the serial port according to the parameter configuration information of the serial port. The soft bus class includes multiple enumeration types of the host computer and each node device during the communication process. The enumeration type is used to declare a preset transmission direction identifier, a preset node address, a host computer linked list, and a device linked list.
[0013] In one possible design, receiving first data sent by a data sending device includes:
[0014] The data sending device obtains authorization of the soft bus by executing a private function;
[0015] The first data is received from the data sending device through a data sending function, where the data sending function is obtained by the data sending device calling its own data sending function address.
[0016] In one possible design, determining the data receiving device according to the node address of the data sending device includes:
[0017] Determining whether the data sending device is the host computer or any of the node devices according to the node address of the data sending device and the preset node address;
[0018] If it is determined that the data sending device is the host computer, determining that the data receiving device is each of the node devices according to the preset transmission direction identifier;
[0019] If it is determined that the data sending device is any of the node devices, the data receiving device is determined to be the host computer or the host computer and each of the node devices according to the preset transmission direction identifier.
[0020] In one possible design, if it is determined that the data receiving device is each node device, sending the first data to the data receiving device according to the data receiving function address of the data receiving device includes:
[0021] Calling the data receiving function of each node device according to the data receiving function address of each node device;
[0022] The first data is sent to each node device according to a data receiving function of each node device.
[0023] In one possible design, if it is determined that the data receiving device is the host computer, sending the first data to the data receiving device according to the data receiving function address of the data receiving device includes:
[0024] Call the data receiving function of the host computer according to the data receiving function address of the host computer;
[0025] The first data is sent to the host computer according to the data receiving function of the host computer.
[0026] In a possible design, after the host computer and / or each node device receives the first data, the method further includes:
[0027] receiving second data sent by the host computer and / or each node device through its own data sending function, where the second data is return data of the first data;
[0028] The second data is transmitted back to the data sending device.
[0029] In one possible design, the serial port includes an RS485 serial port or an RS232 serial port.
[0030] In a second aspect, the present application provides a serial communication device, which is applied to a bus scheduler, wherein the bus scheduler runs a soft bus with a serial port, and the serial port is used for communication between a host computer and each node device; the device includes:
[0031] A receiving module, configured to receive first data sent by a data sending device, wherein the data sending device is the host computer or any node device;
[0032] a processing module, configured to obtain a node address of the data sending device, and determine a data receiving device according to the node address of the data sending device, wherein the data receiving device is the host computer or the host computer and each node device;
[0033] The calling and sending module is used to call the data receiving function address of the data receiving device to send the first data to the data receiving device according to the data receiving function address of the data receiving device.
[0034] In one possible design, the serial port communication device further includes a registration module; the registration module is configured to:
[0035] Receive the respective node addresses and respective data receiving function addresses sent by the host computer and each node device, and send the corresponding data sending function addresses to the host computer and each node device to complete the registration of the host computer and each node device on the soft bus.
[0036] In one possible design, the serial port communication device further includes: a bus class generation module; the bus class generation module is configured to:
[0037] A soft bus class is generated for the serial port according to the parameter configuration information of the serial port. The soft bus class includes multiple enumeration types of the host computer and each node device during the communication process. The enumeration type is used to declare a preset transmission direction identifier, a preset node address, a host computer linked list, and a device linked list.
[0038] In one possible design, the receiving module is specifically configured to:
[0039] The data sending device obtains authorization of the soft bus by executing a private function;
[0040] The first data is received from the data sending device through a data sending function, where the data sending function is obtained by the data sending device calling its own data sending function address.
[0041] In one possible design, the processing module is specifically configured to:
[0042] Determining whether the data sending device is the host computer or any of the node devices according to the node address of the data sending device and the preset node address;
[0043] If it is determined that the data sending device is the host computer, determining that the data receiving device is each of the node devices according to the preset transmission direction identifier;
[0044] If it is determined that the data sending device is any of the node devices, the data receiving device is determined to be the host computer or the host computer and each of the node devices according to the preset transmission direction identifier.
[0045] In one possible design, if it is determined that the data receiving device is each of the node devices, the calling and sending module is specifically configured to:
[0046] Calling the data receiving function of each node device according to the data receiving function address of each node device;
[0047] The first data is sent to each node device according to a data receiving function of each node device.
[0048] In one possible design, if it is determined that the data receiving device is the host computer, the calling and sending module is specifically used to:
[0049] Call the data receiving function of the host computer according to the data receiving function address of the host computer;
[0050] The first data is sent to the host computer according to the data receiving function of the host computer.
[0051] In one possible design, the serial communication device further includes a return module; the return module is configured to:
[0052] receiving second data sent by the host computer and / or each node device through its own data sending function, where the second data is return data of the first data;
[0053] The second data is transmitted back to the data sending device.
[0054] In a third aspect, the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are executed by a processor, they are used to implement any possible serial port communication method provided in the first aspect.
[0055] The present application provides a serial communication method, device and storage medium, the serial communication method is applied to a bus scheduler, the bus scheduler runs a soft bus with a serial port, and the serial port is used for communication between a host computer and each node device. First, the first data sent by a data sending device is received, wherein the data sending device can be a host computer or any node device, then the node address of the data sending device is obtained, and then the data receiving device is determined according to the node address of the data sending device, wherein the data receiving device can be a host computer or a host computer and each node device, and finally the data receiving function address of the data receiving device is called, and the first data is sent to the data receiving device according to the data receiving function address of the data receiving device, so as to realize data transmission between the data sending device and the data receiving device on the serial port. There is no need to pay attention to the allocation of serial port control rights, and the data transmission between the host computer and each node device is realized by the soft bus of the serial port based on the bus scheduler, so that data transmission is transparent and simplified, and the serial communication problem when multiple devices are under the serial port is solved. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, a brief introduction will be given below to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0057] Figure 1 A schematic diagram of a system architecture provided in an embodiment of the present application;
[0058] Figure 2 A flowchart of a serial communication method provided in an embodiment of the present application;
[0059] Figure 3 A flowchart of another serial communication method provided in an embodiment of the present application;
[0060] Figure 4 A schematic diagram of the structure of a serial communication device provided in an embodiment of the present application;
[0061] Figure 5 A schematic structural diagram of another serial communication device provided in an embodiment of the present application;
[0062] Figure 6 A schematic structural diagram of another serial communication device provided in an embodiment of the present application;
[0063] Figure 7 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0064] Exemplary embodiments will be described in detail herein, with examples illustrated in the accompanying drawings. In the following description, when referring to the drawings, identical numerals in different figures represent identical or similar elements, unless otherwise indicated. The embodiments described in the following exemplary embodiments are not intended to represent all embodiments consistent with the present application. Rather, they are merely examples of methods and apparatus consistent with certain aspects of the present application, as detailed in the appended claims.
[0065] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequential order. It should be understood that the numbers used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can, for example, be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0066] RS485 is a half-duplex bus. In practice, it typically uses host polling or token passing to allocate bus control, requiring switching between send and receive directions. When using a personal computer (PC) to emulate multiple devices connected to a serial port, the emulation software must implement multiple devices connected to a single serial port. When each device communicates with the host computer, and when the host computer issues protocols to the serial port, communication with the RS485 hardware becomes a challenge. If this common practice is still used, data transmission becomes complex, hindering the simulation process.
[0067] In response to the above-mentioned problems existing in the prior art, the present application provides a serial communication method, device and storage medium. The inventive concept of the serial communication method provided by the present application is: for the serial port encapsulation, the soft bus corresponding to the serial port runs on the bus scheduler, and the soft bus is responsible for the data transmission and scheduling between the host computer on the serial port and each node device. There is no need to pay attention to the allocation of serial port control rights. The bus scheduler transmits and schedules the data transmission between the host computer and each node device based on the soft bus of the serial port, making the data transmission transparent and simplified, and solving the serial port communication problem when there are multiple devices under the serial port.
[0068] Figure 1 A schematic diagram of a system architecture provided in an embodiment of the present application. Figure 1 As shown, the PC simulates multiple devices under the serial port. The simulation software needs to realize multiple devices under a single serial port. The serial port is used for communication between the host computer 100 and multiple devices. For example, multiple devices include device node 201, device node 202, and device node 203. The number of devices can be determined according to actual working conditions. The embodiment of this application does not limit the number of devices.
[0069] The serial port can be, for example, an RS485 serial port or an RS232 serial port. Taking the RS485 serial port as an example, a soft bus corresponding to the serial port can be encapsulated for the serial port, such as Figure 1 485 soft bus in the bus scheduler 300. The soft bus runs on the bus scheduler 300, which is configured to execute the serial port communication method provided in the embodiment of the present application, so that the soft bus it runs can be responsible for the data transmission and scheduling between the host computer 100 and each node device on the serial port. Compared with the prior art, there is no need to pay attention to the allocation of serial port control rights. The bus scheduler 300 transmits and schedules the data transmission between the host computer 100 and each node device based on the soft bus of the serial port, making the data transmission transparent and simplified, and solving the serial port communication problem when there are multiple devices under the serial port.
[0070] In some embodiments, if the serial port is an RS232 serial port, the serial port address can be distinguished so that the RS232 serial port can also be connected to multiple devices, and is no longer subject to the RS232 point-to-point limitation.
[0071] It is understandable that Figure 1 Each node device in the multi-device simulator can be a device in the multi-device simulator. The embodiment of the present application does not limit the specific type of the device. The bus scheduler 300 is configured in the multi-device simulator. In addition, the number of host computers can also be multiple. Figure 1 In the figure, a host computer 100 is taken as an example, and there is a one-to-one correspondence between the host computer and the serial port.
[0072] It should be noted that the above system architecture is merely illustrative, and the serial communication method, device, and storage medium provided in the embodiments of the present application include but are not limited to the above system architecture. Figure 1 Soft bus 1 in.
[0073] Figure 2 The present invention provides a flow chart of a serial communication method, which can be applied to a bus scheduler. The bus scheduler runs a soft bus with a serial port, and the serial port is used for communication between the host computer and each node device. Figure 2 As shown, the serial communication method provided in the embodiment of the present application includes:
[0074] S101: Receive first data sent by a data sending device.
[0075] The data sending device is a host computer or any node device.
[0076] The data sending device completes registration on the soft bus. This registration allows the soft bus running the bus scheduler to know the node address of the data sending device and the address of the data receiving function. At the same time, the bus scheduler sends the data sending function address to the data sending device. The data sending device can be a host computer or any node device.
[0077] The data sending device can call the data sending function address sent to it by the soft bus in the bus scheduler to call the data sending function. The data sending device then sends the data to be sent through the called data sending function, defining the data to be sent as first data. In other words, the data sending device sends the first data to the soft bus through the called data sending function. Accordingly, the soft bus receives the first data sent by the data sending device through the data sending function, wherein the data sending function is obtained by the data sending device by calling the data sending function address sent to the data sending device by the soft bus. It is understandable that the content of the first data is determined by the data content actually transmitted or scheduled by the node device or the host computer under actual working conditions.
[0078] In one possible design, calling a data transmission function on the soft bus requires obtaining authorization from the soft bus. For example, the soft bus can enable the data transmission device to obtain authorization by executing a private function, such as executing the private function getBusControlRight() to obtain authorization.
[0079] S102: Acquire a node address of a data sending device to determine a data receiving device according to the node address of the data sending device.
[0080] The data receiving device is a host computer or a host computer and each node device.
[0081] After receiving the first data sent by the data sending device, the soft bus obtains the node address of the data sending device. The node address of the data sending device is communicated to the soft bus when the data sending device registers with the soft bus. The node address of the data sending device uniquely identifies the data sending device. The soft bus then determines the data receiving device based on the node address of the data sending device.
[0082] For example, the data sending device is determined to be a host computer based on the node address of the data sending device, and the transmission direction of the first data is data downlink, then the data receiving device can be each node device; the data sending device is determined to be any node device based on the node address of the data sending device, and the transmission direction of the first data can be data uplink or broadcast. When the transmission direction is data uplink, the data receiving device can be the host computer, and when the transmission direction is broadcast, the data receiving device can be the host computer and each node device, that is, all receivers.
[0083] In addition, the soft bus defines a preset transmission direction identifier, which is used to indicate a data transmission direction, including any of uplink, downlink, and broadcast. After determining the data sending device, the soft bus can determine the data transmission direction of the first data based on the preset transmission direction identifier.
[0084] S103: calling a data receiving function address of the data receiving device to send first data to the data receiving device according to the data receiving function address of the data receiving device.
[0085] The data transmitting device and the data receiving device must complete registration on the soft bus. During registration, the data receiving device informs the soft bus of the address of its data receiving function. After determining the data receiving device, the soft bus calls the data receiving function address registered with the soft bus. Based on the called data receiving function address, the data receiving device sends the first data to the data receiving device. The data receiving device then receives the first data sent by the soft bus. This allows data transmission and scheduling between the data transmitting device and the data receiving device to be implemented over the soft bus.
[0086] Through the description of the above embodiment, it can be seen that for the soft bus of the serial port encapsulation serial port, data transmission between the data sending device and the data receiving device corresponding to the serial port is realized based on the soft bus, wherein the data sending device can be a host computer or any node device. When the data sending device is a host computer, the data receiving device can be each node device; when the data sending device is any node device, the data receiving device can be the host computer and each node device. In the serial communication method provided by the embodiment of the present application, for example, when the host computer transmits data to the data receiving device as a data sending device, the host computer does not need to pay attention to how to send the data to the corresponding node device; for example, when any node device transmits data to the host computer and each node device as a data sending device, such as when the transmission direction is uplink or broadcast, any node device also does not need to pay attention to how to send the data to the host computer and each node device. The data sending device only needs to send the data to be transmitted to the soft bus, and the soft bus realizes data transmission and scheduling, making the data transmission process transparent and simplified when there are multiple devices under the serial port, without having to pay attention to the allocation of serial port control rights, and can solve the serial port communication problem when there are multiple devices under the serial port. Otherwise, for example, when broadcasting data, the broadcast data becomes complicated because the node devices are not related to each other.
[0087] exist Figure 2 On the basis of Figure 3 This is a flow chart of another serial communication method provided in the embodiment of the present application. Figure 3 As shown, the serial communication method provided in the embodiment of the present application includes:
[0088] S201: Generate a soft bus class for the serial port according to parameter configuration information of the serial port.
[0089] A soft bus class is pre-generated for the serial port based on the serial port's parameter configuration to encapsulate the corresponding soft bus for the serial port. This soft bus class includes multiple enumeration types for each node on the serial port during the communication process. These enumeration types are used to declare the preset data transfer direction identifier, preset node address, host computer linked list, and device linked list during the communication process. It is understood that each node on the serial port includes the host computer and each node device.
[0090] In some embodiments, a soft bus class is generated for each serial port, and the soft bus class is as follows:
[0091] enum BusState
[0092] {
[0093] Receiving=1, / / Receiving status
[0094] Sending=2 / / Sending status
[0095] };
[0096] enum DataMode
[0097] {
[0098] Up=1, / / Data uplink, that is, the node device sends data to each host computer on the bus (usually there is only one host computer)
[0099] Down=2, / / Data is sent down, that is, the host computer sends data to each node device on the bus
[0100] Broadcast = 3 / / Broadcast, that is, the sender broadcasts the data to all receivers on the bus, including the host computer and node devices
[0101] };
[0102] enum LockType
[0103] {
[0104] NotLock=1 / / Not locked
[0105] UpLock=2, / / Lock the uplink, only one can send when uplink
[0106] DownLock=3, / / Lock downlink, only one can send downlink
[0107] AllLock=4 / / lock both uplink and downlink
[0108] };
[0109] class SoftBus
[0110] {
[0111] private enum BusState currentState;
[0112] upNodeList=new List <upnode>(); / / Host computer linked list, host computer parameters include address, data receiving function
[0113] downNodeList=new List <downnode>(); / / Device list, the parameters of a node device include address, data receiving function
[0114] public bool SendDataToSoftBus(byte[]sendBuffer,int bytesToSend,refint bytesSent,int sourceAddress);
[0115] / / Register to the soft bus. When Address is -1, it means it is a host computer. Generally, the host computer has no address. If there are multiple host computers,
[0116] / / Address = -2, -3 to distinguish different host computers
[0117] / / Address>=0, indicating a node device. Under the same serial port, the node addresses of node devices cannot be the same.
[0118] public bool RegisterToSoftBus(int Address,ReceiveDataDelegatesendDataProcessAddress,SendDataToSoftBusDelegate sendDataToSoftBusAddress);
[0119] public bool UnRegisterToSoftBus(int Address,ReceiveDataDelegatesendDataProcessAddress,SendDataToSoftBusDelegate sendDataToSoftBusAddress);
[0120] private bool getBusControlRight();
[0121] private bool freeBusControlRight();
[0122] }
[0123] As shown above, the soft bus uses a preset transfer direction identifier to define the data transfer direction, which includes uplink, downlink, and broadcast. The preset node address defines the node address of each node on the serial port. The host computer linked list includes host computer parameters, including the host computer's data receive function address and data receive function. The device linked list includes parameters for each node device, including the node device's data receive function address and data receive function.
[0124] S202a: Receive the node addresses and data receiving function addresses sent by the host computer and each node device.
[0125] S202b: Send the corresponding data sending function address to the host computer and each node device to complete the registration of the host computer and each node device on the soft bus.
[0126] Steps S202a and S202b are implementations of the soft bus registration of the host computer and each node device on the serial port. Specifically, the host computer and each node device send their respective node addresses and respective data receiving function addresses to the soft bus, so that the soft bus learns the respective node addresses and data receiving function addresses of the host computer and each node device. Simultaneously, the soft bus transmits the data sending function addresses of the host computer and each node device to the soft bus back to the host computer and each node device, thereby completing the registration of the host computer and each node device on the soft bus.
[0127] S203: Receive first data sent by the host computer or any node device.
[0128] The host computer or any node device calls the data sending function by calling the data sending function address sent to the host computer or any node device by calling the soft bus, and then sends the first data to the soft bus according to the data sending function. Accordingly, the soft bus receives the first data sent by the host computer or any node device.
[0129] In one possible design, the host computer or any node device must obtain authorization from the soft bus before calling the data transmission function of the soft bus. For example, the soft bus can enable the host computer or any node device to obtain authorization by executing a private function. For example, the authorization action can be performed in the data transmission function, that is, executing the private function getBusControlRight().
[0130] The data sending device can be a host computer or any node device. Whether the data sending device is a host computer or any node device is determined based on the node address of the data sending device and the preset node address. The node addresses of the host computer and each node device are defined in the preset node address. When it is determined that the data sending device is a host computer, the soft bus receives the first data sent by the host computer, then data is downlinked, and steps S204a, S205a and S206a are executed after step S203; when it is determined that the data sending device is any node device, the soft bus receives the first data sent by any node device, then data is uplinked or broadcast, wherein steps S204b, S205b and S206b are executed after step S203 for data uplink, and steps S204c, S205c and S206c are executed after step S203 for broadcasting.
[0131] S204a: Determine the data receiving device as each node device according to the preset transmission direction identifier.
[0132] The soft bus defines a preset transmission direction identifier, which is used to indicate the direction of data transmission, including uplink, downlink, and broadcast. If the data transmitting device is the host computer, the data transmission direction of the first data is determined to be downlink based on the preset transmission identifier. The data receiving device is each node device.
[0133] S205a: Calling the data receiving function of each node device according to the data receiving function address of each node device.
[0134] S206a: Sending first data to each node device according to the data receiving function of each node device.
[0135] The soft bus determines that the data receiving device is each node device, then calls the data receiving function address of each node device to call the data receiving function of each node device, and then sends the first data to each node device according to the data receiving function of each node device, thereby realizing the transmission of the first data from the host computer to each node device, that is, realizing the downstream transmission of the first data.
[0136] S204b: Determine that the data receiving device is a host computer according to a preset transmission direction identifier.
[0137] If the data transmitting device is any node device, the data transmission direction of the first data is determined to be uplink or broadcast based on a preset transmission identifier. Uplink or broadcast can be determined based on the data transmission identifier carried by the first data. When the data transmission direction is determined to be uplink based on the data transmission identifier, the data receiving device is only the host computer. If the data transmission direction is determined to be broadcast, the data receiving device is the host computer and.
[0138] S205b: Call the data receiving function of the host computer according to the data receiving function address of the host computer.
[0139] S206b: Send the first data to the host computer according to the data receiving function of the host computer.
[0140] The soft bus determines that the data receiving device is the host computer, and then calls the data receiving function address of the host computer to call the data receiving function of the host computer, and then sends the first data to the host computer according to the data receiving function of the host computer, thereby realizing the transmission of the first data from any node device to the host computer, that is, realizing the uplink transmission of the first data.
[0141] S204c: Determine the data receiving device as the host computer and each node device according to the preset transmission direction identifier.
[0142] If the data transmitting device is any node device, the data transmission direction of the first data is determined to be uplink or broadcast based on a preset transmission identifier. Uplink or broadcast can be determined based on the data transmission identifier carried by the first data. When the data transmission direction is determined to be broadcast based on the data transmission identifier, the data receiving devices are the host computer and each node device.
[0143] S205c: calling the data receiving function of the host computer and each node device according to their respective data receiving function addresses.
[0144] S206c: Send the first data to the host computer and each node device according to the data receiving functions of the host computer and each node device respectively.
[0145] The soft bus determines that the data receiving devices are the host computer and each node device, and then calls the data receiving function addresses of the host computer and each node device to call the data receiving functions of the host computer and each node device, and then broadcasts the first data to the host computer and each node device according to the data receiving functions of the host computer and each node device, thereby realizing the transmission of the first data from all receivers on the serial port of any node device, that is, realizing the broadcast of the first data.
[0146] Furthermore, after the host computer or each node device, or both, receives the first data, the data receiving device must also return the return data corresponding to the first data to the data sending device, defining the return data of the first data as the second data. Specifically, the soft bus receives the second data returned by the data receiving device and returns the second data to the data sending device. The data receiving device can return the second data by calling a data sending function sent by the soft bus to the data receiving device.
[0147] At this point, the soft bus can complete the downlink transmission of the first data from the host computer to each node device, the uplink transmission of the first data from any node device to the host computer, or the broadcast of the first data from any node device to the host computer and each node device, thereby realizing the transmission and scheduling of the first data. The data transmission process does not require attention to the control of the serial port; it only needs to transfer the first data to the soft bus, which then performs the transmission and scheduling of the first data. This makes the data transmission process transparent and simplified, and can solve the complex communication problem of serial port data transmission when multiple devices are connected to the serial port.
[0148] Figure 4 This is a structural diagram of a serial communication device provided in an embodiment of the present application. The serial communication device can be applied to a bus scheduler. The bus scheduler runs a soft bus with a serial port. The serial port is used for communication between the host computer and each node device. Figure 4 As shown, the serial communication device 400 provided in the embodiment of the present application includes:
[0149] A receiving module 401 is configured to receive first data sent by a data sending device, where the data sending device is a host computer or any node device;
[0150] Processing module 402, configured to obtain a node address of a data sending device to determine a data receiving device according to the node address of the data sending device, where the data receiving device is a host computer or a host computer and each node device;
[0151] The calling and sending module 403 is configured to call the data receiving function address of the data receiving device, so as to send the first data to the data receiving device according to the data receiving function address of the data receiving device.
[0152] exist Figure 4 On the basis of Figure 5 This is a structural diagram of another serial communication device provided in an embodiment of the present application. Figure 5 As shown, the serial communication device 400 provided in the embodiment of the present application further includes: a registration module 404, the registration module 404 is used to:
[0153] Receive the node addresses and data receiving function addresses sent by the host computer and each node device, and send the corresponding data sending function addresses to the host computer and each node device to complete the registration of the host computer and each node device on the soft bus.
[0154] exist Figure 5 On the basis of Figure 6 This is a structural diagram of another serial communication device provided in the embodiment of the present application. Figure 6 As shown, the serial communication device 400 provided in the embodiment of the present application further includes: a bus class generation module 405, the bus class generation module 405 is used to:
[0155] A soft bus class is generated for the serial port according to the parameter configuration information of the serial port. The soft bus class includes multiple enumeration types of the host computer and each node device during the communication process. The enumeration type is used to declare the preset transmission direction identifier, preset node address, host computer linked list and device linked list.
[0156] In one possible design, receiving module 401 is specifically configured to:
[0157] By executing the private function, the data sending device obtains the authorization of the soft bus;
[0158] The first data sent by the data sending device through the data sending function is received, where the data sending function is obtained by the data sending device calling its own data sending function address.
[0159] In one possible design, the processing module 402 is specifically configured to:
[0160] Determine whether the data sending device is a host computer or any node device according to the node address of the data sending device and the preset node address;
[0161] If it is determined that the data sending device is the host computer, the data receiving device is determined to be each node device according to the preset transmission direction identifier;
[0162] If it is determined that the data sending device is any node device, the data receiving device is determined to be the host computer or the host computer and each node device according to the preset transmission direction identifier.
[0163] In one possible design, if it is determined that the data receiving device is each node device, the calling and sending module 403 is specifically configured to:
[0164] Call the data receiving function of each node device according to the data receiving function address of each node device;
[0165] The first data is sent to each node device according to the data receiving function of each node device.
[0166] In one possible design, if it is determined that the data receiving device is a host computer, the calling and sending module 403 is specifically used to:
[0167] Call the data receiving function of the host computer according to the data receiving function address of the host computer;
[0168] The first data is sent to the host computer according to the data receiving function of the host computer.
[0169] In one possible design, the serial communication device 400 further includes a return module, which is configured to:
[0170] Receiving second data sent by the host computer and / or each node device through its own data sending function, where the second data is the return data of the first data;
[0171] The second data is transmitted back to the data sending device.
[0172] The serial communication device provided in the embodiment of the present application can execute each step of the serial communication method in the above method embodiment. Its implementation principle and technical effects are similar and will not be repeated here.
[0173] Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 7 As shown, the electronic device 500 provided in the embodiment of the present application may include: a processor 501, and a memory 502 communicatively connected to the processor 501.
[0174] The memory 502 is used to store programs. Specifically, the programs may include program codes, and the program codes include computer-executable instructions.
[0175] The memory 502 may include a high-speed RAM memory, and may also include a non-volatile memory (NoN-volatile memory), such as at least one disk memory.
[0176] The processor 501 is configured to execute computer-executable instructions stored in the memory 502 to implement the serial port communication method.
[0177] The processor 501 may be a central processing unit (CPU), an application specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present application.
[0178] Optionally, the memory 502 may be independent or integrated with the processor 501. When the memory 502 is a device independent of the processor 501, the control system 500 may further include:
[0179] Bus 503 is used to connect processor 501 and memory 502. The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus. Buses can be divided into address buses, data buses, control buses, etc., but this does not mean that there is only one bus or only one type of bus.
[0180] Optionally, in a specific implementation, if the memory 502 and the processor 501 are integrated on a chip, the memory 502 and the processor 501 can communicate through an internal interface.
[0181] The present application also provides a computer-readable storage medium, which may include: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, and other media that can store program codes. Specifically, the computer-readable storage medium stores computer execution instructions, and the computer execution instructions are used for each step of the method in the above embodiment.
[0182] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present application that follow the general principles of the present application and include common knowledge or customary techniques in the art not disclosed herein. The description and examples are to be considered merely as exemplary, and the true scope and spirit of the present application are indicated by the claims.
[0183] It should be understood that the present application is not limited to the exact structure described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.< / downnode> < / upnode>
Claims
1. A serial port communication method, characterized in that, it is applied to a bus scheduler, and the bus scheduler runs a soft bus of the serial port, and the serial port is used for communication between the host computer and each node device; the method includes: receiving first data sent by a data sending device, where the data sending device is the host computer or any node device; obtaining the node address of the data sending device to determine a data receiving device according to the node address of the data sending device, where the data receiving device is the host computer or the host computer and each node device; invoking the data receiving function address of the data receiving device to send the first data to the data receiving device according to the data receiving function address of the data receiving device.
2. The serial port communication method according to claim 1, characterized in that, before receiving the first data sent by the data sending device, it further includes: receiving the respective node addresses and respective data receiving function addresses sent by the host computer and each node device, and sending the corresponding data sending function addresses to the host computer and each node device to complete the registration of the host computer and each node device on the soft bus.
3. The serial port communication method according to claim 2, characterized in that, before receiving the respective node addresses and respective data receiving function addresses sent by the host computer and each node device, it further includes: generating a soft bus class for the serial port according to the parameter configuration information of the serial port, where the soft bus class includes multiple enumerated types in the communication process of the host computer and each node device, and the enumerated types are used to declare a preset transfer direction identifier, a preset node address, a host computer linked list, and a device linked list.
4. The serial port communication method according to claim 3, characterized in that, receiving the first data sent by the data sending device includes: enabling the data sending device to obtain authorization from the soft bus by executing a private function; receiving the first data sent by the data sending device through a data sending function, where the data sending function is obtained by the data sending device calling its own data sending function address.
5. The serial port communication method according to claim 4, characterized in that, determining the data receiving device according to the node address of the data sending device includes: determining whether the data sending device is the host computer or any node device according to the node address of the data sending device and the preset node address; if it is determined that the data sending device is the host computer, determining the data receiving device as each node device according to the preset transfer direction identifier; if it is determined that the data sending device is any node device, determining the data receiving device as the host computer or the host computer and each node device according to the preset transfer direction identifier.
6. The serial port communication method according to claim 5, characterized in that, If it is determined that the data receiving device is each of the node devices, sending the first data to the data receiving device according to the data receiving function address of the data receiving device includes: Invoking the data receiving function of each node device according to the data receiving function address of each node device; Sending the first data to each node device according to the data receiving function of each node device.
7. The serial port communication method according to claim 5, wherein, If it is determined that the data receiving device is the host computer, sending the first data to the data receiving device according to the data receiving function address of the data receiving device includes: Invoking the data receiving function of the host computer according to the data receiving function address of the host computer; Sending the first data to the host computer according to the data receiving function of the host computer.
8. The serial port communication method according to claim 5, wherein, After the host computer and / or each node device receives the first data, it further includes: Receiving second data sent by the host computer and / or each node device through its own data sending function, where the second data is the feedback data of the first data; Returning the second data to the data sending device.
9. The serial port communication method according to any one of claims 1-8, wherein, The serial port includes an RS485 serial port or an RS232 serial port.
10. A serial port communication device, wherein, Applied to a bus scheduler, the bus scheduler runs a software bus of a serial port, and the serial port is used for communication between a host computer and each node device; The device includes: A receiving module, configured to receive first data sent by a data sending device, where the data sending device is the host computer or any one of the node devices; A processing module, configured to obtain the node address of the data sending device, so as to determine a data receiving device according to the node address of the data sending device, where the data receiving device is the host computer or the host computer and each node device; An invocation and sending module, configured to invoke the data receiving function address of the data receiving device, so as to send the first data to the data receiving device according to the data receiving function address of the data receiving device.
11. The serial port communication device according to claim 10, wherein, The serial port communication device further includes: a registration module; the registration module is configured to: Receive the respective node addresses and respective data receiving function addresses sent by the host computer and each node device, and send the corresponding data sending function addresses to the host computer and each node device, so as to complete the registration of the host computer and each node device on the software bus.
12. The serial port communication device according to claim 11, wherein, The serial port communication device further includes: a bus class generation module; the bus class generation module is configured to: Generate a soft bus class for the serial port according to the parameter configuration information of the serial port. The soft bus class includes multiple enumeration types in the communication process of the host computer and each node device. The enumeration types are used to declare a preset transfer direction identifier, a preset node address, a host computer linked list, and a device linked list.
13. The serial port communication device according to claim 12, wherein, the receiving module is specifically configured to: enable the data sending device to obtain authorization from the soft bus by executing a private function; receive the first data sent by the data sending device through a data sending function, and the data sending function is obtained by the data sending device calling its own data sending function address.
14. The serial port communication device according to claim 13, wherein, the processing module is specifically configured to: determine whether the data sending device is the host computer or any node device according to the node address of the data sending device and the preset node address; if it is determined that the data sending device is the host computer, determine the data receiving device as each node device according to the preset transfer direction identifier; if it is determined that the data sending device is any node device, determine the data receiving device as the host computer or the host computer and each node device according to the preset transfer direction identifier.
15. The serial port communication device according to claim 14, wherein, if it is determined that the data receiving device is each node device, the calling and sending module is specifically configured to: call the data receiving function of each node device according to the data receiving function address of each node device; send the first data to each node device according to the data receiving function of each node device.
16. The serial port communication device according to claim 14, wherein, if it is determined that the data receiving device is the host computer, the calling and sending module is specifically configured to: call the data receiving function of the host computer according to the data receiving function address of the host computer; send the first data to the host computer according to the data receiving function of the host computer.
17. The serial port communication device according to claim 14, wherein, the serial port communication device further includes: a feedback module; the feedback module is configured to: receive second data sent by the host computer and / or each node device through its own data sending function, and the second data is the feedback data of the first data; feedback the second data to the data sending device.
18. A computer-readable storage medium, wherein, computer-executable instructions are stored in the computer-readable storage medium, and when the computer-executable instructions are executed by a processor, they are used to implement the serial port communication method according to any one of claims 1 to 9.