Method, system and medium for implementing expansion module based on RS485 and CAN bus

Through the expansion module implementation method based on RS485 and CAN bus, the problems of high expansion cost, complex installation and poor compatibility of IO modules are solved, and efficient fault detection and configuration management are realized, which is suitable for a variety of master control devices.

CN119172198BActive Publication Date: 2025-02-14SHENZHEN JUST MOTION CONTROL ELECTROMECHANICS CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202411535172.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-31
Publication Date
2025-02-14
Estimated Expiration
2044-10-31

AI Technical Summary

Technical Problem

The existing IO modules are costly, complex in operation and installation, poor compatibility, and incomplete fault detection. Especially for PLC master control devices that do not support communication methods such as EtherCAT, Profibus, CClink, etc., there are major obstacles.

Method used

Provides an implementation method of expansion module based on RS485 and CAN bus. By obtaining the dial state of the dial switch, setting the station number and baud rate, generating configuration information, and analyzing the operating status and interaction information in real time, performing fault analysis and Configuration adjustment.

Benefits of technology

It realizes the reduction of expansion module costs, simplifies installation process, improves compatibility and fault detection capabilities, supports RS485 and CAN bus communication, and is suitable for a variety of master control devices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119172198B_ABST
    Figure CN119172198B_ABST
Patent Text Reader

Abstract

The embodiment of the present application provides a method, system and medium for implementing an expansion module based on RS485 and CAN bus. The method includes: obtaining the dial state of a dial switch, setting the station number and baud rate of the local RS485 or CAN bus based on the dial state, and generating configuration information; creating a task based on the configuration information, and analyzing the operating status information of the expansion module in real time; analyzing the interaction information between external main control devices based on the operating status information of the expansion module; performing fault analysis based on the comparison result between the interaction information and the set safe operating condition information to obtain fault information; adjusting the configuration information based on the fault information; the present application can conveniently and quickly view the hardware connection and configuration problems of other devices on the bus connected to it, complete the setting of the station number and baud rate by dialing, and support RS485 and CAN bus at the same time.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of bus compatible expansion, and in particular to a method, system and medium for realizing an expansion module based on RS485 and CAN bus. Background Art

[0002] At present, most of the IO modules on the market are integrated into the PLC or motion controller body, and some are made into expansion modules. These expansion modules generally use industrial bus communication to realize data interaction, and support Ethercat, Profibus, CCLink and other methods. Generally, these devices require a coupler (used to interact with the master control or PLC for data) and the corresponding IO module to realize the function of extended IO. For example, with the EtherCAT expansion module, the master control or PLC (which needs to support the EtherCAT bus protocol) interacts with the coupler for data. After the coupler receives the data from the master control, the coupler interacts with the IO module connected to it to realize data collection and control. At present, this kind of expansion of coupler + IO module requires at least one coupler to be matched with an IO module to be used, and the cost is high when fewer IO modules are required.

[0003] The existing RS485 or CAN bus IO modules only support one of the buses, and the compatibility is poor; the existing RS485 or CAN station number setting is relatively complicated, and users are required to install terminal resistors additionally, which is troublesome. Some traditional PLC master controls do not have EtherCAT, Profibus, CClink and other communication methods, and cannot be used. The installation is complicated and the fault detection is not perfect. Effective technical solutions are urgently needed for the above problems. Summary of the invention

[0004] The purpose of the embodiments of the present application is to provide a method, system and medium for implementing an expansion module based on RS485 and CAN bus, so as to solve the problems of high cost of expansion modules, complex operation and installation, poor compatibility and imperfect fault detection.

[0005] The embodiment of the present application also provides a method for implementing an expansion module based on RS485 and CAN bus, including:

[0006] Get the state of the DIP switch, set the station number and baud rate of the local RS485 or CAN bus based on the state of the DIP switch, and generate configuration information;

[0007] Create tasks based on configuration information and analyze the running status information of extension modules in real time;

[0008] Analyze the interaction information between external master control devices based on the operation status information of the expansion module;

[0009] Perform fault analysis based on the comparison result between the interactive information and the set safe operation condition information to obtain fault information;

[0010] Adjust configuration information based on the fault information.

[0011] Optionally, in the implementation method of the expansion module based on RS485 and CAN bus described in the embodiment of the present application, the dial state of the dial switch is obtained, the station number and baud rate of the local RS485 or CAN bus are set based on the dial state, and the configuration information is generated; specifically including:

[0012] Get the parameter information of the DIP switch, and obtain the DIP state of the DIP switch and the corresponding connection state;

[0013] Based on the dial state of the dial switch and the corresponding connection state, the station number of the local RS485 or CAN bus is matched to obtain the set dial state;

[0014] Get the current state of the DIP switch, compare the current state with the set state, and determine whether the current state is the same as the set state.

[0015] If they are the same, set the station number and baud rate of the local RS485 or CAN bus to generate configuration information;

[0016] If they are not the same, turn the DIP switch to adjust the current DIP state of the DIP switch.

[0017] Optionally, in the implementation method of the expansion module based on RS485 and CAN bus described in the embodiment of the present application, it also includes:

[0018] Obtain RS485 or CAN bus operating status information and establish status detection tasks;

[0019] Analyze the RS485 or CAN bus operation status based on the status detection task to see if it is faulty;

[0020] If there is a fault, RS485 or CAN bus fault information will be generated, and LED tasks will be generated based on the RS485 or CAN bus fault information;

[0021] If there is no fault, analyzing whether the RS485 or CAN bus is connected to the external main control device, if no connection is established, generating no connection information, generating a first display mode according to the no connection information, and performing LED display based on the first display mode;

[0022] If the connection is established, connection information is generated, and the connection information is sent to the expansion module to generate a second display mode, and LED display is performed according to the second display mode.

[0023] Optionally, in the RS485 and CAN bus based expansion module implementation method described in the embodiment of the present application, fault analysis is performed according to the comparison result between the interaction information and the set safe operation condition information to obtain fault information, specifically including:

[0024] Acquire interaction information, and generate LED display status information of the extension module based on the interaction information;

[0025] Analyze the LED display color and flashing frequency based on the LED display status information of the expansion module;

[0026] Analyze whether the LED display color and flashing frequency meet the set safe operating conditions;

[0027] If satisfied, it is judged that the operation is normal;

[0028] If not, analyze whether the voltage change information of the external main control device is consistent with the baud rate voltage change of the local device;

[0029] If they are consistent, the LED is judged to be faulty;

[0030] If they are inconsistent, abnormal information is generated, and fault information is generated based on the abnormal information.

[0031] Optionally, in the implementation method of the expansion module based on RS485 and CAN bus described in the embodiment of the present application, it also includes:

[0032] Obtain RS485, CAN bus and external master control device communication protocols;

[0033] Determine whether the communication protocol meets the set communication condition information;

[0034] If the set communication condition information is not met, analyzing the compatibility difference information between the communication protocol and the set communication condition information, and adjusting the communication protocol based on the compatibility difference information;

[0035] If the set communication condition information is met, the Modbus protocol, CANOpen protocol and free communication protocol are generated.

[0036] Optionally, in the implementation method of the expansion module based on RS485 and CAN bus described in the embodiment of the present application, it also includes:

[0037] Obtaining the baud rate of the CAN bus, and identifying the state information of the CAN bus based on the baud rate of the CAN bus, wherein the state information of the CAN bus includes the interval width, amplitude, and number of data sampling points;

[0038] Analyze whether the baud rate of the CAN bus is consistent with the set baud rate based on the status information of the CAN bus;

[0039] If they are consistent, it is determined that the CAN bus baud rate meets the requirements;

[0040] If there is any inconsistency, a fault code is generated, and the fault code is compared with the standard fault code to generate fault type information.

[0041] In a second aspect, an embodiment of the present application provides an expansion module implementation system based on RS485 and CAN bus, the system comprising: a memory and a processor, the memory comprising a program for implementing an expansion module based on RS485 and CAN bus, and the program for implementing an expansion module based on RS485 and CAN bus is executed by the processor to implement the following steps:

[0042] Get the state of the DIP switch, set the station number and baud rate of the local RS485 or CAN bus based on the state of the DIP switch, and generate configuration information;

[0043] Create tasks based on configuration information and analyze the running status information of extension modules in real time;

[0044] Analyze the interaction information between external master control devices based on the operation status information of the expansion module;

[0045] Perform fault analysis based on the comparison result between the interactive information and the set safe operation condition information to obtain fault information;

[0046] Adjust configuration information based on the fault information.

[0047] Optionally, in the RS485 and CAN bus based expansion module implementation system described in the embodiment of the present application, the dial state of the dial switch is obtained, the station number and baud rate of the local RS485 or CAN bus are set based on the dial state, and the configuration information is generated; specifically including:

