A numerical control input / output control method and system based on M-code

By parsing M-code instructions and constructing task objects, standardized management of task scheduling and control processes in CNC systems is achieved, solving the problems of high cost and low flexibility caused by PLC program dependence, and improving the maintainability and responsiveness of the system.

CN122085853APending Publication Date: 2026-05-26GUANGZHOU KEYUAN CNC TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610236087.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-02-27
Publication Date
2026-05-26

AI Technical Summary

Technical Problem

The control logic of M-code in existing CNC systems relies on PLC programs, resulting in high development and maintenance costs, insufficient responsiveness, and inability to meet the rapid response requirements of complex processes. In particular, programming is cumbersome and maintenance is difficult when input point status linkage is involved.

Method used

By acquiring and parsing M-code instructions, a task object is constructed and submitted to the task scheduling module. The control logic is then executed using the software state scheduling module, enabling configurability and adaptability of the control flow and supporting task encapsulation and standardized management.

Benefits of technology

It improves the system's maintainability, cross-device reuse capability, and overall control logic traceability, enhances task scheduling efficiency and system flexibility, and ensures the configurability and adaptability of the control process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122085853A_ABST
    Figure CN122085853A_ABST
Patent Text Reader

Abstract

This application relates to a numerical control input / output control method and system based on M-codes. The method includes acquiring M-code instructions, reading and parsing the M-code instructions to obtain parsing results; constructing task objects based on the parsing results and submitting the task objects to the execution queue of the task scheduling module; and executing corresponding control logic based on the task objects after the software state scheduling module receives the task objects. This application has the effect of improving task scheduling efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the technical field of numerical control system control, and in particular to a numerical control input / output control method and system based on M-code. Background Technology

[0002] In existing CNC systems, the control of input and output points typically relies on PLC programs, with M-codes serving only as trigger signals. The control logic itself must be embedded within the PLC program. This architecture has several limitations: firstly, PLC program development involves specific logic programming languages ​​and hardware configuration requirements, resulting in a high barrier to entry, requiring users to possess professional knowledge to complete development and debugging; secondly, once the control logic needs adjustment, the PLC program must be modified and redeployed, making it difficult to meet the rapid response requirements of today's complex and frequently changing processes.

[0003] Especially when M-codes need to be linked with the state of input points, traditional PLC architectures usually require the introduction of additional intermediate variables and program state machines, which makes programming cumbersome, maintenance difficult, and lacks centralized control over task-level execution status, scheduling order, and repeated execution.

[0004] The existing technical solutions mentioned above have the following drawbacks: the existing architecture often requires the use of complex PLC state logic, which results in high development and maintenance costs, insufficient responsiveness, and inability to meet the refined requirements for task scheduling, safety control, and anomaly handling under complex processes. Therefore, there is room for improvement. Summary of the Invention

[0005] To improve task scheduling efficiency, this application provides a numerical control input / output control method and system based on M-code.

[0006] The above-mentioned objective of this application is achieved through the following technical solution: A numerical control input / output control method based on M-code, the method comprising: Obtain M-code instructions, read and parse the M-code instructions, and obtain the parsing results; Based on the parsing results, a task object is constructed and submitted to the execution queue of the task scheduling module; After receiving the task object, the software state scheduling module executes the corresponding control logic based on the task object.

[0007] By adopting the above technical solution, and by acquiring, reading, and parsing M-code instructions, the parameter information required for control logic can be extracted in a structured manner from the source, ensuring the configurability and adaptability of the control flow, thereby solving the problems of traditional M-code instructions being rigid and having poor scalability. By constructing task objects based on the parsing results and submitting them to the task scheduling module, the encapsulation and standardized management of control tasks can be realized, thereby supporting task queuing, priority control, and centralized scheduling. By receiving and executing the control logic in the task objects through the software state scheduling module, it can be ensured that the control flow corresponding to each M-code is processed by a unified software framework, thereby improving system maintainability, cross-device reusability, and the traceability of the overall control logic.

[0008] In one example, this application can be further configured such that: the reading and parsing of the M-code instructions to obtain the parsing result specifically includes: Read the M-code instruction, identify the type of the M-code instruction, and determine whether the M-code instruction is a dynamic parameter type or a preset number type based on the type of the M-code instruction; When the M-code instruction is a dynamic parameter type, the control parameter field is extracted from the instruction text corresponding to the M-code instruction, and the control parameter field is used as the parsing result. The control parameter field includes output point parameter, shutdown point parameter, detection point parameter, timeout time parameter, repeat control parameter, and signal hold time parameter. When the M-code instruction is a preset number type, the number value in the M-code instruction is extracted, and the corresponding parameter set is searched in the preset local configuration parameter table based on the number value. The parameter set is used as the parsing result. The parameter set includes an output point list, a closing point list, detection points, and corresponding timeout times.

[0009] By adopting the above technical solutions, and by identifying the type of M-code instructions and determining whether they are dynamic parameter types or preset number types, the parsing path can be selected according to different control requirements, thereby achieving unified compatibility with complex and standardized instructions. By extracting control parameter fields from instructions of dynamic parameter types, the control flow can dynamically adapt parameters during CNC execution, thereby improving flexibility and customization capabilities. By mapping parameters to instructions of preset number types, control tasks can be quickly constructed using existing configuration libraries, thereby reducing configuration costs and improving operating efficiency.

[0010] In one example, this application can be further configured such that: the construction of the task object based on the parsing result specifically includes: Write the parsing result into the attribute field of the task object and generate a task number; In the task object, a target state corresponding to the parsing result is set respectively. The target state includes an output control field, an input detection field, a repetition control field, an exception handling field, and a scheduling priority field. The task object is submitted to the queue of tasks to be executed in the task scheduling module, and waits to be scheduled and executed in sequence.

[0011] By adopting the above technical solution, and writing the parsing results into the attribute fields of the task object to generate a task number, it is possible to achieve unique identification and status management of the task, thereby supporting task tracking, recording, and debugging. By setting output control fields, input detection fields, repetition control fields, exception handling fields, and scheduling priority fields, each key process controlling task execution can be parameterized, thereby supporting flexible task execution paths, branching strategies, and exception response mechanisms. By submitting to the pending execution queue in the task scheduling module, it is possible to ensure that multiple tasks are queued and prioritized according to rules, thereby improving execution efficiency and the orderliness of system response.

[0012] In one example, this application can be further configured such that: the execution of corresponding control logic based on the task object specifically includes: The task object is obtained from the queue to be executed, and the task execution order is determined according to the scheduling priority field in the task object; Based on the output control field in the task object, control the corresponding physical output point to enter the target state; After completing the output control, the corresponding input point is periodically detected within a set timeout period according to the input detection field in the task object to obtain the detection result; If the detection result meets the signal conditions, the output point is closed according to the closing point parameters, and the execution flow of the current task ends. If the detection result does not meet the signal condition, but meets the repeated control trigger condition, the output point is re-controlled according to the repeated control field and the repeated detection process is started.

[0013] By adopting the above technical solutions, the task execution order can be determined based on the scheduling priority field in the task object, and the scheduling process can be controlled according to the importance or real-time nature of the task, thereby improving the system resource utilization efficiency and avoiding critical control lags. By controlling the corresponding physical output point to enter the target state, the M-code control intent can be executed accurately, thereby ensuring the accuracy of process actions. By periodically detecting the input point within a set timeout period, the execution feedback signal status can be grasped in real time, thereby responding to execution anomalies in a timely manner and entering the next logical branch. By performing a shutdown operation on tasks that meet the signal conditions, the control action can be accurately terminated, thereby ensuring the integrity and reliability of the action. By starting a repeat detection process based on the repeat control field when the detection fails, fault-tolerant control can be performed on occasional failures, thereby reducing the probability of false stops or false alarms.

[0014] In one example, this application can be further configured such that: the M-code-based numerical control input / output control method further includes: The output control field also includes feedback point configuration, and after the output control is completed, the state change of the feedback point is read. If the state change of the feedback point indicates that the feedback point has not reached the target state within the set time, an alarm warning event is triggered.

[0015] By adopting the above technical solution, by configuring feedback points in the output control field and reading the feedback status after the output control is completed, the output action result can be actively confirmed, thereby constructing a closed-loop control of the output action; by triggering an alarm warning event when no change in feedback status is detected within a set time, the system or operator can be quickly notified in case of fault or failure to execute, thereby improving the safety and response speed of the CNC system and avoiding equipment misoperation or safety accidents.

[0016] In one example, this application can be further configured as follows: if the detection result does not meet the signal condition but meets the repeat control trigger condition, the output point is re-controlled and the repeat detection process is started according to the repeat control field, specifically including: Close the current output point and record the current number of repetitions. If the number of repetitions does not reach the preset repetition control threshold, the output point will be reactivated and the detection process will be executed again after the set repetition interval time. If the signal condition is not detected when the number of repetitions reaches the preset repetition control threshold, then the alarm processing logic is executed.

[0017] By adopting the above technical solutions, recording the current number of repetitions and closing the output point when the detection result does not meet the signal conditions can provide accurate status basis for subsequent judgment and control logic, thereby ensuring the integrity of task execution. By reactivating the output point and detecting again when the number of repetitions has not reached the upper limit, a parameter-based repetition fault-tolerant strategy can be implemented, thereby improving the stability of the control process and the success rate of execution. By executing alarm processing when the expected signal state is not reached after the number of repetitions reaches the threshold, long-term abnormal execution can be effectively prevented, risky actions can be interrupted in time, thereby ensuring the safe operation of equipment and reducing human intervention costs.

[0018] In one example, this application can be further configured such that: the M-code-based numerical control input / output control method further includes: An alarm response strategy is set according to the exception handling field in the task object, and the alarm response strategy includes multiple alarm levels; When the alarm level in the set alarm strategy is the prompt level, a non-blocking prompt operation is performed. The non-blocking prompt operation includes generating prompt information and recording alarm logs without interrupting the current program flow. When the alarm level in the set alarm strategy is the interrupt level, an interrupt operation is executed. The interrupt operation includes triggering alarm output, pausing the CNC program and waiting for manual intervention or a reset signal. When the alarm level in the set alarm strategy is the linkage level, a multi-channel linkage response operation is executed. The multi-channel linkage response operation includes triggering the shutdown of multiple output points, calling a preset control subroutine, and sending alarm event information to the human-machine interface.

[0019] By adopting the above technical solutions and setting alarm response strategies based on the exception handling fields in the task objects, hierarchical management of different types of exceptions can be achieved, thereby improving the accuracy of alarm response and system resilience. By generating prompt information and recording logs under the prompt level exception without interrupting the program flow, it can be ensured that non-critical exceptions do not affect normal process operation, thereby improving the system's tolerance and production line continuity. By pausing the program and waiting for manual handling under the interruption level exception, it can prevent the intermediate process from continuing to execute and causing chain problems, thereby ensuring the safety of complex processes. By triggering the closure of multiple output points, calling subroutines, and reporting to the human-machine interface under the linkage level exception, it can quickly enter the protection state and notify the operator when a critical fault occurs, thereby building a complete automated fault linkage mechanism and improving the overall protection capability and user operability of the system.

[0020] The second objective of this invention is achieved through the following technical solution: A numerical control input / output control system based on M-code, the control system comprising: The instruction parsing module is used to acquire M-code instructions, read and parse the M-code instructions, and obtain the parsing results; The task construction module is used to construct a task object based on the parsing result and submit the task object to the execution queue of the task scheduling module; The scheduling and execution module is used to execute corresponding control logic based on the task object after the software state scheduling module receives the task object.

[0021] By adopting the above technical solution, and by acquiring, reading, and parsing M-code instructions, the parameter information required for control logic can be extracted in a structured manner from the source, ensuring the configurability and adaptability of the control flow, thereby solving the problems of traditional M-code instructions being rigid and having poor scalability. By constructing task objects based on the parsing results and submitting them to the task scheduling module, the encapsulation and standardized management of control tasks can be realized, thereby supporting task queuing, priority control, and centralized scheduling. By receiving and executing the control logic in the task objects through the software state scheduling module, it can be ensured that the control flow corresponding to each M-code is processed by a unified software framework, thereby improving system maintainability, cross-device reusability, and the traceability of the overall control logic.

[0022] In summary, this application includes the following beneficial technical effects: 1. By acquiring and reading M-code instructions, the parameter information required by the control logic can be extracted from the source in a structured manner, ensuring the configurability and adaptability of the control flow, thereby solving the problems of rigid and poor scalability of traditional M-code instructions; 2. By constructing task objects based on the parsing results and submitting them to the task scheduling module, the encapsulation and standardized management of control tasks can be realized, thereby supporting task queuing, priority control and centralized scheduling; by receiving and executing the control logic in the task object through the software state scheduling module, it can be ensured that the control flow corresponding to each M code is processed by a unified software framework, thereby improving system maintainability, cross-device reusability and traceability of overall control logic. Attached Figure Description

[0023] Figure 1 This is a flowchart of a numerical control input / output control method based on M-code in one embodiment of this application; Figure 2 This is a flowchart illustrating the implementation of step S10 in a numerical control input / output control method based on M-code in one embodiment of this application. Figure 3 This is a flowchart illustrating the implementation of step S20 in a numerical control input / output control method based on M-code in one embodiment of this application. Figure 4This is a flowchart illustrating the implementation of step S30 in a numerical control input / output control method based on M-code in one embodiment of this application. Figure 5 This is a block diagram of a numerical control input / output control system based on M-code in one embodiment of this application. Detailed Implementation

[0024] The present application will be further described in detail below with reference to the accompanying drawings.

[0025] In one embodiment, such as Figure 1 As shown, this application discloses a numerical control input / output control method based on M-code, which specifically includes the following steps: S10: Obtain M-code instructions, read and parse the M-code instructions, and obtain the parsing results.

[0026] Specifically, when the CNC system reads a line of code starting with M89 or M260-M299, it will start a dedicated parser. This parsing process does not depend on the PLC, but is directly completed by the core software of the CNC system. During the operation of the control program, the instruction parsing module is invoked to analyze and process the current M-code instruction. First, it checks whether the code line numbered M89 or M260~M299 is the currently active line according to the preset trigger rules. If a matching M-code is detected, the instruction string of that line is automatically read and the control parameter content is extracted by splitting it by spaces or identifiers. For example, when the instruction “M89I0.0K0.0J5.0Q0.0” is received, the M-code number “M89” can be extracted. The remaining code data will be split into [“I0.0”, “K0.0”, “J5.0”, “Q0.0”]. The parsing module sequentially breaks down each parameter into key-value pairs and identifies its level meaning or time unit, and finally generates a structured parsing result to support the subsequent task construction process. If a key field is missing, a parameter conflict is found, or the semantics are invalid during the parsing process, an exception feedback will be triggered and the execution of the current control logic will be stopped.

[0027] S20: Construct a task object based on the parsing results and submit the task object to the execution queue of the task scheduling module.

[0028] Specifically, immediately after the parsing result is successfully generated, an "M89 Task" or "M260 Task" object is created. This object is then initialized, with control parameters extracted from the parsing result, such as output points, detection points, timeouts, and shutdown points, written into the corresponding fields. A task number, timestamp, and identifier are assigned to the task object for subsequent scheduling identification. The task object also records the current M-code source, task validity flags, and whether interruption is allowed. The completed task object is then written into the pending task queue maintained by the task scheduling module and placed in the scheduling list according to a priority sorting mechanism for polling by the scheduler. After successful task object submission, the parsing module resources are immediately released to await the parsing of the next M-code instruction. The task queue uses a weighted priority sorting mechanism to maintain the overall scheduling order to ensure that M-code control actions do not conflict or omission.

[0029] S30: After the software state scheduling module receives the task object, it executes the corresponding control logic based on the task object.

[0030] Specifically, when a valid task object is detected in the task queue during the scheduling cycle, the task object is automatically loaded and its field content is read to start the execution process. When the M-code instruction is a dynamic parameter type, a control command is sent to the underlying hardware interface module according to the output point parameters recorded in the task to drive the target output point to enter a high-level or low-level state. At the same time, the initialization signal detection module starts to periodically poll whether the input point status has reached the preset trigger value. During the input point detection process, a timeout counter is started and the current detection time is judged in real time to see if it exceeds the limit range. While detecting a valid signal, if a shutdown point parameter is set, the output reset function is called to shut down the specified output point after successful detection to end the control process of this round. If the detection fails, the output process is restarted according to the repeated control strategy set by the task object or the alarm handling logic is entered. In this way, a complete input-output control closed loop with the task object as the carrier can be realized, and different M-code control tasks can be uniformly included in the scheduler execution framework for orderly operation.

[0031] When the M-code instruction is of a preset number type, initial output and shutdown actions are first executed according to the parameter set associated with the task object. All output points configured in the parameter table are set via the underlying driver interface, and the configured shutdown points are reset. These output and shutdown actions are completed simultaneously within the same execution cycle. After the initial actions are completed, the corresponding execution mode is automatically matched based on whether a detection point is configured in the task object and the detection time parameter. When both detection points exist and the detection time is greater than zero, a timing process corresponding to the detection time is started, and the real-time status of the detection points is continuously read during the timing process. If a signal meeting the conditions is detected before the timing ends, the execution flow of the current M-code is terminated. If no signal is detected after the end, the exception handling path is entered and the current program execution is paused. When there is a detection point but the detection time is zero or not configured, the continuous detection mode is entered and the detection point status is read in a loop until a valid signal is detected, at which point the current M code execution ends without triggering an exception. When there is no detection point but the detection time is configured and the detection time is greater than zero, a pure delay process is started and the current M code execution ends directly after the delay time is reached. At this time, the detection time parameter is used as a simple delay control parameter. When there is no detection point configured and the detection time is empty or zero, the execution flow of the current M code ends immediately after the initial output and shutdown actions are completed, thereby realizing the control logic that automatically adapts to multiple execution modes based on parameter combinations.

