NMT interaction method based on CANOPEN
By packing NMT services in embedded application scenarios and providing interactive commands in shell, the problem of difficulty in operating NMT services in the Canopen network in the existing technology in the existing technology has improved the efficiency of node status control and network monitoring.
Patent Information
- Application Number
- CN202411470769.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-21
- Publication Date
- 2025-01-28
AI Technical Summary
In embedded application scenarios, it is difficult for the prior art to implement NMT service operations in CANopen network in SHELL, resulting in low node status control and network monitoring efficiency.
By defining the node configuration state structure Nodestate and the prompt information array of the interactive commands Help_info, package NMT services and provide interactive commands in shell to achieve operation of NMT services. Specific steps include defining structures, establishing prompt information arrays, processing command parameters, and performing corresponding operations.
The efficiency of node status control and network monitoring during the CANOPEN bus communication, and achieved effective operation of NMT services in shell.
Smart Images

Figure CN119383030A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of computer control and relates to a CANOPEN-based NMT interaction method. Background Art
[0002] CANopen is an open communication standard based on the CAN bus, used for communication between industrial automation devices. NMT (Network Management) is a service for device management in the CANopen network.
[0003] The NMT service can perform node status control. The master node can control the slave node to enter different states, such as initialization state, pre-operation state, operation state, and stop state.
[0004] NMT service can perform network monitoring. The master node can monitor the status of the slave node through NMT. If the slave node fails or the communication is abnormal, the master node can detect it in time and take corresponding measures. Summary of the invention
[0005] 1. Technical issues to be resolved
[0006] NMT service belongs to the management service in CANopen network. The present invention proposes a CANOPEN-based NMT interaction method in embedded application scenario, encapsulates NMT service based on SHELL, and realizes NMT service operation in SHELL.
[0007] (II) Technical solution
[0008] In order to solve the above technical problems, the present invention provides a CANOPEN-based NMT interaction method, which includes the following steps:
[0009] S0: defines the node configuration state structure NodeState;
[0010] S1: Create an array help_info of type const char*, which includes prompt information of interactive commands;
[0011] S2: The operation command is cmd_canopen_nmt, and the entry parameters are argc and argv;
[0012] S2_1 determines the value of agrc. If it is greater than or equal to 2, it goes to S2_2 for determination.
[0013] S2_2 obtains the data with index 1 through the secondary pointer argv, stores the obtained data in the variable operator, and uses the string comparison function strcmp to determine the value of operator. Different values perform different processing.
[0014] In step S0, the member variables of the structure NodeState include: ① node number nodeID, ② node name name, ③ node state, the node state includes initialization state Initialisation, disconnected state Disconnected, connected state Connecting, preparing state Preparing, stopped state Stopped, operational state Operational, pre-operational state Pre_operational, and unknown state Unknown_state.
[0015] In step S0, for a one-master-two-slave motor system, a 3-element array is defined, in which the variable is the structure NodeState, the master node number is 0, the node name is "Master", and the initial node state is Unknown_state; the slave 1 node number is 1, the node name is "Line", and the node state is Unknown_state; the slave 2 node number is 2, the node name is "Turn", and the node state is Unknown_state.
[0016] In step S1, the prompt information of the interactive command includes:
[0017] ① Print the NMT status of all nodes. The operation format is canopen_nmt list. This operation format is the standard Linux command line format;
[0018] ② Get the status of the CAN node. The operation format is canopen_nmt get[nodeID]. This operation format is the standard Linux command line format.
[0019] ③Operate the slave node NMT instruction, the operation format is canopen_nmt s[operational] <nodeid>, this operation format is the standard Linux command line format;
[0020] ④Operate the master node NMT instruction, the operation format is canopen_nmt m[operational] <nodeid>,,This operation format is the standard Linux command line format.
[0021] In step S2, the type of argc is unsigned byte type.
[0022] In step S2_1, if the value of agrc is less than 2, the parameter input is incorrect. Use the rt_kprintf function in the shell to print the operation format prompt information in step S1.
[0023] In step S2_2, if the operar value is list, the rt_kprintf function is used to print all node states.
[0024] In step S2_2, if the operator value is get, continue to determine the value of agrc;
[0025] If the value of argc is less than or equal to 2, the rt_kprintf function is used to print a prompt that the command is used incorrectly.
[0026] If the value of argc is greater than 2 at this time, the string-to-integer function is used to convert the character with subscript 2 of the secondary pointer argv into integer data and store it in the variable nodeID. The nodeID node name, node number, and node status are printed using the rt_kprintf function.
[0027] In step S2_2, if the value of operator is s, a setting operation is performed on the slave NMT;
[0028] If the value of argc is less than or equal to 3, the rt_kprintf function is used to print a prompt that the command is used incorrectly.
[0029] If the value of argc is greater than 3 at this time, the data with subscript 2 is obtained through the secondary pointer argv, and the obtained data is stored in the variable operator; the string comparison function strcmp is used to determine the value of operator;
[0030] If the value of Operator is start, the switch state is the start node NMT_Start_Node;
[0031] If the value of Operator is stop, the switch state is NMT_Stop_Node;
[0032] If the value of Operator is pre, the switching state is to enter the pre-operational mode NMT_Enter_PreOperational;
[0033] If the value of Operator is rn, the switching state is reset node NMT_Reset_Node;
[0034] If the value of Operator is rc, the switching state is reset communication NMT_Reset_Comunication;
[0035] S2_53 converts the character at the subscript 3 of the secondary pointer argv into integer data and stores it in the variable nodeID
[0036] S2_54 uses the CANOPEN standard slave state switching function masterSendNMTstateChange to switch based on the node number nodeID and Operator.
[0037] In step S2_2, if the value of operator is m, the NMT setting operation is performed on the master station;
[0038] If the value of argc is less than or equal to 2, the rt_kprintf function is used to print a prompt that the command is used incorrectly.
[0039] If the value of argc is greater than 2, the data with subscript 2 is obtained through the secondary pointer argv, and the obtained data is stored in the variable operator; the string comparison function strcmp is used to determine the value of operator;
[0040] Define the master operation mode variable newState,
[0041] If the value of Operator is start, the value of newState is the operational state Operational;
[0042] If the value of Operator is stop, the value of newState is Stopped;
[0043] If the value of Operator is pre, the value of newState is the pre-operational state Pre_operational;
[0044] Use the master state setting function setState to set the master state to the state stored in newState.
[0045] (III) Beneficial effects
[0046] The CANOPEN-based NMT interaction method provided by the above technical solution realizes NMT service in SHELL by encapsulating NMT service, thereby improving the node status control and network monitoring efficiency during CANopen bus communication. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] Figure 1 This is a flow chart of the NMT interaction method based on CANOPEN of the present invention. DETAILED DESCRIPTION
[0048] In order to make the purpose, content and advantages of the present invention more clear, the specific implementation methods of the present invention are further described in detail below in conjunction with the drawings and examples.
[0049] Reference Figure 1 As shown, the NMT interaction method based on CANOPEN in this embodiment includes the following steps:
[0050] S0: Define the node configuration state structure NodeState
[0051] The member variables of the structure NodeState include: ① node number nodeID, ② node name name, ③ node status. The node status includes initialization status Initialisation, disconnected status Disconnected, connected status Connecting, preparing status Preparing, stopped status Stopped, operational status Operational, pre-operational status Pre_operational, and unknown status Unknown_state.
[0052] For a one-master-two-slave motor system, define a 3-element array, in which the variable is the structure NodeState. For example, the master node number is 0, the node name is "Master", and the initial node state is Unknown_state; the slave 1 node number is 1, the node name is "Line", and the node state is Unknown_state; the slave 2 node number is 2, the node name is "Turn", and the node state is Unknown_state.
[0053] S1: Create an array help_info of type const char*, which includes prompt information of interactive commands.
[0054] The prompt information of the interactive command includes:
[0055] ① Print the NMT status of all nodes. The operation format can be canopen_nmt list. This operation format is the standard Linux command line format.
[0056] ② Get the status of the CAN node. The operation format can be canopen_nmt get[nodeID]. This operation format is the standard Linux command line format.
[0057] ③Operate the slave node NMT instruction, the operation format is canopen_nmt s[operational] <nodeid>, this operation format is the standard Linux command line format.
[0058] ④Operate the master node NMT instruction, the operation format is canopen_nmt m[operational] <nodeid>,,This operation format is the standard Linux command line format.
[0059] S2: The operation command is cmd_canopen_nmt, the input parameters are argc and argv, and the argc type is unsigned byte type.
[0060] S2_1 determines the value of agrc.
[0061] If it is less than 2, the parameter input is incorrect. Use the rt_kprintf function in the shell to print the operation format prompt information in step S1.
[0062] If it is greater than or equal to 2, go to S2_2 for judgment.
[0063] S2_2 obtains the data with index 1 through the secondary pointer argv, stores the obtained data in the variable operator, and uses the string comparison function strcmp to determine the value of operator.
[0064] S2_3 If the operator value is list, use the rt_kprintf function to print all node states.
[0065] S2_4 If the operator value is get, continue to determine the value of agrc.
[0066] If the value of argc is less than or equal to 2, the rt_kprintf function is used to print a prompt indicating that the command was used incorrectly.
[0067] If the value of argc is greater than 2 at this time, the string-to-integer function is used to convert the character with subscript 2 of the secondary pointer argv into integer data and store it in the variable nodeID. The nodeID node name, node number, and node status are printed using the rt_kprintf function.
[0068] S2_5 If the value of operator is s, the slave NMT is set.
[0069] S2_51 If the value of argc is less than or equal to 3 at this time, use the rt_kprintf function to print a prompt that the command is used incorrectly.
[0070] S2_52 If the value of argc is greater than 3 at this time, the data with subscript 2 is obtained through the secondary pointer argv, and the obtained data is stored in the variable operator. The string comparison function strcmp is used to determine the value of operator.
[0071] If the value of Operator is start, the switch state is NMT_Start_Node (start node);
[0072] If the value of Operator is stop, the switch state is NMT_Stop_Node (stop node);
[0073] If the value of Operator is pre, the switching state is NMT_Enter_PreOperational (entering pre-operation mode);
[0074] If the value of Operator is rn, the switching state is NMT_Reset_Node (reset node);
[0075] If the value of Operator is rc, the switching state is NMT_Reset_Communication (reset communication);
[0076] S2_53 converts the character at the subscript 3 of the secondary pointer argv into integer data and stores it in the variable nodeID
[0077] S2_54 uses the CANOPEN standard slave state switching function masterSendNMTstateChange to switch with the node number nodeID and Operator. S2_6 If the value of operator is m, perform NMT setting operation on the master station.
[0078] S2_61 If the value of argc is less than or equal to 2 at this time, use the rt_kprintf function to print a prompt that the command is used incorrectly.
[0079] S2_62 If the value of argc is greater than 2, the data with subscript 2 is obtained through the secondary pointer argv and stored in the variable operator. The string comparison function strcmp is used to determine the value of operator.
[0080] Define the master operation mode variable newState,
[0081] If the value of Operator is start, the value of newState is Operational (operational state);
[0082] If the value of Operator is stop, the value of newState is Stopped (stopped state);
[0083] If the value of Operator is pre, the value of newState is Pre_operational (pre-operational state).
[0084] S2_63 uses the master state setting function setState to set the master state to the state stored in newState.
[0085] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the technical principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.< / nodeid> < / nodeid> < / nodeid> < / nodeid>
Claims
1. A CANOPEN-based NMT interaction method, characterized in that: The following steps are involved: S0: defines the node configuration state structure NodeState; S1: Create an array help_info of type const char*, which includes prompt information of interactive commands; S2: The operation command is cmd_canopen_nmt, and the entry parameters are argc and argv; S2_1 determines the value of agrc. If it is greater than or equal to 2, it goes to S2_2 for determination. S2_2 obtains the data with index 1 through the secondary pointer argv, stores the obtained data in the variable operator, and uses the string comparison function strcmp to determine the value of operator. Different values perform different processing.
2. The CANOPEN-based NMT interaction method according to claim 1, characterized in that: In step S0, the member variables of the structure NodeState include: ① node number nodeID, ② node name name, ③ node state, the node state includes initialization state Initialisation, disconnected state Disconnected, connected state Connecting, preparing state Preparing, stopped state Stopped, operational state Operational, pre-operational state Pre_operational, and unknown state Unknown_state.
3. The CANOPEN-based NMT interaction method according to claim 2, characterized in that: In step S0, for a one-master-two-slave motor system, a 3-element array is defined, in which the variable is the structure NodeState, the master node number is 0, the node name is "Master", and the initial node state is Unknown_state; the slave 1 node number is 1, the node name is "Line", and the node state is Unknown_state; the slave 2 node number is 2, the node name is "Turn", and the node state is Unknown_state.
4. The CANOPEN-based NMT interaction method according to claim 2, characterized in that: In step S1, the prompt information of the interactive command includes: ① Print the NMT status of all nodes. The operation format is canopen_nmt list. This operation format is the standard Linux command line format; ② Get the status of the CAN node. The operation format is canopen_nmt get[nodeID]. This operation format is the standard Linux command line format. ③Operate the slave node NMT instruction, the operation format is canopen_nmt s[operational] <nodeid> , this operation format is the standard Linux command line format;< / nodeid> ④Operate the master node NMT instruction, the operation format is canopen_nmt m[operational] <nodeid> ,,This operation format is the standard Linux command line format.< / nodeid> 5. The CANOPEN-based NMT interaction method according to claim 4, characterized in that: In step S2, the type of argc is unsigned byte type.
6. The CANOPEN-based NMT interaction method according to claim 5, characterized in that: In step S2_1, if the value of agrc is less than 2, the parameter input is incorrect. Use the rt_kprintf function in the shell to print the operation format prompt information in step S1.
7. The CANOPEN-based NMT interaction method according to claim 6, characterized in that: In step S2_2, if the operar value is list, the rt_kprintf function is used to print all node states.
8. The CANOPEN-based NMT interaction method according to claim 7, characterized in that: In step S2_2, if the operator value is get, continue to determine the value of agrc; If the value of argc is less than or equal to 2, the rt_kprintf function is used to print a prompt that the command is used incorrectly. If the value of argc is greater than 2 at this time, the string-to-integer function is used to convert the character with subscript 2 of the secondary pointer argv into integer data and store it in the variable nodeID. The nodeID node name, node number, and node status are printed using the rt_kprintf function.
9. The CANOPEN-based NMT interaction method according to claim 8, characterized in that: In step S2_2, if the value of operator is s, a setting operation is performed on the slave NMT; If the value of argc is less than or equal to 3, the rt_kprintf function is used to print a prompt that the command is used incorrectly. If the value of argc is greater than 3 at this time, the data with subscript 2 is obtained through the secondary pointer argv, and the obtained data is stored in the variable operator; the string comparison function strcmp is used to determine the value of operator; If the value of Operator is start, the switch state is the start node NMT_Start_Node; If the value of Operator is stop, the switch state is NMT_Stop_Node; If the value of Operator is pre, the switching state is to enter the pre-operational mode NMT_Enter_PreOperational; If the value of Operator is rn, the switching state is reset node NMT_Reset_Node; If the value of Operator is rc, the switching state is reset communication NMT_Reset_Comunication; S2_53 converts the character at the subscript 3 of the secondary pointer argv into integer data and stores it in the variable nodeID S2_54 uses the CANOPEN standard slave state switching function masterSendNMTstateChange to switch based on the node number nodeID and Operator.
10. The CANOPEN-based NMT interaction method according to claim 9, characterized in that: In step S2_2, if the value of operator is m, the NMT setting operation is performed on the master station; If the value of argc is less than or equal to 2, the rt_kprintf function is used to print a prompt that the command is used incorrectly. If the value of argc is greater than 2, the data with subscript 2 is obtained through the secondary pointer argv, and the obtained data is stored in the variable operator; the string comparison function strcmp is used to determine the value of operator; Define the master operation mode variable newState, If the value of Operator is start, the value of newState is the operational state Operational; If the value of Operator is stop, the value of newState is Stopped; If the value of Operator is pre, the value of newState is the pre-operational state Pre_operational; Use the master state setting function setState to set the master state to the state stored in newState.