[0048] Get the parameter information of the DIP switch, and obtain the DIP state of the DIP switch and the corresponding connection state;

[0049] Based on the dial state of the dial switch and the corresponding connection state, the station number of the local RS485 or CAN bus is matched to obtain the set dial state;

[0050] Get the current state of the DIP switch, compare the current state with the set state, and determine whether the current state is the same as the set state.

[0051] If they are the same, set the station number and baud rate of the local RS485 or CAN bus to generate configuration information;

[0052] If they are not the same, turn the DIP switch to adjust the current DIP state of the DIP switch.

[0053] Optionally, in the RS485 and CAN bus-based expansion module implementation system described in the embodiment of the present application, the system further includes:

[0054] Obtain RS485 or CAN bus operating status information and establish status detection tasks;

[0055] Analyze the RS485 or CAN bus operation status based on the status detection task to see if it is faulty;

[0056] If there is a fault, RS485 or CAN bus fault information will be generated, and LED tasks will be generated based on the RS485 or CAN bus fault information;

[0057] If there is no fault, analyzing whether the RS485 or CAN bus is connected to the external main control device, if no connection is established, generating no connection information, generating a first display mode according to the no connection information, and performing LED display based on the first display mode;

[0058] If the connection is established, connection information is generated, and the connection information is sent to the expansion module to generate a second display mode, and LED display is performed according to the second display mode.

[0059] In the third aspect, an embodiment of the present application also provides a computer-readable storage medium, which includes a program for implementing a method for an expansion module based on RS485 and CAN bus. When the program for implementing a method for an expansion module based on RS485 and CAN bus is executed by a processor, the steps of the method for implementing an expansion module based on RS485 and CAN bus as described in any one of the above items are implemented.

[0060] As can be seen from the above, the embodiment of the present application provides an RS485 and CAN bus-based expansion module implementation method, system and medium, which obtains the dial state of the dial switch, sets the station number and baud rate of the local RS485 or CAN bus based on the dial state, and generates configuration information; creates tasks based on the configuration information, and analyzes the operating status information of the expansion module in real time; analyzes the interaction information between external main control devices based on the operating status information of the expansion module; performs fault analysis based on the comparison result between the interaction information and the set safe operating condition information to obtain fault information; adjusts the configuration information based on the fault information; the present application can conveniently and quickly view the hardware connection and configuration problems of other devices on the bus connected to it, completes the setting of the station number and baud rate by dialing, and supports RS485 and CAN buses at the same time. BRIEF DESCRIPTION OF THE DRAWINGS

[0061] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments of the present application will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.

[0062] Figure 1 A flowchart of a method for implementing an expansion module based on RS485 and CAN bus provided in an embodiment of the present application;

[0063] Figure 2 A flow chart of a configuration information acquisition method for an expansion module implementation method based on RS485 and CAN bus provided in an embodiment of the present application;

[0064] Figure 3 RS485 or CAN bus operating status fault analysis flow chart of the RS485 or CAN bus expansion module implementation method provided in the embodiment of the present application;

[0065] Figure 4 A schematic diagram of the connection between the expansion module and the external main control device provided in the embodiment of the present application;

[0066] Figure 5 This is a block diagram of an expansion module based on RS485 and CAN bus provided in an embodiment of the present application. DETAILED DESCRIPTION

[0067] The technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all of the embodiments. The components of the embodiments of the present application described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present application.

[0068] It should be noted that similar reference numerals and letters represent similar items in the following drawings, so once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings. At the same time, in the description of this application, the terms "first", "second", etc. are only used to distinguish the description and cannot be understood as indicating or implying relative importance.

[0069] Please refer to Figure 1 , Figure 1The following is a flow chart of an RS485 and CAN bus based expansion module implementation method in some embodiments of the present application. The RS485 and CAN bus based expansion module implementation method is used in a terminal device, and the RS485 and CAN bus based expansion module implementation method comprises the following steps:

[0070] S101, obtaining the dial state of the dial switch, setting the station number and baud rate of the local RS485 or CAN bus based on the dial state, and generating configuration information;

[0071] S102, creating a task based on the configuration information, and analyzing the running status information of the extension module in real time;

[0072] S103, analyzing the interaction information between the external main control devices based on the operation status information of the extension module;

[0073] S104, performing fault analysis based on a comparison result between the interaction information and the set safe operation condition information to obtain fault information;

[0074] S105: Adjust configuration information based on the fault information.

[0075] It should be noted that the expansion modules of RS485 and CAN bus can support both RS485 and CAN communication, and can be connected to most of the master control or PLC. The product is equipped with a dial code, which can directly set the station number and baud rate, and the terminal resistance can be directly connected by dialing, which simplifies the wiring and provides fault detection function. When the module fails or there is a problem with the communication transmission, the cause of the error can be intuitively identified through the LED light above, and the LED light can be used to determine whether the baud rate of the device connected to it matches.

[0076] Please refer to Figure 2 , Figure 2 This is a flow chart of a configuration information acquisition method for an expansion module implementation method based on RS485 and CAN bus in some embodiments of the present application. According to an embodiment of the present invention, the dial state of the dial switch is obtained, and the station number and baud rate of the local RS485 or CAN bus are set based on the dial state to generate configuration information; specifically, it includes:

[0077] S201, acquiring parameter information of the dip switch, and obtaining the dip state of the dip switch and the corresponding connection state;

[0078] S202, matching the station number of the local RS485 or CAN bus based on the dial state of the dial switch and the corresponding connection state to obtain the set dial state;

[0079] S203, obtaining the current dial state of the dial switch, comparing the current dial state with the set dial state, and determining whether the current dial state is the same as the set dial state;

[0080] S204, if they are the same, then set the station number and baud rate of the local RS485 or CAN bus to generate configuration information;

[0081] S205: If they are not the same, the DIP switch is toggled to adjust the current DIP state of the DIP switch.

[0082] It should be noted that by analyzing the difference between the dial state of the dial switch and the set dial state, the dial state of the dial switch is dynamically adjusted to match the station number of the local RS485 or CAN bus, thereby realizing the configuration of the local RS485 or CAN bus.

[0083] Please refer to Figure 3 , Figure 3 It is a flow chart of RS485 or CAN bus operation status fault analysis of an expansion module implementation method based on RS485 or CAN bus in some embodiments of the present application. According to an embodiment of the present invention, it also includes:

[0084] S301, obtain RS485 or CAN bus operation status information and establish a status detection task;

[0085] S302, analyzing whether the operation status of RS485 or CAN bus is faulty based on the status detection task;

[0086] S303, if there is a fault, RS485 or CAN bus fault information will be generated, and an LED task will be generated based on the RS485 or CAN bus fault information;

[0087] S304, if there is no fault, analyzing whether the RS485 or CAN bus is connected to the external main control device, if no connection is established, generating no connection information, generating a first display mode according to the no connection information, and performing LED display based on the first display mode;

[0088] S305: If the connection is established, then generate connection information, send the connection information to the extension module to generate a second display mode, and perform LED display according to the second display mode.

[0089] It should be noted that the connection status of RS485 or CAN bus and external main control device is judged by analyzing the RS485 or CAN bus operation status information, so as to accurately analyze the LED display status and make the LED display status accurately match the connection status of RS485 or CAN bus and external main control device.

[0090] According to an embodiment of the present invention, a fault analysis is performed based on a comparison result between the interaction information and the set safe operation condition information to obtain fault information, specifically including:

[0091] Acquire interaction information, and generate LED display status information of the extension module based on the interaction information;

[0092] Analyze the LED display color and flashing frequency based on the LED display status information of the expansion module;

[0093] Analyze whether the LED display color and flashing frequency meet the set safe operating conditions;

[0094] If satisfied, it is judged that the operation is normal;

[0095] If not, analyze whether the voltage change information of the external main control device is consistent with the baud rate voltage change of the local device;

[0096] If they are consistent, the LED is judged to be faulty;

[0097] If they are inconsistent, abnormal information is generated, and fault information is generated based on the abnormal information.

[0098] It should be noted that the RS485 bus status detection is performed through the baud rate detection function of the USART inside the chip. The detection is performed by querying whether the voltage change of the peripheral is consistent with the baud rate voltage change of the device. Other faults, such as noise interference, data disorder, etc., can also be queried through voltage changes and change amplitudes to find out the causes of the faults. These fault causes are identified by reading the USART registers.

[0099] According to an embodiment of the present invention, it also includes:

[0100] Obtain RS485, CAN bus and external master control device communication protocols;

[0101] Determine whether the communication protocol meets the set communication condition information;

[0102] If the set communication condition information is not met, analyzing the compatibility difference information between the communication protocol and the set communication condition information, and adjusting the communication protocol based on the compatibility difference information;

[0103] If the set communication condition information is met, the Modbus protocol, CANOpen protocol and free communication protocol are generated.

[0104] It should be noted that the protocol stacks supported by the device include: Modbus-RTU, CANOPEN, and CAN free protocol communication. By cutting the Modbus-RTU Slave protocol stack, removing unused function codes, optimizing the underlying Usart transmission method, and using DMA+timer+Usart error detection mechanism to achieve data interaction, compared with the traditional method of using Usart interrupt to receive data, using DMA+timer+Usart error detection can greatly reduce the CPU occupancy rate, so that data reception and analysis can be completed normally regardless of the amount of data.

[0105] According to an embodiment of the present invention, it also includes:

[0106] Obtaining the baud rate of the CAN bus, and identifying the state information of the CAN bus based on the baud rate of the CAN bus, wherein the state information of the CAN bus includes the interval width, amplitude, and number of data sampling points;

[0107] Analyze whether the baud rate of the CAN bus is consistent with the set baud rate based on the status information of the CAN bus;

[0108] If they are consistent, it is determined that the CAN bus baud rate meets the requirements;

[0109] If there is any inconsistency, a fault code is generated, and the fault code is compared with the standard fault code to generate fault type information.

[0110] It should be noted that by analyzing the baud rate of the CAN bus to obtain the fault code and comparing it with the standard fault code, the fault type corresponding to the different fault codes can be accurately analyzed to improve the accuracy of fault analysis.

[0111] Please refer to Figure 5 , Figure 5 It is a block diagram of an expansion module implementation based on RS485 and CAN bus in some embodiments of the present application. In the second aspect, the embodiments of the present application provide an expansion module implementation system based on RS485 and CAN bus, the system comprising: a memory and a processor, the memory comprising a program of an expansion module implementation method based on RS485 and CAN bus, and the program of the expansion module implementation method based on RS485 and CAN bus is executed by the processor to implement the following steps:

[0112] Get the state of the DIP switch, set the station number and baud rate of the local RS485 or CAN bus based on the state of the DIP switch, and generate configuration information;

[0113] Create tasks based on configuration information and analyze the running status information of extension modules in real time;

[0114] Analyze the interaction information between external master control devices based on the operation status information of the expansion module;

[0115] Perform fault analysis based on the comparison result between the interactive information and the set safe operation condition information to obtain fault information;

[0116] Adjust configuration information based on the fault information.

[0117] It should be noted that if Figure 4 As shown in the figure, the module JIO2416 integrates communication and IO functions. It is a module used to expand digital input and output, including 24 inputs and 16 outputs, and supports RS485 communication and CAN communication. The device hardware has a dip switch to set the station number and baud rate of the device and to control the opening of the hardware terminal resistor. The device has an LED light with different colors. The color and flashing frequency of the LED light can be used to identify the operating status and faults of the device.

[0118] According to an embodiment of the present invention, the dial state of the dial switch is obtained, the station number and baud rate of the local RS485 or CAN bus are set based on the dial state, and configuration information is generated; specifically including:

[0119] Get the parameter information of the DIP switch, and obtain the DIP state of the DIP switch and the corresponding connection state;

[0120] Based on the dial state of the dial switch and the corresponding connection state, the station number of the local RS485 or CAN bus is matched to obtain the set dial state;

[0121] Get the current state of the DIP switch, compare the current state with the set state, and determine whether the current state is the same as the set state.

[0122] If they are the same, set the station number and baud rate of the local RS485 or CAN bus to generate configuration information;

[0123] If they are not the same, turn the DIP switch to adjust the current DIP state of the DIP switch.

[0124] It should be noted that by analyzing the difference between the dial state of the dial switch and the set dial state, the dial state of the dial switch is dynamically adjusted to match the station number of the local RS485 or CAN bus, thereby realizing the configuration of the local RS485 or CAN bus.

[0125] According to an embodiment of the present invention, it also includes:

[0126] Obtain RS485 or CAN bus operating status information and establish status detection tasks;

[0127] Analyze the RS485 or CAN bus operation status based on the status detection task to see if it is faulty;

[0128] If there is a fault, RS485 or CAN bus fault information will be generated, and LED tasks will be generated based on the RS485 or CAN bus fault information;

[0129] If there is no fault, analyzing whether the RS485 or CAN bus is connected to the external main control device, if no connection is established, generating no connection information, generating a first display mode according to the no connection information, and performing LED display based on the first display mode;

[0130] If the connection is established, connection information is generated, and the connection information is sent to the expansion module to generate a second display mode, and LED display is performed according to the second display mode.

[0131] It should be noted that the connection status of RS485 or CAN bus and external main control device is judged by analyzing the RS485 or CAN bus operation status information, so as to accurately analyze the LED display status and make the LED display status accurately match the connection status of RS485 or CAN bus and external main control device.

[0132] According to an embodiment of the present invention, a fault analysis is performed based on a comparison result between the interaction information and the set safe operation condition information to obtain fault information, specifically including:

[0133] Acquire interaction information, and generate LED display status information of the extension module based on the interaction information;

[0134] Analyze the LED display color and flashing frequency based on the LED display status information of the expansion module;

[0135] Analyze whether the LED display color and flashing frequency meet the set safe operating conditions;

[0136] If satisfied, it is judged that the operation is normal;

[0137] If not, analyze whether the voltage change information of the external main control device is consistent with the baud rate voltage change of the local device;

[0138] If they are consistent, the LED is judged to be faulty;

[0139] If they are inconsistent, abnormal information is generated, and fault information is generated based on the abnormal information.

[0140] It should be noted that the RS485 bus status detection is performed through the baud rate detection function of the USART inside the chip. The detection is performed by querying whether the voltage change of the peripheral is consistent with the baud rate voltage change of the device. Other faults, such as noise interference, data disorder, etc., can also be queried through voltage changes and change amplitudes to find out the causes of the faults. These fault causes are identified by reading the USART registers.

[0141] According to an embodiment of the present invention, it also includes:

[0142] Obtain RS485, CAN bus and external master control device communication protocols;

[0143] Determine whether the communication protocol meets the set communication condition information;

[0144] If the set communication condition information is not met, analyzing the compatibility difference information between the communication protocol and the set communication condition information, and adjusting the communication protocol based on the compatibility difference information;

[0145] If the set communication condition information is met, the Modbus protocol, CANOpen protocol and free communication protocol are generated.

[0146] It should be noted that the protocol stacks supported by the device include: Modbus-RTU, CANOPEN, and CAN free protocol communication. By cutting the Modbus-RTU Slave protocol stack, removing unused function codes, optimizing the underlying Usart transmission method, and using DMA+timer+Usart error detection mechanism to achieve data interaction, compared with the traditional method of using Usart interrupt to receive data, using DMA+timer+Usart error detection can greatly reduce the CPU occupancy rate, so that data reception and analysis can be completed normally regardless of the amount of data.

[0147] According to an embodiment of the present invention, it also includes:

[0148] Obtaining the baud rate of the CAN bus, and identifying the state information of the CAN bus based on the baud rate of the CAN bus, wherein the state information of the CAN bus includes the interval width, amplitude, and number of data sampling points;

[0149] Analyze whether the baud rate of the CAN bus is consistent with the set baud rate based on the status information of the CAN bus;

[0150] If they are consistent, it is determined that the CAN bus baud rate meets the requirements;

[0151] If there is any inconsistency, a fault code is generated, and the fault code is compared with the standard fault code to generate fault type information.

[0152] It should be noted that by analyzing the baud rate of the CAN bus to obtain the fault code and comparing it with the standard fault code, the fault type corresponding to the different fault codes can be accurately analyzed to improve the accuracy of fault analysis.

[0153] The third aspect of the present invention provides a computer-readable storage medium, which includes a program for implementing a method for an expansion module based on RS485 and CAN bus. When the program for implementing a method for an expansion module based on RS485 and CAN bus is executed by a processor, the steps of any of the above-mentioned methods for implementing an expansion module based on RS485 and CAN bus are implemented.

[0154] The invention discloses an RS485 and CAN bus-based expansion module implementation method, system and medium. The method obtains the dial state of a dial switch, sets the station number and baud rate of the local RS485 or CAN bus based on the dial state, and generates configuration information; creates tasks based on the configuration information, and analyzes the running state information of the expansion module in real time; analyzes the interaction information between external main control devices based on the running state information of the expansion module; performs fault analysis based on the comparison result between the interaction information and the set safe running condition information to obtain fault information; and adjusts the configuration information based on the fault information. The application can conveniently and quickly view the hardware connection and configuration problems of other devices on the bus connected thereto, completes the setting of the station number and baud rate by dialing, and supports RS485 and CAN buses at the same time.

[0155] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are only schematic. For example, the division of units is only a logical function division. There may be other division methods in actual implementation, such as: multiple units or components can be combined, or can be integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, and the indirect coupling or communication connection of devices or units can be electrical, mechanical or other forms.

[0156] The units described above as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units; they may be located in one place or distributed on multiple network units; some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.

[0157] In addition, all functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may be separately used as a unit, or two or more units may be integrated into one unit; the above-mentioned integrated units may be implemented in the form of hardware or in the form of hardware plus software functional units.

[0158] Those skilled in the art can understand that: all or part of the steps of implementing the above method embodiments can be completed by hardware related to program instructions, the aforementioned program can be stored in a readable storage medium, and when the program is executed, it executes the steps of the above method embodiments; and the aforementioned storage medium includes: mobile storage devices, read-only memories (ROM, Read-Only Memory), random access memories (RAM, Random Access Memory), disks or optical disks, and other media that can store program codes.

[0159] Alternatively, if the above-mentioned integrated unit of the present invention is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a readable storage medium. Based on this understanding, the technical solution of the embodiment of the present invention can be essentially or partly reflected in the form of a software product that contributes to the prior art. The software product is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, ROM, RAM, magnetic disks or optical disks.

Claims

1. A method for implementing an expansion module based on RS485 and CAN bus, characterized in that: include: Get the state of the DIP switch, set the station number and baud rate of the local RS485 or CAN bus based on the state of the DIP switch, and generate configuration information; Create tasks based on configuration information and analyze the running status information of extension modules in real time; Analyze the interaction information between external master control devices based on the operation status information of the expansion module; Perform fault analysis based on the comparison result between the interactive information and the set safe operation condition information to obtain fault information; Acquire interaction information, and generate LED display status information of the extension module based on the interaction information; Analyze the LED display color and flashing frequency based on the LED display status information of the expansion module; Analyze whether the LED display color and flashing frequency meet the set safe operating conditions; If satisfied, it is judged that the operation is normal; If not, analyze whether the voltage change information of the external main control device is consistent with the baud rate voltage change of the local device; If they are consistent, the LED is judged to be faulty; If they are inconsistent, abnormal information is generated, and fault information is generated based on the abnormal information; Adjust configuration information based on fault information; Obtain RS485, CAN bus and external master control device communication protocols; Determine whether the communication protocol meets the set communication condition information; If the set communication condition information is not met, analyzing the compatibility difference information between the communication protocol and the set communication condition information, and adjusting the communication protocol based on the compatibility difference information; If the set communication condition information is met, the Modbus protocol, CANOpen protocol and free communication protocol are generated; Obtaining the baud rate of the CAN bus, and identifying the state information of the CAN bus based on the baud rate of the CAN bus, wherein the state information of the CAN bus includes the interval width, amplitude, and number of data sampling points; Analyze whether the baud rate of the CAN bus is consistent with the set baud rate based on the status information of the CAN bus; If they are consistent, it is determined that the CAN bus baud rate meets the requirements; If there is any inconsistency, a fault code is generated, and the fault code is compared with the standard fault code to generate fault type information.

2. The expansion module implementation method based on RS485 and CAN bus according to claim 1, characterized in that: Get the state of the DIP switch, set the station number and baud rate of the local RS485 or CAN bus based on the DIP state, and generate configuration information; specifically including: Get the parameter information of the DIP switch, and obtain the DIP state of the DIP switch and the corresponding connection state; Based on the dial state of the dial switch and the corresponding connection state, the station number of the local RS485 or CAN bus is matched to obtain the set dial state; Get the current state of the DIP switch, compare the current state with the set state, and determine whether the current state is the same as the set state. If they are the same, set the station number and baud rate of the local RS485 or CAN bus to generate configuration information; If they are not the same, turn the DIP switch to adjust the current DIP state of the DIP switch.

3. The expansion module implementation method based on RS485 and CAN bus according to claim 2, characterized in that: Also includes: Obtain RS485 or CAN bus operating status information and establish status detection tasks; Analyze the RS485 or CAN bus operation status based on the status detection task to see if it is faulty; If there is a fault, RS485 or CAN bus fault information will be generated, and LED tasks will be generated based on the RS485 or CAN bus fault information; If there is no fault, analyzing whether the RS485 or CAN bus is connected to the external main control device, if no connection is established, generating no connection information, generating a first display mode according to the no connection information, and performing LED display based on the first display mode; If the connection is established, connection information is generated, and the connection information is sent to the expansion module to generate a second display mode, and LED display is performed according to the second display mode.

4. An expansion module implementation system based on RS485 and CAN bus, characterized in that: The system includes: a memory and a processor, wherein the memory includes a program for implementing a method for implementing an expansion module based on RS485 and a CAN bus, and when the program for implementing a method for implementing an expansion module based on RS485 and a CAN bus is executed by the processor, the following steps are implemented: Get the state of the DIP switch, set the station number and baud rate of the local RS485 or CAN bus based on the state of the DIP switch, and generate configuration information; Create tasks based on configuration information and analyze the running status information of extension modules in real time; Analyze the interaction information between external master control devices based on the operation status information of the expansion module; Perform fault analysis based on the comparison result between the interactive information and the set safe operation condition information to obtain fault information; Acquire interaction information, and generate LED display status information of the extension module based on the interaction information; Analyze the LED display color and flashing frequency based on the LED display status information of the expansion module; Analyze whether the LED display color and flashing frequency meet the set safe operating conditions; If satisfied, it is judged that the operation is normal; If not, analyze whether the voltage change information of the external main control device is consistent with the baud rate voltage change of the local device; If they are consistent, the LED is judged to be faulty; If they are inconsistent, abnormal information is generated, and fault information is generated based on the abnormal information; Adjust configuration information based on fault information; Obtain RS485, CAN bus and external master control device communication protocols; Determine whether the communication protocol meets the set communication condition information; If the set communication condition information is not met, analyzing the compatibility difference information between the communication protocol and the set communication condition information, and adjusting the communication protocol based on the compatibility difference information; If the set communication condition information is met, the Modbus protocol, CANOpen protocol and free communication protocol are generated; Obtaining the baud rate of the CAN bus, and identifying the state information of the CAN bus based on the baud rate of the CAN bus, wherein the state information of the CAN bus includes the interval width, amplitude, and number of data sampling points; Analyze whether the baud rate of the CAN bus is consistent with the set baud rate based on the status information of the CAN bus; If they are consistent, it is determined that the CAN bus baud rate meets the requirements; If there is any inconsistency, a fault code is generated, and the fault code is compared with the standard fault code to generate fault type information.

5. The expansion module realization system based on RS485 and CAN bus according to claim 4 is characterized in that: Get the state of the DIP switch, set the station number and baud rate of the local RS485 or CAN bus based on the DIP state, and generate configuration information; specifically including: Get the parameter information of the DIP switch, and obtain the DIP state of the DIP switch and the corresponding connection state; Based on the dial state of the dial switch and the corresponding connection state, the station number of the local RS485 or CAN bus is matched to obtain the set dial state; Get the current state of the DIP switch, compare the current state with the set state, and determine whether the current state is the same as the set state. If they are the same, set the station number and baud rate of the local RS485 or CAN bus to generate configuration information; If they are not the same, turn the DIP switch to adjust the current DIP state of the DIP switch.

6. The expansion module realization system based on RS485 and CAN bus according to claim 4, characterized in that: Also includes: Obtain RS485 or CAN bus operating status information and establish status detection tasks; Analyze the RS485 or CAN bus operation status based on the status detection task to see if it is faulty; If there is a fault, RS485 or CAN bus fault information will be generated, and LED tasks will be generated based on the RS485 or CAN bus fault information; If there is no fault, analyzing whether the RS485 or CAN bus is connected to the external main control device, if no connection is established, generating no connection information, generating a first display mode according to the no connection information, and performing LED display based on the first display mode; If the connection is established, connection information is generated, and the connection information is sent to the expansion module to generate a second display mode, and LED display is performed according to the second display mode.

7. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes an RS485 and CAN bus-based expansion module implementation method program. When the RS485 and CAN bus-based expansion module implementation method program is executed by a processor, the steps of the RS485 and CAN bus-based expansion module implementation method as described in any one of claims 1 to 3 are implemented.

Citation Information

Patent Citations

  • Bus expansion module of engineering machinery vehicle and bus data processing method

    CN102955437A

  • CAN baud rate automatic matching method and device, terminal and storage medium

    CN118713954A

  • Configurable I / O module with multiple bus interface

    CN1964363A