[0032] By adopting the above technical solution, and by acquiring, reading, and parsing M-code instructions, the parameter information required for control logic can be extracted in a structured manner from the source, ensuring the configurability and adaptability of the control flow, thereby solving the problems of traditional M-code instructions being rigid and having poor scalability. By constructing task objects based on the parsing results and submitting them to the task scheduling module, the encapsulation and standardized management of control tasks can be realized, thereby supporting task queuing, priority control, and centralized scheduling. By receiving and executing the control logic in the task objects through the software state scheduling module, it can be ensured that the control flow corresponding to each M-code is processed by a unified software framework, thereby improving system maintainability, cross-device reusability, and the traceability of the overall control logic.

[0033] In one embodiment, such as Figure 2 As shown, in step S10, the M-code instructions are read and parsed to obtain the parsing results, specifically including: S11: Read M-code instructions, identify the type of M-code instructions, and determine whether the M-code instructions are dynamic parameter types or preset number types based on the type of M-code instructions.

[0034] Specifically, after receiving the M code line from the CNC program, the instruction reading module loads the complete code text into the cache area and calls the semantic recognition function to perform lexical analysis and format parsing on the instruction structure. It determines whether the instruction belongs to the dynamic parameter type by judging whether it starts with M89. If the code starts with M260-M299, it is identified as a preset number type. After the recognition is completed, the type result is recorded and the corresponding parameter extraction path is entered to prepare for the subsequent parsing process, thereby realizing the multi-model classification logic under unified instruction input.

[0035] S12: When the M-code instruction is a dynamic parameter type, extract the control parameter field from the instruction text corresponding to the M-code instruction, and use the control parameter field as the parsing result. The control parameter field includes output point parameter, shutdown point parameter, detection point parameter, timeout parameter, repeat control parameter, and signal hold time parameter.

[0036] Specifically, upon identification as a dynamic parameter type, the original instruction text is immediately segmented and extracted character by character. Based on preset formatting rules, each parameter pair prefixed with an uppercase English letter is extracted and stored in a structured parameter table. Here, I represents the output point parameter, K the detection point parameter, Q the shutdown point parameter, J the timeout, P the number of repetitions, H the signal hold time, and R the time interval. For the code M89I0.0K0.0J5.0Q0.0, it will be split into: ["I0.0", "K0.0", "J5.0", "Q0.0"]. After extraction, a parsing result structure containing these fields is constructed and cached in the current task context for parameter calls and references in subsequent task construction logic. Simultaneously, the parser checks whether more than five I or Q parameters are used on the same line and reports an error if the limit is exceeded.

[0037] S13: When the M-code instruction is a preset number type, extract the number value from the M-code instruction, and search for the corresponding parameter set in the preset local configuration parameter table based on the number value. Then, use the parameter set as the parsing result. The parameter set includes the output point list, the closing point list, the detection point, and the corresponding timeout time.

[0038] Specifically, after determining that the M-code instruction is of the preset number type, its number value is extracted from the instruction and converted into an integer index. For example, "M261" is converted into 261 as the key index value for parameter mapping. Then, the local pre-loaded parameter mapping table is accessed and the corresponding parameter set is searched using the index value as the key. After the result is found, all the field contents of the set, such as output points Y0.0 and Y0.1, closing point Y0.2, detection point X0.0, and timeout setting of 3.0 seconds, are loaded into the current task initialization context as a complete parsing result, thereby completing the static mapping and extraction operation from the preset number to the execution parameter.

[0039] In one embodiment, such as Figure 3 As shown, in step S20, which involves constructing a task object based on the parsing results, the specific steps include: S21: Write the parsing results into the attribute fields of the task object and generate a task number.

[0040] Specifically, after parsing, the task object construction module is called to initialize the task object. The various control parameters from the parsing results are written into the corresponding attribute areas of the task object according to a field mapping method. This includes basic information such as action type, control point identifier, timing value, and detection conditions. Simultaneously, a unique number corresponding to this task is generated based on the current task generation logic timestamp and automatic numbering rules. This number can be determined by combining the current execution sequence and the M-code instruction position to achieve scheduling uniqueness. During the task object construction process, the original M-code statements are retained as additional information for subsequent debugging or tracing. After writing, the status flag of the task object is updated to "Construction Completed," ready to enter the scheduling preparation process. For example, after parsing "M89I0.0K0.0T3.0", the output point Y0.0 can be written into the output parameter field, and the detection point X0.0 and the timeout of 3.0 seconds can be written into the input detection field and timeout parameter field, ultimately generating a task object with a number such as "TASK_M89_001". After writing, the status flag of the task object is updated to "Construction Completed," ready to enter the scheduling preparation process.

[0041] S22: Set the target state corresponding to the parsing result in the task object. The target state includes output control field, input detection field, duplicate control field, exception handling field and scheduling priority field.

[0042] Specifically, the key control content extracted from the parsing results is mapped to the internal target state definition structure of the task object through a field mapping function. The target state includes an output control field describing the target behavior of the output point, an input detection field defining the input monitoring conditions and methods, a repeat control field setting whether retrying control is supported, an exception handling field indicating control flow interruption and fault-tolerant paths, and a scheduling priority field for the scheduling module's sorting judgment. During this setting process, default values ​​can be assigned to some fields to adapt to unconfigured scenarios, ensuring that the basic control logic of the task is not interrupted even when the target state is incomplete or lacks configuration. When constructing the target state structure, it is also possible to mark whether each field is enabled to support branch control during the scheduler execution phase. For example, when an M-code task only specifies the output point Y1.0 and a timeout of 5.0 seconds without setting a detection point, the input detection field can be marked as invalid but the default detection behavior logic can still be set. When constructing the target state structure, it is also possible to mark whether each field is enabled to support branch control during the scheduler execution phase.

[0043] S23: Submit the task object to the queue of tasks to be executed in the task scheduling module, and wait for it to be scheduled and executed in sequence.

[0044] Specifically, after setting the target state, the completed task object is written into the task queue list maintained by the scheduling module through the scheduling interface method. The insertion position is determined based on the priority field in the task object and the current queue state. If the queue is currently empty, the task is directly placed at the head of the queue for immediate execution. If there are multiple tasks in the queue, they are inserted into the corresponding positions according to the scheduling strategy (such as FIFO or priority first). After being written into the queue, the status label of the task object is automatically updated to "pending execution" and its enqueue time information is recorded. In the next execution cycle, the scheduling module will poll and load the task object as the scheduling target to start the control logic execution process. For example, if tasks TASK_001 and TASK_002 are already in the queue, and the newly added task TASK_003 has a higher priority value, it will be inserted at the front of the queue. In the next execution cycle, the scheduling module will poll and load the task object as the scheduling target to start the control logic execution process.

[0045] In one embodiment, such as Figure 4 As shown, in step S30, the corresponding control logic is executed based on the task object, specifically including: S31: Retrieve task objects from the queue to be executed, and determine the task execution order based on the scheduling priority field in the task object.

[0046] Specifically, when traversing the queue to be executed within the scheduling cycle, all task objects are first read and sorted according to the scheduling priority field in each task object. The higher the priority value, the earlier the task will be executed. After sorting, the highest priority task object is retrieved from the head of the queue and locked into the execution state. Subsequent task objects will continue to be kept in the queue to wait for the next round of scheduling. For example, when there are three task objects with priorities of 3, 1, and 2 in the task queue, the task with priority of 3 will be scheduled first in the current round for output control and input detection. The sorting logic can support dynamic insertion and priority adjustment mechanisms to adapt to the needs of sudden task response.

[0047] S32: Based on the output control field in the task object, control the corresponding physical output point to enter the target state.

[0048] Specifically, after reading the structure of the output control field from the task object, the target output point number and the control state value to be achieved are parsed one by one. The output instruction construction function is called to encode the instruction set into the underlying communication format and send it to the output control module of the CNC equipment through the output bus interface to drive the physical output point to enter the high or low level state. During this process, the success status of the output instruction is also recorded for subsequent feedback verification. For example, if the output points configured in the task object are Y0.0 and Y1.2 and the target state is high, the control logic will synchronously send set signals to these two output ports and mark them as "output completed" after the confirmation signal arrives. At the same time, the execution stage mark inside the task object is updated to "output completed".

[0049] After the task object is parsed and enters the control execution phase, if it is detected that the input detection field in the task object does not have configured detection point information or the detection time field is zero or default, the call to the input status reading and signal sampling module is skipped, and the output point setting operation is directly executed according to the target action defined in the output control field. At the same time, it is determined whether there is a shutdown point parameter or a delayed shutdown setting. If so, a timer is started according to the delay parameter. After the timer expires, the output reset instruction is called to shut down the specified output point. The entire process does not involve signal validity judgment and alarm response logic. For example, when the M code task only contains I0.0 output and has no K_ / T_ parameter configuration, the Y0.0 setting operation is directly executed and shut down after J_ seconds. There is no need to monitor whether the X input status is in place. This is suitable for non-safety-critical control actions that only require unidirectional drive output and do not rely on feedback confirmation.

[0050] S33: After completing the output control, periodically detect the corresponding input point within the set timeout period according to the input detection field in the task object to obtain the detection result.

[0051] Specifically, after completing the output action, the input detection field set in the task object is immediately read to determine the number of the input point to be detected and its target state requirements. At the same time, the set timeout parameter is read and the timer is started. During the entire timeout period, the target input point is read and sampled at fixed detection cycle intervals, and the original value and sampling time of each reading are recorded for subsequent judgment. For example, in a scenario where the set timeout is 3 seconds and the detection cycle is 100ms, a maximum of 30 detection polls will be performed within 3 seconds. When any of the sampling results meets the set state (such as X0.0 being high), the detection is immediately recorded as successful and the detection cycle is stopped. Otherwise, if no satisfactory signal is detected before the timeout, it is marked as "detection failure" and the process is ready to enter the subsequent processing branch.

[0052] When the signal hold time field extracted from the parsing result is not zero, the detection thread needs to confirm that the target state has not reversed within the time interval by continuous sampling. If state jitter or signal interruption occurs during continuous sampling, the hold counter is cleared and the count is restarted until the cumulative duration reaches or exceeds the set threshold for the first time before a valid detection signal output event is generated. For example, if the hold time is set to 2 seconds and the target is low level, the subsequent shutdown logic of the task will only be triggered after X0.2 holds a continuous low level for 2 seconds.

[0053] When the hold time field is defaulted or explicitly set to zero, the detection module does not enable the continuous hold judgment mechanism. When the input point reaches the target level for the first time in any sampling period, it is considered that the condition is met and immediately jumps out of the detection loop and enters the subsequent logic branch. In this mode, the response speed is faster but the anti-interference ability is relatively weak. It is suitable for working conditions with high stability or low operation safety requirements.

[0054] During task object construction, only one direction of detection level parameter is allowed to be configured as the input judgment basis. When set to high level detection mode, the detection logic only judges whether the input value is high and continuously meets the holding time requirement. When set to low level detection mode, it only judges whether the low level meets the continuous condition. High and low level detection instruction fields are not allowed to exist in the same task at the same time. If the user configuration is incorrect, a blocking prompt will be given when the task is created. This mutual exclusion strategy can effectively avoid judgment ambiguity and improve the controllability and clarity of the execution process.

[0055] S34: If the detection result meets the signal conditions, execute the output point closing operation according to the closing point parameters and end the execution flow of the current task.

[0056] Specifically, when the input detection module returns the result of "signal condition met", the shutdown point parameters configured in the task object are read, and all the output point numbers contained therein are extracted as targets to be shut down. Shutdown instructions are sent to the corresponding physical output points in sequence through the output reset interface to control them to return from a high level to a low level or interrupt state. At the same time, the output shutdown timestamp is recorded in the task object and the task status is marked as "completed". Then, the task resources are released and the task is removed from the waiting queue from the scheduler. For example, when X0.0 is detected to be high and the shutdown point in the task object is Y0.0, the reset instruction for Y0.0 is immediately executed to close the execution path, and the entire M code task flow is marked as successfully executed.

[0057] S35: If the detection result does not meet the signal condition, but meets the repeated control trigger condition, execute the re-control of the output point according to the repeated control field and start the repeated detection process.

[0058] Specifically, when the detection times out and the expected input signal is not received, the repetition control field in the task object is read and it is determined whether the current task allows repeated output attempts. If repetition control is allowed, the output point is first reset to the initial target state, and then the input detection process is restarted after the set interval waiting time, thus forming a complete "output-detection" repetition control closed loop. At the same time, the repeated count field in the task object is updated and the upper limit judgment control is performed in each loop. For example, if the task is set to allow a maximum of 2 repetitions and the repetition interval is 2 seconds, the current output is closed after the initial detection fails and the output point is reopened after 2 seconds, entering the second round of detection process, until the detection is successful or the repetition limit is reached before entering the termination process.

[0059] In one embodiment, the M-code-based numerical control input / output control method further includes: S321: The output control field also includes feedback point configuration. After the output control is completed, the state changes of the feedback points are read.

[0060] Specifically, after completing the target output point setting or resetting action specified in the output control field, the feedback signal monitoring logic is immediately invoked and the target input point number and its expected feedback state recorded in the feedback point field are parsed. Short-cycle polling or instantaneous reading is started to collect the current state value of the target input point, and the feedback point state is compared with the preset target value item by item. The result serves as an auxiliary basis for judging whether the current output action is correctly executed by the device. For example, if the output Y1.0 is the main cylinder start signal, and the feedback point is configured as X2.1 to represent the main cylinder position signal, if X2.1 immediately becomes high, it is considered that the feedback is correct. If it remains low, the subsequent timeout monitoring process is entered.

[0061] S322: If the status change of the feedback point indicates that the feedback point has not reached the target status within the set time, an alarm warning event is triggered.

[0062] Specifically, when the feedback point status is read but not immediately detected to have reached the preset target state value, a feedback timeout timer is started and a short-cycle detection mode is entered. The status of the feedback point is continuously sampled within the set maximum waiting time and it is determined whether the target state has been reached in any sampling. If no valid state change is detected after the timeout period ends, an alarm event structure is immediately constructed and written to the alarm module log. At the same time, the event broadcast mechanism is called to send a warning notification signal to the HMI interface, remote monitoring system, or upper control program. For example, the feedback point X2.1 is set to go high within 2000 milliseconds. If X2.1 remains low after the timeout, an alarm number "F201" is generated and "Main cylinder not in place in time" is displayed. The task status is marked as "Output feedback failure".

[0063] In one embodiment, in step S35, if the detection result does not meet the signal condition but meets the repetitive control trigger condition, the output point is re-controlled according to the repetitive control field and the repetitive detection process is started, specifically including: S351: Close the current output point and record the current number of repetitions.

[0064] Specifically, after the current detection process ends and it is determined that the input signal does not meet the conditions, the output point number currently in the active state is immediately read according to the output control field in the task object, and the output point is reset by issuing a shutdown command through the underlying output driver module. At the same time, the internal counter field value in the task object is incremented by one to indicate that a complete "output-detection" cycle has been completed. This counter value will be used in subsequent executions to determine whether the repetition control conditions are still met. For example, when the currently active output point is Y0.0 and two detection failure cycles have been completed, the reset action of Y0.0 is executed and the repetition counter field value of the task object is updated to "2".

[0065] S352: If the number of repetitions does not reach the preset repetition control threshold, the output point will be reactivated and the detection process will be executed again after the set repetition interval.

[0066] Specifically, after closing the current output point and updating the repetition counter, the relationship between the maximum repetition threshold set in the task object and the current counter value is determined. If the counter value has not yet reached the set upper limit, the repetition interval delay timer is started. After the timer cycle ends, the output control function is called again to set the original output point to the target state to restart the next round of detection operation. At the same time, the task object state is reset to "waiting for detection" to re-enter the input monitoring process. For example, when the M code sets P_ to the upper limit of 3 repetitions and R_ to the interval of 2 seconds, after completing the second failure loop, it will wait for 2 seconds and then reactivate the output Y0.0 and enter the third round of input signal judgment.

[0067] S353: If the signal condition is not detected when the number of repetitions reaches the preset repetition control threshold, then the alarm processing logic is executed.

[0068] Specifically, after completing the current detection round and updating the repetition count, if the repetition counter value has reached the maximum repetition threshold set in the task object, the subsequent repetition control process is immediately terminated, and the alarm processing module is called to construct an alarm event data structure. Based on the detection point fields and alarm strategy settings recorded in the task object, the corresponding alarm number and alarm description are generated and sent to the CNC main control interface or the upper-level human-machine interface through the alarm interface to complete the alarm information display. At the same time, a log file is recorded for subsequent analysis. For example, if X0.0 fails to meet the high-level condition in three consecutive detection rounds and the task is set to a maximum repetition count of 3, an alarm event code such as "A3300" is generated and the content "X0.0 signal failed to be detected three times, task aborted" is displayed.

[0069] In one embodiment, the M-code-based numerical control input / output control method further includes: S40: Set the alarm response strategy based on the exception handling field in the task object. The alarm response strategy includes multiple alarm levels.

[0070] Specifically, after the task object is constructed, the alarm policy configuration content is read from its exception handling field and the corresponding alarm level type is parsed out. An alarm response configuration structure is generated based on the alarm level and registered in the alarm control scheduling queue for invocation after an abnormal event is triggered. The alarm level can be divided into three categories: prompt level, interrupt level, and linkage level. Each level has differences in event triggering conditions, processing scope, and intervention degree. For example, when the alarm level field is set to "2" to indicate the interrupt level, the interrupt type processing logic will be triggered and subsequent CNC task execution will be suspended after a detection failure or feedback timeout event occurs.

[0071] S50: When the alarm level in the set alarm policy is the prompt level, execute a non-blocking prompt operation. The non-blocking prompt operation includes generating prompt information and recording alarm logs without interrupting the current program flow.

[0072] Specifically, when the alarm level is determined to be at the alert level, an alert-level alarm information object is immediately constructed and the message recording module is called to generate the corresponding text content to be recorded in the alarm log. At the same time, the human-machine interface interaction module is called to send an information pop-up or badge reminder to the user that there is an abnormality in the current operation, but it is not serious and does not block the current control flow, and the task will continue to be executed. For example, if no change in feedback point Y1.3 is detected after a certain output action is completed, but the task is not configured to force feedback verification, the prompt "Y1.3 has not changed, task continues" is generated and retained in the operation log without triggering interruption or linkage.

[0073] S60: When the alarm level in the set alarm strategy is the interrupt level, an interrupt operation is executed. The interrupt operation includes triggering alarm output, pausing the CNC program and waiting for manual intervention or a reset signal.

[0074] Specifically, under the premise that the interrupt-level alarm strategy is in effect, when an unmet input signal, unresponsive feedback, or abnormal output point status occurs during task execution, the alarm output command is immediately invoked to control physical devices such as alarm lights or buzzers to issue warning signals. At the same time, the CNC main program control interface is invoked to suspend the program execution logic and lock the current task status to "waiting for intervention". The suspension state is lifted and the process is allowed to resume only after the monitoring module receives a manual intervention signal or a reset signal from the upper-level command. For example, after three failed detections of the X0.2 signal, an interrupt alarm is triggered and the screen displays "Please confirm the equipment status and press the reset button".

[0075] S70: When the alarm level in the set alarm strategy is the linkage level, execute the multi-channel linkage response operation. The multi-channel linkage response operation includes triggering the shutdown of multiple output points, calling the preset control subroutine, and sending alarm event information to the human-machine interface.

[0076] Specifically, when the linkage-level alarm strategy is activated, after an abnormal event is detected, the output point reset operation is first executed in batches according to the linkage configuration list in the task object, switching all related devices to a safe state. At the same time, a series of protective actions such as power failure, hydraulic pressure relief, and cylinder retraction are executed by calling the predefined linkage control subroutine. After that, a complete alarm event structure is constructed, including alarm number, trigger source, linkage object list and suggested handling solution, and sent to the operation terminal or remote monitoring platform through the human-machine interface message push module. For example, when the detection point X3.1 cannot meet the delay condition and the task level is linkage, multiple outputs Y0.0~Y0.5 are immediately shut down and the safety subroutine named "ResetRoutine" is called to run synchronously.

[0077] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.

[0078] In one embodiment, a numerical control input / output control system based on M-code is provided, which corresponds one-to-one with the numerical control input / output control method based on M-code in the above embodiments. For example... Figure 5 As shown, this M-code-based CNC input / output control system includes an instruction parsing module, a task construction module, and a scheduling and execution module. Detailed descriptions of each functional module are as follows: The instruction parsing module is used to acquire M-code instructions, read and parse the M-code instructions, and obtain the parsing results; The task construction module is used to construct task objects based on the parsing results and submit the task objects to the execution queue of the task scheduling module; The scheduling and execution module is used to execute the corresponding control logic based on the task object after the software state scheduling module receives the task object.

[0079] Optionally, the instruction parsing module includes: The type identification submodule is used to read M-code instructions, identify the type of M-code instructions, and determine whether the M-code instruction is a dynamic parameter type or a preset number type based on the type of M-code instruction. The dynamic parameter parsing submodule is used to extract control parameter fields from the instruction text corresponding to the M code instruction when the M code instruction is of dynamic parameter type, and use the control parameter fields as the parsing result. The control parameter fields include output point parameters, shutdown point parameters, detection point parameters, timeout parameters, repeat control parameters, and signal hold time parameters. The number parameter mapping submodule is used to extract the number value in the M code instruction when the M code instruction is of the preset number type, and to look up the corresponding parameter set in the preset local configuration parameter table based on the number value, and use the parameter set as the parsing result. The parameter set includes the output point list, the close point list, the detection point and the corresponding timeout time.

[0080] Optionally, the task building modules include: The attribute writing submodule is used to write the parsed results into the attribute fields of the task object and generate a task number; The field setting submodule is used to set the target state corresponding to the parsing result in the task object. The target state includes output control field, input detection field, duplicate control field, exception handling field and scheduling priority field. The queue submission submodule is used to submit task objects to the task queue in the task scheduling module, where they will wait to be scheduled and executed in sequence.

[0081] Optionally, the scheduling execution module includes: The priority scheduling submodule is used to retrieve task objects from the queue to be executed and determine the task execution order based on the scheduling priority field in the task object; The output control submodule is used to control the corresponding physical output point to enter the target state according to the output control field in the task object; The input detection submodule is used to periodically detect the corresponding input point within a set timeout period after the output control is completed, based on the input detection field in the task object, and obtain the detection result. The condition judgment submodule is used to execute the output point closing operation according to the closing point parameters and end the execution flow of the current task if the detection result meets the signal conditions. The repeat triggering submodule is used to re-control the output point and start the repeat detection process if the detection result does not meet the signal condition but meets the repeat control trigger condition.

[0082] Optionally, this M-code-based numerical control input / output control system further includes: The feedback detection module, used for output control fields, also includes feedback point configuration. After output control is completed, the status changes of the feedback points are read. The feedback exception handling module is used to trigger an alarm warning event if the status change of the feedback point indicates that the feedback point has not reached the target status within a set time.

[0083] Optional, the repeatable trigger submodule includes: The output point shutdown unit is used to shut down the current output point and record the number of repetitions that have been executed. The repetition determination unit is used to reactivate the output point and execute the detection process again after the set repetition interval if the number of repetitions does not reach the preset repetition control threshold. The over-limit alarm unit is used to execute alarm processing logic if no signal condition is detected when the number of repetitions reaches a preset repetition control threshold.

[0084] Optionally, this M-code-based numerical control input / output control system further includes: The alarm policy parsing module is used to set alarm response policies based on the exception handling fields in the task object. The alarm response policies include multiple alarm levels. The prompt response module is used to perform non-blocking prompt operations when the alarm level in the set alarm policy is the prompt level. The non-blocking prompt operations include generating prompt information and recording alarm logs without interrupting the current program flow. The interrupt response module is used to perform an interrupt operation when the alarm level in the set alarm strategy is the interrupt level. The interrupt operation includes triggering alarm output, pausing the CNC program and waiting for manual intervention or a reset signal. The linkage response module is used to execute multi-channel linkage response operations when the alarm level in the set alarm strategy is linkage level. The multi-channel linkage response operations include triggering the shutdown of multiple output points, calling preset control subroutines, and sending alarm event information to the human-machine interface.

[0085] For specific limitations regarding the M-code-based CNC input / output control system, please refer to the limitations of the M-code-based CNC input / output control method described above, which will not be repeated here. Each module in the aforementioned M-code-based CNC input / output control system can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device, or stored in the computer device's memory as software, so that the processor can call and execute the operations corresponding to each module.

[0086] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is used as an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the system can be divided into different functional units or modules to complete all or part of the functions described above.

[0087] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.

Claims

1. A numerical control input / output control method based on M-code, characterized in that, The numerical control input / output control method based on M-code includes: Obtain M-code instructions, read and parse the M-code instructions, and obtain the parsing results; Based on the parsing results, a task object is constructed and submitted to the execution queue of the task scheduling module; After receiving the task object, the software state scheduling module executes the corresponding control logic based on the task object.

2. The numerical control input / output control method based on M-code according to claim 1, characterized in that, The process of reading and parsing the M-code instructions to obtain the parsing results specifically includes: Read the M-code instruction, identify the type of the M-code instruction, and determine whether the M-code instruction is a dynamic parameter type or a preset number type based on the type of the M-code instruction; When the M-code instruction is a dynamic parameter type, the control parameter field is extracted from the instruction text corresponding to the M-code instruction, and the control parameter field is used as the parsing result. The control parameter field includes output point parameter, shutdown point parameter, detection point parameter, timeout time parameter, repeat control parameter, and signal hold time parameter. When the M-code instruction is a preset number type, the number value in the M-code instruction is extracted, and the corresponding parameter set is searched in the preset local configuration parameter table based on the number value. The parameter set is used as the parsing result. The parameter set includes an output point list, a closing point list, detection points, and corresponding timeout times.

3. The numerical control input / output control method based on M-code according to claim 2, characterized in that, The construction of the task object based on the parsing result specifically includes: Write the parsing result into the attribute field of the task object and generate a task number; In the task object, a target state corresponding to the parsing result is set respectively. The target state includes an output control field, an input detection field, a repetition control field, an exception handling field, and a scheduling priority field. The task object is submitted to the queue of tasks to be executed in the task scheduling module, and waits to be scheduled and executed in sequence.

4. The numerical control input / output control method based on M-code according to claim 3, characterized in that, The execution of corresponding control logic based on the task object specifically includes: The task object is obtained from the queue to be executed, and the task execution order is determined according to the scheduling priority field in the task object; Based on the output control field in the task object, control the corresponding physical output point to enter the target state; After completing the output control, the corresponding input point is periodically detected within a set timeout period according to the input detection field in the task object to obtain the detection result; If the detection result meets the signal conditions, the output point is closed according to the closing point parameters, and the execution flow of the current task ends. If the detection result does not meet the signal condition, but meets the repeated control trigger condition, the output point is re-controlled according to the repeated control field and the repeated detection process is started.

5. The numerical control input / output control method based on M-code according to claim 4, characterized in that, The M-code-based numerical control input / output control method further includes: The output control field also includes feedback point configuration, and after the output control is completed, the state change of the feedback point is read. If the state change of the feedback point indicates that the feedback point has not reached the target state within the set time, an alarm warning event is triggered.

6. The numerical control input / output control method based on M-code according to claim 1, characterized in that, If the detection result does not meet the signal condition, but meets the repetitive control trigger condition, the output point is re-controlled according to the repetitive control field, and the repetitive detection process is started. Specifically, this includes: Close the current output point and record the current number of repetitions. If the number of repetitions does not reach the preset repetition control threshold, the output point will be reactivated and the detection process will be executed again after the set repetition interval time. If the signal condition is not detected when the number of repetitions reaches the preset repetition control threshold, then the alarm processing logic is executed.

7. The numerical control input / output control method based on M-code according to claim 1, characterized in that, The M-code-based numerical control input / output control method further includes: An alarm response strategy is set according to the exception handling field in the task object, and the alarm response strategy includes multiple alarm levels; When the alarm level in the set alarm strategy is the prompt level, a non-blocking prompt operation is performed. The non-blocking prompt operation includes generating prompt information and recording alarm logs without interrupting the current program flow. When the alarm level in the set alarm strategy is the interrupt level, an interrupt operation is executed. The interrupt operation includes triggering alarm output, pausing the CNC program and waiting for manual intervention or a reset signal. When the alarm level in the set alarm strategy is the linkage level, a multi-channel linkage response operation is executed. The multi-channel linkage response operation includes triggering the shutdown of multiple output points, calling a preset control subroutine, and sending alarm event information to the human-machine interface.

8. A numerical control input / output control system based on M-code, characterized in that, The M-code-based numerical control input / output control system includes: The instruction parsing module is used to acquire M-code instructions, read and parse the M-code instructions, and obtain the parsing results; The task construction module is used to construct a task object based on the parsing result and submit the task object to the execution queue of the task scheduling module; The scheduling and execution module is used to execute corresponding control logic based on the task object after the software state scheduling module receives the task object.