CN115834282A - CAN bus communication method, device, equipment and readable storage medium - Google Patents
CAN bus communication method, device, equipment and readable storage medium Download PDFInfo
- Publication number
- CN115834282A CN115834282A CN202211387508.2A CN202211387508A CN115834282A CN 115834282 A CN115834282 A CN 115834282A CN 202211387508 A CN202211387508 A CN 202211387508A CN 115834282 A CN115834282 A CN 115834282A
- Authority
- CN
- China
- Prior art keywords
- slave
- master
- host
- mode
- machine
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000004891 communication Methods 0.000 title claims abstract description 75
- 238000000034 method Methods 0.000 title claims abstract description 52
- 230000000737 periodic effect Effects 0.000 claims abstract description 28
- 230000001360 synchronised effect Effects 0.000 claims abstract description 11
- 238000004590 computer program Methods 0.000 claims description 10
- 230000004044 response Effects 0.000 claims description 10
- 230000002159 abnormal effect Effects 0.000 claims description 8
- 230000008569 process Effects 0.000 description 8
- 238000010586 diagram Methods 0.000 description 7
- 238000012545 processing Methods 0.000 description 7
- 230000003993 interaction Effects 0.000 description 3
- 230000003287 optical effect Effects 0.000 description 3
- 230000006870 function Effects 0.000 description 2
- 230000004048 modification Effects 0.000 description 2
- 238000012986 modification Methods 0.000 description 2
- 238000013459 approach Methods 0.000 description 1
- 238000003491 array Methods 0.000 description 1
- 238000013473 artificial intelligence Methods 0.000 description 1
- 230000005540 biological transmission Effects 0.000 description 1
- 238000004364 calculation method Methods 0.000 description 1
- 230000001413 cellular effect Effects 0.000 description 1
- 238000013461 design Methods 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 230000006872 improvement Effects 0.000 description 1
- 239000004973 liquid crystal related substance Substances 0.000 description 1
- 238000010801 machine learning Methods 0.000 description 1
- 238000012423 maintenance Methods 0.000 description 1
- 230000006855 networking Effects 0.000 description 1
- 239000013307 optical fiber Substances 0.000 description 1
- 239000004065 semiconductor Substances 0.000 description 1
- 230000001953 sensory effect Effects 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
- 230000000007 visual effect Effects 0.000 description 1
Images
Classifications
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02P—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN THE PRODUCTION OR PROCESSING OF GOODS
- Y02P90/00—Enabling technologies with a potential contribution to greenhouse gas [GHG] emissions mitigation
- Y02P90/02—Total factory control, e.g. smart factories, flexible manufacturing systems [FMS] or integrated manufacturing systems [IMS]
Landscapes
- Information Transfer Systems (AREA)
Abstract
The embodiment of the disclosure provides a CAN bus communication method, a device, equipment and a readable storage medium, wherein the method comprises the following steps: the method comprises the steps that a communication link is established between a host and a slave; the master machine sends a periodic synchronization frame to each slave machine on the CAN bus; each slave machine receives the periodic synchronous frame sent by the host machine and sends data of an active error counter or a passive error counter to the host machine; the master machine determines the mode of each slave machine according to the error counter data sent by each slave machine and sets the mode of each slave machine; and each slave computer actively enters a corresponding mode according to the mode set by the master computer. In this way, a CAN bus data communication mode with a master-slave mode and a multi-master mode mixed is realized, and a data link CAN be ensured to have reliable link under the condition of reducing the load rate of a data bus.
Description
Technical Field
The present disclosure relates to the field of communications, and more particularly, to the field of CAN bus communications.
Background
CAN and CAN FD (CAN) bus technologies are widely used in various electronic devices and systems in trains. The CAN bus is a multi-master bus, and each node participating in networking CAN independently send data.
However, in a train, the architecture of the electronic device and system is generally a master → slave mode, the slave periodically receives a command from the master and sends various data to the master, and the architecture of the CAN bus multi-master mode is not logically matched with the master-slave mode control system. Meanwhile, the CAN bus CAN only bear 8 bytes or 64 bytes (CAN FD) data at most, so that complex timing messages are hard to bear, if a multi-master protocol is adopted, a host and a plurality of slaves do not have clock synchronization, and due to clock deviation of each host or slave, the data of the host and the data of the slaves are hard to be ensured in the same control period, so that the real-time performance of the data is hard to be ensured.
Another way to use a CAN bus is to use a master-slave approach, where the entire bus is controlled by the host. When the host needs to control the slave mode, the control data is actively issued to the slave, the slave executes the command after receiving the command, and the execution framework is fed back to the host. The host and the slave agree on the valid time, if the host issues a command at the time of T0, the slave feeds back the execution result in one period T, and then the host should receive the feedback data within the time of T0+ T, otherwise, the communication failure is defined. When the host needs to collect the data of the slave, the host issues a command to the slave, the slave feeds the data back to the host immediately due to the real-time requirement of the collected data, and if the data is not fed back, the host continuously issues the command of the data request to the slave.
Disclosure of Invention
The disclosure provides a CAN bus communication method, a device, equipment and a readable storage medium.
According to a first aspect of the present disclosure, there is provided a CAN bus communication method including:
the method comprises the steps that a communication link is established between a host and a slave;
the master machine sends a periodic synchronization frame to each slave machine on the CAN bus;
each slave machine receives the periodic synchronization frame sent by the host machine and sends data of an active error counter or a passive error counter to the host machine;
the master machine determines the mode of each slave machine according to the error counter data sent by each slave machine and sets the mode of each slave machine;
and each slave computer actively enters a corresponding mode according to the mode set by the master computer.
In some implementations of the first aspect, the establishing, by the master, the communication link with the slave includes:
after the slave computer is electrified and normally operates, if the control command of the host computer is not received, the CAN node is directly driven to enter a master mode, and a registration frame is actively sent to the host computer and waits for the response of the host computer;
after the host is electrified and normally operates, if the register frame of any slave machine is not received, the broadcast frame is actively initiated, each slave machine is required to send the register frame, and each slave machine is waited for successful registration.
In some implementations of the first aspect, the sending, by the master, the cycle synchronization frame to each slave on the CAN bus comprises:
and the master machine sends a periodic synchronization frame to each slave machine on the CAN bus in a broadcast frame mode so that the slave machines are synchronized with the master machine after receiving the periodic synchronization frame.
In some implementations of the first aspect, the receiving, by each slave, a periodic synchronization frame sent by the master, and sending data of an active error counter or a passive error counter to the master includes:
and each slave receives the periodic synchronous frame sent by the host, calculates time deviation, and sends the time deviation and error counter data to the host if the time deviation between the operating period of the slave and the periodic synchronous frame sent by the host exceeds a threshold value.
In some implementations of the first aspect, the determining, by the master, a mode of each slave according to the error counter data sent by each slave, and performing mode setting on each slave includes:
under normal conditions, the CAN bus is in an active error state, and when an error frame is received, the active error counter accumulates corresponding numerical values according to error types;
if the value of the active error counter is smaller than a first threshold value, the slave mode is the master mode, otherwise, the slave mode is changed into the slave mode;
in the slave mode, if the value of the active error counter is smaller than a second threshold value, the CAN bus is in an active error state, otherwise, the CAN bus is changed into a passive error state;
in the passive error state, if the value of the passive error counter is smaller than a third threshold value, the passive error counter continues to accumulate the corresponding value, otherwise, the CAN bus is closed.
In some implementations of the first aspect, the method further comprises:
if the host judges that the communication is finished, the host sends a command to each slave on the CAN bus, and each slave receives the command sent by the host and stops sending data;
if the host judges that the communication is abnormal, the communication link is disconnected, the state of the CAN bus is checked, and the link is reestablished.
According to a second aspect of the present disclosure, there is provided a CAN bus communication apparatus including:
the link establishing unit is used for establishing a communication link between the host and the slave;
the system comprises a period synchronization frame sending unit, a CAN bus and a synchronization frame receiving unit, wherein the period synchronization frame sending unit is used for sending a period synchronization frame to each slave on the CAN bus by the host;
the master-slave synchronization unit is used for receiving the periodic synchronization frame sent by the host by each slave and sending data of an active error counter or a passive error counter to the host;
the mode setting unit is used for determining the mode of each slave machine by the master machine according to the error counter data sent by each slave machine and setting the mode of each slave machine;
and the working unit is used for enabling each slave to actively enter a corresponding mode according to the mode set by the host.
According to a third aspect of the present disclosure, an electronic device is provided. The electronic device includes: a memory having a computer program stored thereon and a processor implementing the method as described above when executing the program.
According to a fourth aspect of the present disclosure, there is provided a computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements a method as in accordance with the first aspect of the present disclosure.
According to the method, communication links are established between a master machine and a plurality of slave machines, after links are established between the master machine and all the slave machines, the master machine sends special data frames to all equipment on a bus to serve as control period synchronization marks, all the slave machines and the master machine can be in the same control period, after the master machine sends the synchronization marks to the slave machines, each slave machine sends data of an active error counter or a passive error counter to the master machine to serve as a response, the master machine determines whether the slave machine is in a master mode or a slave mode according to the error counter, and the slave machines actively enter the corresponding modes according to the modes set by the master machine. In this way, a master-slave mode and multi-master mode mixed CAN bus data communication mode is realized, and a data link CAN be ensured to have reliable link under the condition of reducing the load rate of a data bus.
It should be understood that the statements herein reciting aspects are not intended to limit the critical or essential features of the embodiments of the present disclosure, nor are they intended to limit the scope of the present disclosure. Other features of the present disclosure will become apparent from the following description.
Drawings
The above and other features, advantages and aspects of various embodiments of the present disclosure will become more apparent by referring to the following detailed description when taken in conjunction with the accompanying drawings. The accompanying drawings are included to provide a further understanding of the present disclosure, and are not intended to limit the disclosure thereto, and the same or similar reference numerals will be used to indicate the same or similar elements, where:
fig. 1 shows a flow diagram of a CAN bus communication method according to an embodiment of the disclosure;
FIG. 2 shows a flow chart of a CAN bus communication method according to an embodiment of the disclosure;
FIG. 3 shows a block diagram of a CAN bus communication device in accordance with an embodiment of the present disclosure;
FIG. 4 illustrates a block diagram of an exemplary electronic device capable of implementing embodiments of the present disclosure.
Detailed Description
To make the objects, technical solutions and advantages of the embodiments of the present disclosure more clear, the technical solutions of the embodiments of the present disclosure will be described clearly and completely with reference to the drawings in the embodiments of the present disclosure, and it is obvious that the described embodiments are some, but not all embodiments of the present disclosure. All other embodiments, which can be derived by a person skilled in the art from the embodiments disclosed herein without inventive step, are intended to be within the scope of the present disclosure.
In addition, the term "and/or" herein is only one kind of association relationship describing an associated object, and means that there may be three kinds of relationships, for example, a and/or B, which may mean: a exists alone, A and B exist simultaneously, and B exists alone. In addition, the character "/" herein generally indicates that the former and latter related objects are in an "or" relationship.
According to the method, communication links are established between a master machine and a plurality of slave machines, after the master machine and all the slave machines establish links, the master machine sends special data frames to all equipment on a bus as control period synchronization marks, all the slave machines can be in the same control period with the master machine, after the master machine sends the synchronization marks to the slave machines, each slave machine sends data of an active error counter or a passive error counter of the slave machine to the master machine as a response, the master machine determines whether the slave machine is in a master mode or a slave mode according to the error counters, if the master machine judges that data communication is finished, a command is sent to the slave machine, the slave machine stops sending the data after receiving the command, if the communication is abnormal, the links are disconnected, the bus state is checked, and the links are reestablished.
Fig. 1 shows a flow diagram of a CAN bus communication method according to an embodiment of the disclosure.
As shown in fig. 1, initially, a communication link is established between a master and each slave, the master sends a periodic synchronization frame to the slave in the form of a broadcast frame, each slave processes and calculates a time offset, the slave receives the periodic synchronization frame sent by the master and sends the time offset, active error counter data and passive error counter data as responses, the master determines an operating mode of the slave according to slave information, the slave actively enters a corresponding mode after receiving the slave, the master actively sends the time offset and the error counter data, the slave actively waits for a data packet requested by the master and then sends the data, and the master processes the data after receiving the data sent by the slave.
Fig. 2 shows a flow chart of a CAN bus communication method according to an embodiment of the disclosure.
As shown in fig. 2, the CAN bus communication method 200 includes:
s201: the method comprises the steps that a communication link is established between a host computer and a slave computer;
s202: the master machine sends a periodic synchronization frame to each slave machine on the CAN bus;
s203: each slave machine receives the periodic synchronization frame sent by the host machine and sends data of an active error counter or a passive error counter to the host machine;
s204: the master machine determines the mode of each slave machine according to the error counter data sent by each slave machine and performs mode setting on each slave machine;
s205: and each slave computer actively enters a corresponding mode according to the mode set by the master computer.
In S201, the establishing, by the master, a communication link with the slave includes:
after the slave computer is electrified and normally operates, if the control command of the host computer is not received, the CAN node is directly driven to enter a master mode, and a registration frame is actively sent to the host computer and waits for the response of the host computer;
after the host is powered on and normally operates, if the register frame of any slave machine is not received, the broadcast frame is actively initiated, each slave machine is required to send the register frame, and each slave machine is waited to be successfully registered.
According to the embodiment of the disclosure, because the host and the slave have different software and hardware, and the power-on time and the equipment self-checking process are different, the time for normal communication is also different. After the slave computer is powered on and normally operates firstly, if the control command of the host computer is not received, the CAN node is directly driven to enter a master mode, a registration frame is actively sent to the host computer and waits for the response of the host computer, and after the response of the host computer, data is sent to the host computer; after the host finishes electrifying and normally operates, if the register frame of any slave machine is not received, the broadcast frame is actively initiated to require each slave machine to send the register frame, and all the slave machines are waited to be successfully registered. Therefore, the host computer and the slave computer can confirm that the two parties work normally through interaction, and start to establish a communication link to normally send various commands and data.
In S202, the sending, by the master, the cycle synchronization frame to each slave on the CAN bus includes:
and the master machine sends a periodic synchronization frame to each slave machine on the CAN bus in a broadcast frame mode so that the slave machines are synchronized with the master machine after receiving the periodic synchronization frame.
According to the embodiment of the disclosure, after the host and all the slaves establish links, the host sends a special data frame to all the devices on the bus as a mark for controlling cycle synchronization, and no matter what state the current slave is, as long as the cycle synchronization frame sent by the host is received, the slave should be immediately synchronized with the host, so that all the slaves can be in the same control cycle with the host.
In S203, the step of receiving the periodic synchronization frame sent by the master from each slave and sending data of the active error counter or the passive error counter to the master includes:
and each slave receives the periodic synchronous frame sent by the host, calculates time deviation, and sends the time deviation and error counter data to the host if the time deviation between the operating period of the slave and the periodic synchronous frame sent by the host exceeds a threshold value.
In some embodiments, the active and passive error counters of the CAN bus are two registers in the CAN controller.
In some embodiments, after the master sends the synchronization flag to the slave, each slave starts to process and calculate the time offset, and if the slave finds that the current operation period is greatly different from the period synchronization frame sent by the master, for example, the timing error exceeds 10%, the slave reports a fault to the master and sends the time offset and the error counter data to the master.
It will be appreciated that a fault refers to a situation where the clock of the slave processor may have an excessive error.
According to the embodiment of the disclosure, the master sends the synchronization flag to the slave, and the slave calculates and processes the time deviation and simultaneously sends the time deviation and the error counter data to the master, so that the master adjusts the communication synchronization with the slave according to the time deviation and simultaneously meets the condition that the master receives the error counter data so as to set the mode of the slave.
In S204, the master determines a mode of each slave according to the error counter data sent by each slave, and performing mode setting on each slave includes:
under normal conditions, the CAN bus is in an active error state, and when an error frame is received, an active error counter accumulates corresponding numerical values according to error types;
if the value of the active error counter is smaller than a first threshold value, the slave mode is the master mode, otherwise, the slave mode is changed into the slave mode;
in the slave mode, if the value of the active error counter is smaller than a second threshold value, the CAN bus is in an active error state, otherwise, the CAN bus is changed into a passive error state;
in the passive error state, if the value of the passive error counter is smaller than a third threshold value, the passive error counter continues to accumulate the corresponding value, otherwise, the CAN bus is closed.
In some embodiments, the CAN is normally in an active error state, and when an error frame is received, the active error counter is incremented by 8 (different error types may be incremented by different values), and when incremented by 96, an alarm is generated, and when incremented by 127, the active error state changes to a passive error state, and when the passive error counter counts up to 255, the CAN bus is shut down. When the active error counter reaches 96 or is larger than 96, when warning is generated, the communication mode of the master machine and the slave machine is changed into a slave mode, when the master machine sends a data request, the slave machine sends a data response, otherwise, the slave machine works in the master mode.
In some embodiments, the slave itself operates in a special master mode, and only the register frame is sent, and the master mode or the slave mode can be entered only after the slave completes its own mode setting after receiving the data frame sent by the master for setting the slave mode.
According to the embodiment of the disclosure, each slave machine sends the data of the active error counter or the passive error counter to the master machine, the master machine determines the mode of each slave machine according to the data of the error counter, sends the data to the CAN bus, and sets the mode of each slave machine according to the relation between the data of the error counter and the set threshold value, so that the master machine and the plurality of slave machines CAN carry out normal communication in different modes.
In S205, each slave actively enters a corresponding mode according to the mode set by the master.
In some embodiments, the slave in master mode may actively send data on its own; in the slave mode, the slave needs to receive a data request from the master to send data to the master.
In some embodiments, the method further comprises: if the host judges that the communication is finished, the host sends a command to each slave on the CAN bus, and each slave receives the command sent by the host and stops sending data;
if the host judges that the communication is abnormal, the communication link is disconnected, the state of the CAN bus is checked, and the link is reestablished.
In some embodiments, when the CAN bus communication is abnormal, some nodes enter bus-off or restart, or due to the host, the host cannot receive data for a plurality of periods, and the host judges the communication is abnormal and disconnects the communication link.
At this time, the slave node in the master mode does not know that the master is disconnected from the link communication, and therefore, the normal data frame is still transmitted, but the master is not processed any more. Therefore, at this time, the master needs to actively send an inquiry frame to the slave to inquire information such as the CAN bus error count and the running period number, if the slave CAN respond and the state is correct, it indicates that the slave has no problem, and the master needs to actively enter a data receiving state. If the slave does not answer, the slave is in failure, and the host application software needs to enter a corresponding state for processing.
According to the embodiment of the disclosure, when the host considers that the data communication is finished, the host sends the command to the slave, and the slave stops sending the data after receiving the command, so that the normal chain breakage of the communication between the host and the slave is ensured; when the communication link between the host and the slave is disconnected due to abnormal CAN bus communication, the host CAN send an inquiry frame to the slave to inquire information such as error counter data, operation period and the like, and the host judges the state of the slave according to the response condition of the slave so as to timely maintain the link under the condition that the communication link is abnormally disconnected.
The above is a description of embodiments of the method, and the embodiments of the apparatus are further described below.
Fig. 3 shows a block diagram of a CAN bus communication device according to an embodiment of the disclosure.
As shown in fig. 3, the CAN bus communication apparatus 300 includes:
a link establishing unit 301, configured to establish a communication link between the master and the slave;
a period synchronization frame sending unit 302, configured to send a period synchronization frame to each slave on the CAN bus by the master;
a master-slave synchronization unit 303, configured to receive the periodic synchronization frame sent by the host from each slave, and send data of an active error counter or a passive error counter to the host;
a mode setting unit 304, configured to determine a mode of each slave by the master according to error counter data sent by each slave, and perform mode setting on each slave;
and the working unit 305 is used for enabling each slave to actively enter a corresponding mode according to the mode set by the master.
In some embodiments, the system further includes a normal link disconnection unit, configured to, if the master determines that communication is completed, send a command to each slave on the CAN bus by the master, and each slave receives the command sent by the master and stops data transmission;
in some embodiments, the system further includes a link maintenance unit, configured to disconnect the communication link, perform CAN bus status check, and reestablish the link if the host determines that the communication is abnormal.
It is noted that while for simplicity of explanation, the foregoing method embodiments have been described as a series of acts or combination of acts, it will be appreciated by those skilled in the art that the present disclosure is not limited by the order of acts, as some steps may, in accordance with the present disclosure, occur in other orders and concurrently. Further, those skilled in the art should also appreciate that the embodiments described in the specification are exemplary embodiments and that acts and modules referred to are not necessarily required by the disclosure.
It can be clearly understood by those skilled in the art that, for convenience and simplicity of description, the specific working process of the described module may refer to the corresponding process in the foregoing method embodiment, and details are not described herein again.
According to an embodiment of the present disclosure, the present disclosure also provides an electronic device.
FIG. 4 illustrates a block diagram of an exemplary electronic device capable of implementing embodiments of the present disclosure. Electronic devices are intended to represent various forms of digital computers, such as laptops, desktops, workstations, personal digital assistants, servers, blade servers, mainframes, and other appropriate computers. The electronic device may also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions, are meant to be examples only, and are not meant to limit implementations of the disclosure described and/or claimed herein.
The device 400 comprises a computing unit 401 which may perform various suitable actions and processes in accordance with a computer program stored in a Read Only Memory (ROM) 402 or a computer program loaded from a storage unit 408 into a Random Access Memory (RAM) 403. In the RAM 403, various programs and data required for the operation of the device 400 can also be stored. The calculation unit 401, the ROM 402, and the RAM 403 are connected to each other via a bus 404. An input/output (I/O) interface 405 is also connected to bus 404.
A number of components in device 400 are connected to I/O interface 405, including: an input unit 406 such as a keyboard, a mouse, or the like; an output unit 407 such as various types of displays, speakers, and the like; a storage unit 408 such as a magnetic disk, optical disk, or the like; and a communication unit 409 such as a network card, modem, wireless communication transceiver, etc. The communication unit 409 allows the device 400 to exchange information/data with other devices via a computer network, such as the internet, and/or various telecommunication networks.
Various implementations of the systems and techniques described here above may be implemented in digital electronic circuitry, integrated circuitry, field Programmable Gate Arrays (FPGAs), application Specific Integrated Circuits (ASICs), application Specific Standard Products (ASSPs), system on a chip (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and/or combinations thereof. These various embodiments may include: implemented in one or more computer programs that are executable and/or interpretable on a programmable system including at least one programmable processor, which may be special or general purpose, receiving data and instructions from, and transmitting data and instructions to, a storage system, at least one input device, and at least one output device.
Program code for implementing the methods of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general purpose computer, special purpose computer, or other programmable data processing apparatus, such that the program codes, when executed by the processor or controller, cause the functions/operations specified in the flowchart and/or block diagram to be performed. The program code may execute entirely on the machine, partly on the machine, as a stand-alone software package partly on the machine and partly on a remote machine or entirely on the remote machine or server.
In the context of this disclosure, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
To provide for interaction with a user, the systems and techniques described here can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to a user; and a keyboard and a pointing device (e.g., a mouse or a trackball) by which a user may provide input to the computer. Other kinds of devices may also be used to provide for interaction with a user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form, including acoustic, speech, or tactile input.
The systems and techniques described here can be implemented in a computing system that includes a back-end component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front-end component (e.g., a user computer having a graphical user interface or a web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such back-end, middleware, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: local Area Networks (LANs), wide Area Networks (WANs), and the Internet.
The computer system may include clients and servers. A client and server are generally remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other. The server may be a cloud server, a server of a distributed system, or a server with a combined blockchain.
It should be understood that various forms of the flows shown above may be used, with steps reordered, added, or deleted. For example, the steps described in the present disclosure may be executed in parallel or sequentially or in different orders, and are not limited herein as long as the desired results of the technical solutions of the present disclosure can be achieved.
The above detailed description should not be construed as limiting the scope of the disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may be made in accordance with design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present disclosure should be included in the scope of protection of the present disclosure.
Claims (10)
1. A CAN bus communication method, the method comprising:
the method comprises the steps that a communication link is established between a host and a slave;
the master machine sends a periodic synchronization frame to each slave machine on the CAN bus;
each slave machine receives the periodic synchronization frame sent by the host machine and sends data of an active error counter or a passive error counter to the host machine;
the master machine determines the mode of each slave machine according to the error counter data sent by each slave machine and sets the mode of each slave machine;
and each slave computer actively enters a corresponding mode according to the mode set by the master computer.
2. The CAN bus communication method of claim 1, wherein establishing the communication link between the master and the slave comprises:
after the slave computer is electrified and normally operates, if the control command of the host computer is not received, the CAN node is directly driven to enter a master mode, and a registration frame is actively sent to the host computer and waits for the response of the host computer;
after the host is powered on and normally operates, if the register frame of any slave machine is not received, the broadcast frame is actively initiated, each slave machine is required to send the register frame, and each slave machine is waited to be successfully registered.
3. The CAN-bus communication method of claim 1, wherein the sending of the cycle synchronization frame by the master to each slave on the CAN-bus comprises:
and the master machine sends a periodic synchronization frame to each slave machine on the CAN bus in a broadcast frame mode so that the slave machines are synchronized with the master machine after receiving the periodic synchronization frame.
4. The CAN bus communication method of claim 1, wherein the receiving of the periodic synchronization frame from the master and the sending of the data of the active or passive error counter to the master by each slave comprises:
and each slave receives the periodic synchronous frame sent by the host, calculates time deviation, and sends the time deviation and error counter data to the host if the time deviation between the operating period of the slave and the periodic synchronous frame sent by the host exceeds a threshold value.
5. The CAN bus communication method of claim 1, wherein the master determines the mode of each slave according to the error counter data sent by each slave, and performing the mode setting for each slave comprises:
under normal conditions, the CAN bus is in an active error state, and when an error frame is received, the active error counter accumulates corresponding numerical values according to error types;
if the value of the active error counter is smaller than a first threshold value, the slave mode is the master mode, otherwise, the slave mode is changed into the slave mode;
in the slave mode, if the value of the active error counter is smaller than a second threshold value, the CAN bus is in an active error state, otherwise, the CAN bus is changed into a passive error state;
in the passive error state, if the value of the passive error counter is smaller than a third threshold value, the passive error counter continues to accumulate the corresponding value, otherwise, the CAN bus is closed.
6. The CAN bus communication method of claim 1, further comprising:
if the host judges that the communication is finished, the host sends a command to each slave on the CAN bus, and each slave receives the command sent by the host and stops sending data;
if the host judges that the communication is abnormal, the communication link is disconnected, the state of the CAN bus is checked, and the link is reestablished.
7. A CAN bus communication apparatus, the apparatus comprising:
the link establishing unit is used for establishing a communication link between the host and the slave;
the system comprises a period synchronization frame sending unit, a CAN bus and a synchronization frame receiving unit, wherein the period synchronization frame sending unit is used for sending a period synchronization frame to each slave on the CAN bus by the host;
the master-slave synchronization unit is used for receiving the periodic synchronization frame sent by the host by each slave and sending data of an active error counter or a passive error counter to the host;
the mode setting unit is used for determining the mode of each slave machine by the master machine according to the error counter data sent by each slave machine and setting the mode of each slave machine;
and the working unit is used for enabling each slave to actively enter a corresponding mode according to the mode set by the host.
8. An electronic device, comprising:
at least one processor;
and a memory communicatively coupled to the at least one processor;
wherein the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-6.
9. A non-transitory computer readable storage medium having stored thereon computer instructions for causing the computer to perform the method of any one of claims 1-6.
10. A computer program product comprising a computer program which, when executed by a processor, implements the method according to any one of claims 1-6.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202211387508.2A CN115834282A (en) | 2022-11-07 | 2022-11-07 | CAN bus communication method, device, equipment and readable storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202211387508.2A CN115834282A (en) | 2022-11-07 | 2022-11-07 | CAN bus communication method, device, equipment and readable storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN115834282A true CN115834282A (en) | 2023-03-21 |
Family
ID=85527020
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202211387508.2A Pending CN115834282A (en) | 2022-11-07 | 2022-11-07 | CAN bus communication method, device, equipment and readable storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN115834282A (en) |
Citations (12)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US5361260A (en) * | 1991-03-22 | 1994-11-01 | Mitsubishi Denki Kabushiki Kaisha | Communication system |
CN1960242A (en) * | 2006-10-17 | 2007-05-09 | 中控科技集团有限公司 | Method, device, system for implementing clock synchronization, and distribution system |
CN106094801A (en) * | 2016-07-12 | 2016-11-09 | 四川大学 | A kind of novel CAN FD controller |
US20170230126A1 (en) * | 2015-07-08 | 2017-08-10 | Mitsubishi Electric Corporation | Network system, time master station, and time slave station |
CN107040327A (en) * | 2017-06-14 | 2017-08-11 | 深圳市华信天线技术有限公司 | Slave TDMA slot synchronous calibration method and device |
CN109728943A (en) * | 2018-12-21 | 2019-05-07 | 交控科技股份有限公司 | Fault simulator and computer interlock CAN bus communication failure test method |
CN110795369A (en) * | 2019-09-19 | 2020-02-14 | 深圳震有科技股份有限公司 | Method and terminal for realizing MIDO slave function based on GPIO pin |
CN112087241A (en) * | 2020-08-14 | 2020-12-15 | 湖州慧微电子科技有限公司 | Method for realizing single-wire communication of elevator bus button |
CN114500156A (en) * | 2022-03-18 | 2022-05-13 | 西安超越申泰信息科技有限公司 | Flexibly configurable bus type communication system and communication method |
CN114911727A (en) * | 2022-05-26 | 2022-08-16 | 上海美仁半导体有限公司 | Bus arbitration method and device, computer readable storage medium and main control chip |
CN115001618A (en) * | 2022-05-25 | 2022-09-02 | 山东泰开电力电子有限公司 | Synchronous serial time-sharing multiplexing bus method applied to high-voltage cascade equipment |
CN115065575A (en) * | 2022-07-26 | 2022-09-16 | 广州智慧城市发展研究院 | Data transmission system based on CAN bus controller and electronic equipment |
-
2022
- 2022-11-07 CN CN202211387508.2A patent/CN115834282A/en active Pending
Patent Citations (12)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US5361260A (en) * | 1991-03-22 | 1994-11-01 | Mitsubishi Denki Kabushiki Kaisha | Communication system |
CN1960242A (en) * | 2006-10-17 | 2007-05-09 | 中控科技集团有限公司 | Method, device, system for implementing clock synchronization, and distribution system |
US20170230126A1 (en) * | 2015-07-08 | 2017-08-10 | Mitsubishi Electric Corporation | Network system, time master station, and time slave station |
CN106094801A (en) * | 2016-07-12 | 2016-11-09 | 四川大学 | A kind of novel CAN FD controller |
CN107040327A (en) * | 2017-06-14 | 2017-08-11 | 深圳市华信天线技术有限公司 | Slave TDMA slot synchronous calibration method and device |
CN109728943A (en) * | 2018-12-21 | 2019-05-07 | 交控科技股份有限公司 | Fault simulator and computer interlock CAN bus communication failure test method |
CN110795369A (en) * | 2019-09-19 | 2020-02-14 | 深圳震有科技股份有限公司 | Method and terminal for realizing MIDO slave function based on GPIO pin |
CN112087241A (en) * | 2020-08-14 | 2020-12-15 | 湖州慧微电子科技有限公司 | Method for realizing single-wire communication of elevator bus button |
CN114500156A (en) * | 2022-03-18 | 2022-05-13 | 西安超越申泰信息科技有限公司 | Flexibly configurable bus type communication system and communication method |
CN115001618A (en) * | 2022-05-25 | 2022-09-02 | 山东泰开电力电子有限公司 | Synchronous serial time-sharing multiplexing bus method applied to high-voltage cascade equipment |
CN114911727A (en) * | 2022-05-26 | 2022-08-16 | 上海美仁半导体有限公司 | Bus arbitration method and device, computer readable storage medium and main control chip |
CN115065575A (en) * | 2022-07-26 | 2022-09-16 | 广州智慧城市发展研究院 | Data transmission system based on CAN bus controller and electronic equipment |
Non-Patent Citations (3)
Title |
---|
MENGTAO HUANG: ""Design of Electronic Shaft Synchronization Control System Based on EtherCAT Bus"", 《2018 CHINESE AUTOMATION CONGRESS》, 24 January 2019 (2019-01-24) * |
陈海燕: ""基于CANopen协议的主从站伺服控制研究"", 《中国优秀硕士学位论文全文数据库 信息科技辑》, 15 January 2014 (2014-01-15) * |
陈静波;胡金春;: "基于CAN总线的分布式容错系统实现", 清华大学学报(自然科学版)网络.预览, no. 07, 15 July 2009 (2009-07-15) * |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN112511456B (en) | Flow control method, apparatus, device, storage medium, and computer program product | |
CN107666415B (en) | Optimization method and device of FC-AE-1553 protocol bridge | |
WO2015184866A1 (en) | Monitoring method and device, and first monitoring unit in power source system | |
CN112653758B (en) | Method, device, equipment and medium for updating edge node | |
JP5514040B2 (en) | Operation management system, operation management method, and operation management apparatus | |
CN107277083A (en) | A kind of processing method of data interaction, apparatus and system | |
CN113630465A (en) | Message processing method, device, equipment and storage medium | |
CN107508916B (en) | Server link management method for intelligent robot | |
CN116699964A (en) | Redundant operation method and system for industrial process controller | |
CN103997436A (en) | Link maintaining method and gateway in internet of things of elevator | |
CN107317731A (en) | A kind of detection method of client and server connection state | |
CN103001787A (en) | System and method for disaster recovery backup of data processing center | |
CN111090518A (en) | Edge computing equipment control method and device and storage medium | |
US9886400B2 (en) | Communication system and communication method | |
CN104348645A (en) | Server and data transmission method of server | |
CN115834282A (en) | CAN bus communication method, device, equipment and readable storage medium | |
US9705823B2 (en) | Port status synchronization method, related device, and system | |
CN112817992B (en) | Method, apparatus, electronic device and readable storage medium for executing change task | |
CN112822039B (en) | Main and standby mode switching method for dual-machine hot standby system | |
CN108259130A (en) | The Modbus Transmission systems and method of a kind of baud rate even-odd check position adaptive | |
CN107465477A (en) | A kind of multilevel monitor method for synchronizing network time and system | |
CN113420275A (en) | Data connection processing method, related device and computer program product | |
CN105007293A (en) | Double master control network system and double writing method for service request therein | |
CN109245864B (en) | ETH-CAN communication front-end detection device based on self-feedback and error self-detection method | |
AU2022205145B2 (en) | Communication method, communication device and communication system |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |