Control method and device of external equipment, equipment and medium

The method of creating software-level peripheral instances and handles with callback functions addresses the inflexibility and inefficiency of traditional host device control systems, enhancing system flexibility, efficiency, and maintainability by decoupling application and hardware layers.

CN119105820AInactive Publication Date: 2024-12-10BEIJING YINGCHUANGLIHE ELECTRONIC TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411040378.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-31
Publication Date
2024-12-10
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

Traditional host device control systems face inflexibility and inefficiency due to reliance on register configuration, requiring code rewriting for each device addition or change, leading to increased development workload and reduced adaptability and portability.

Method used

A method and device for controlling external devices through the creation of software-level peripheral instances and handles, along with callback functions, decoupling the application and hardware layers, enabling flexible and efficient management of external devices.

Benefits of technology

This approach enhances system flexibility, efficiency, and maintainability by reducing code duplication, improving portability, and simplifying development when switching device models, while ensuring seamless integration and real-time monitoring.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119105820A_ABST
    Figure CN119105820A_ABST
Patent Text Reader

Abstract

The invention provides a control method and device of external equipment, equipment and a medium, and relates to the technical field of computers. The method comprises the following steps: in response to an instance creation request issued by an application program, creating a peripheral instance corresponding to external equipment according to an equipment identifier of the external equipment; establishing a peripheral handle corresponding to the peripheral instance; establishing a callback function corresponding to the peripheral handle; and controlling the external device according to the external instance and the callback function. According to the technical scheme, the flexibility and efficiency of controlling the external equipment can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Background Art

[0002] In traditional host device control systems, the control of external devices mainly relies on register configuration, which is not only inflexible, but also faces a variety of peripheral interface types (such as RS485, RS232, 4-20mA, etc.). Each addition or deletion of a device or change in data format will lead to code rewriting, which not only consumes a lot of time and energy for code transplantation and testing, but also reduces the adaptability of the software and the transplantation capabilities of the platform.

[0003] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present application, and therefore may include information that does not constitute the prior art known to ordinary technicians in the field. Summary of the invention

[0004] The purpose of the embodiments of the present application is to provide a control method of an external device, a control device, a device and a medium for an external device, thereby overcoming the problems of insufficient flexibility and efficiency in the control methods of related external devices at least to a certain extent.

[0005] Other features and advantages of the present application will become apparent from the following detailed description, or may be learned in part by the practice of the present application.

[0006] According to a first aspect of an embodiment of the present application, a method for controlling an external device is provided, which is applied to a device management component. The method includes:

[0007] In response to an instance creation request issued by an application, a peripheral instance corresponding to the external device is created according to a device identifier of the external device included in the instance creation request, thereby realizing decoupling of the application layer and the hardware layer, wherein the peripheral instance is an object instance at the software level; a peripheral handle corresponding to each of the peripheral instances is established; at least one callback function corresponding to each of the peripheral handles is established, and the callback function is used to process related events of the external device; based on the peripheral handle, the external device is controlled through the peripheral instance and the callback function.

[0008] In some example embodiments of the present application, based on the aforementioned scheme, creating a peripheral instance corresponding to the external device according to the device identifier of the external device included in the instance creation request includes: determining the type and attribute information of the external device by querying a preset device identifier list; based on the type and attribute information, calling a corresponding instance creation interface to create the peripheral instance, and the instance creation interface includes Screat().

[0009] In some example embodiments of the present application, based on the aforementioned scheme, the establishment of a peripheral handle corresponding to each of the peripheral instances includes: allocating a unique peripheral handle to each of the peripheral instances; storing references to the peripheral handle and the peripheral instance in a handle table so as to quickly locate and call the corresponding peripheral instance through the peripheral handle.

[0010] In some example embodiments of the present application, based on the aforementioned scheme, the instance creation request includes a device identifier, device configuration parameters and a handle pointer, wherein the device configuration parameters include one or more of an interface type, a working mode and a collection interval.

[0011] In some example embodiments of the present application, based on the aforementioned scheme, based on the peripheral handle, the external device is controlled through the peripheral instance and the callback function, including: in response to an instance start instruction issued by an application, locating and calling the corresponding peripheral instance through the peripheral handle, calling Sstart() to control the operation of the external device according to the set parameters in the peripheral instance; in response to the operation of the external device, generating a start event and a data update event; calling the callback function through the peripheral handle to obtain specific data in the start event and the data update event.

[0012] In some example embodiments of the present application, based on the aforementioned scheme, the generating of a start event and a data update event in response to the operation of the external device includes: generating the start event in response to the startup of the external device; generating the data update event corresponding to the data acquisition task in response to the external device completing a data acquisition task.

[0013] In some example embodiments of the present application, based on the aforementioned scheme, the method for controlling an external device further includes: in response to a stop instruction issued by the application, controlling the external device to stop running through the peripheral handle; and in response to a delete instruction issued by the application, deleting the corresponding external device through the peripheral handle.

[0014] According to a second aspect of an embodiment of the present application, a control device for an external device is provided, the device comprising:

[0015] A peripheral instance creation module, for responding to an instance creation request issued by an application, and creating a peripheral instance corresponding to the external device according to the device identifier of the external device included in the instance creation request, so as to realize the decoupling of the application layer and the hardware layer, wherein the peripheral instance is an object instance at the software level; a peripheral handle establishment module, for establishing a peripheral handle corresponding to each of the peripheral instances; a callback function establishment module, for establishing at least one callback function corresponding to each of the peripheral handles, wherein the callback function is used to process related events of the external device; an external device control module, for controlling the external device through the peripheral instance and the callback function based on the peripheral handle.

[0016] According to a third aspect of an embodiment of the present application, an electronic device is provided, comprising: a processor; and a memory, wherein the memory stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the above-mentioned method for controlling an external device is implemented.

[0017] According to a fourth aspect of an embodiment of the present application, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the control method of the external device described above is implemented.

[0018] The technical solution provided by the embodiments of the present application may have the following beneficial effects:

[0019] In the control method of the external device in the example embodiment of the present application, on the one hand, when the application requests to create an external device instance, the device management component creates an instance corresponding to the specific external device according to the provided device identifier to ensure correct communication with the external device; in addition, after the external device instance is created, a peripheral handle associated with it is generated, and the peripheral handle is used as an identifier for subsequent interactions, so that the application can identify and operate the specific device instance; on the other hand, a callback function associated with the peripheral handle is generated, and the callback function will be called when the device state changes or the data collection is completed, and is responsible for further processing and distribution of the data; on the other hand, the device management component controls the external device according to the created peripheral instance and the registered callback function, including functions such as start, stop, data collection and event notification. Thus, the unification and automation of the control of the external device is realized, the cumbersome manual configuration process in the traditional method is avoided, the flexibility and efficiency of the device management are improved, and at the same time, the need for repeated code writing is reduced, and the portability and maintainability of the system are enhanced. In addition, the centralized management strategy simplifies the development of the upper-level application, so that it does not need to make a lot of modifications when changing the external device model, thereby saving development time and improving the operation efficiency and reliability of the overall system.

[0020] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] The drawings herein are incorporated into the specification and constitute a part of the specification, illustrate embodiments consistent with the present application, and together with the specification are used to explain the principles of the present application. Obviously, the drawings described below are only some embodiments of the present application, and for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0022] Figure 1 A flowchart of a method for controlling an external device according to some embodiments of the present application is schematically shown.

[0023] Figure 2 A schematic diagram showing an exemplary system architecture of a control system of an external device to which an embodiment of the present application can be applied.

[0024] Figure 3 A block diagram of a control device for an external device according to some embodiments of the present application is schematically shown.

[0025] Figure 4 A schematic diagram of the structure of a computer system of an electronic device according to some embodiments of the present application is schematically shown.

[0026] Figure 5 A schematic diagram of a computer-readable storage medium according to some embodiments of the present application is schematically shown.

[0027] In the drawings, the same or corresponding reference numerals represent the same or corresponding parts. DETAILED DESCRIPTION

[0028] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementations described in the following exemplary embodiments do not represent all implementations consistent with this specification. Instead, they are merely examples of devices and methods consistent with some aspects of this specification as detailed in the appended claims.

[0029] The terms used in this specification are for the purpose of describing specific embodiments only and are not intended to limit this specification. The singular forms "a", "the" and "the" used in this specification and the appended claims are also intended to include plural forms unless the context clearly indicates otherwise. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.

[0030] It should be understood that although the terms first, second, third, etc. may be used in this specification to describe various information, this information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of this specification, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".

[0031] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that this application will be more comprehensive and complete and fully convey the concept of the example embodiments to those skilled in the art.

[0032] In addition, described feature, structure or characteristic can be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided so as to provide a full understanding of the embodiments of the present application. However, it will be appreciated by those skilled in the art that the technical scheme of the present application can be put into practice without one or more of the specific details, or other methods, components, devices, steps, etc. can be adopted. In other cases, known methods, devices, realizations or operations are not shown or described in detail to avoid blurring the various aspects of the present application.

[0033] Furthermore, the drawings are only schematic illustrations and are not necessarily drawn to scale. The block diagrams shown in the drawings are only functional entities and do not necessarily correspond to physically separate entities. That is, these functional entities may be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.

[0034] In related technologies, the host usually controls the peripherals by directly accessing the registers of the external devices and configuring specific status bits. However, this control method has certain limitations, mainly reflected in its lack of flexibility. With the development of Internet of Things technology, the types of peripherals and interface types are becoming increasingly rich. For example, temperature and humidity sensors may use multiple communication interfaces such as RS485, RS232, 4~20mA, etc. For the access of each new device, traditional control schemes often require the special writing of corresponding driver codes to adapt to different interface standards and data formats. This process not only increases the development workload, but also leads to code duplication problems, reducing the code reuse rate and the efficiency of the overall software.

[0035] Furthermore, due to the lack of effective abstraction and standardization mechanisms, each addition or deletion of a device, or even a minor change in the data format, may require large-scale modification and retesting of the existing code, severely restricting the software's adaptability and system scalability. In addition, this tightly coupled design approach also limits the system's platform portability, making it difficult for the same software to run seamlessly on different hardware platforms, increasing the difficulty and cost of cross-platform deployment.

[0036] In order to solve all or part of the technical problems in the above-mentioned related technologies, in an exemplary embodiment of the present application, a control method of an external device is firstly proposed. Figure 1 The flowchart of a method for controlling an external device according to some embodiments of the present application is schematically shown. Figure 1 As shown, the control method of the external device may include the following steps:

[0037] Step S110, in response to the instance creation request sent by the application, creating a peripheral instance corresponding to the external device according to the device identifier of the external device included in the instance creation request, so as to achieve decoupling of the application layer and the hardware layer, wherein the peripheral instance is an object instance at the software level;

[0038] Step S120, establishing a peripheral handle corresponding to each peripheral instance;

[0039] Step S130, establishing at least one callback function corresponding to each peripheral handle, wherein the callback function is used to process related events of the external device;

[0040] Step S140: Based on the peripheral handle, the external device is controlled through the peripheral instance and the callback function.

[0041] The control method of the external device is applied to a device management component, which can be a device manager module in an operating system, or a part of a universal device control platform (UDCP), or other suitable device management components such as a device controller in an embedded system, which is mainly used to coordinate and manage the interaction between the application and the external device. The control method of the external device in the embodiment of the present application is described with the device management component as the execution subject.

[0042] According to the control method of the external device in the above example embodiment, on the one hand, when the application requests to create an external device instance, the device management component creates an instance corresponding to the specific external device according to the provided device identifier to ensure correct communication with the external device; in addition, after the external device instance is created, a peripheral handle associated with it is generated, and the peripheral handle is used as an identifier for subsequent interactions, so that the application can identify and operate the specific device instance; on the other hand, a callback function associated with the peripheral handle is generated, and the callback function will be called when the device state changes or the data collection is completed, and is responsible for further processing and distribution of the data; on the other hand, the device management component controls the external device according to the created peripheral instance and the registered callback function, including functions such as start, stop, data collection and event notification. Thus, the unification and automation of the control of the external device is realized, the cumbersome manual configuration process in the traditional method is avoided, the flexibility and efficiency of the device management are improved, and at the same time, the need for repeated code writing is reduced, and the portability and maintainability of the system are enhanced. In addition, the centralized management strategy simplifies the development of the upper-level application, so that it does not need to make a lot of modifications when changing the external device model, thereby saving development time and improving the operation efficiency and reliability of the overall system.

[0043] Next, the control method of the external device in the exemplary embodiment will be further described.

[0044] In step S110 , in response to the instance creation request sent by the application, a peripheral device instance corresponding to the external device is created according to the device identifier of the external device.

[0045] Among them, the application program may represent the application layer software that requests to create and control the external device, which may be a desktop application, a mobile application or a server-side application, and is mainly responsible for user interface presentation, logic processing and communication with the external device. A device identifier may represent a mark used to uniquely identify and distinguish each external device in a network or system, which is usually composed of a string of characters or numbers, which may be defined by a hardware manufacturer, or may be dynamically generated by a system or network. For example, the device identifier may be a device ID, a MAC address, an IP address, a universally unique identifier (UU ID) or a globally unique identifier (GU ID) and other suitable identifiers. A peripheral instance may represent an object instance created for a specific external device in a software system, which represents the existence of the external device at the software level, and may include the state, attributes, functions and methods of interacting with the external device.

[0046] Specifically, the application obtains the device identifier of the target external device through user selection, device scanning or reading from a configuration file. Then, the application sends a create instance request containing the device identifier to the device management component, which can be made by API call, and contains necessary parameters such as device type, identifier, etc. Then, after receiving the create instance request, the device management component can search for an external device matching the given device identifier in the known device list and verify whether the external device is in a connectable state. If the external device is found and verified, the device management component can create a corresponding peripheral instance based on the type and characteristics of the external device. Finally, the device management component can return the created peripheral instance to the application so that the application can control the external device or obtain external device data by calling the method of the peripheral instance.

[0047] Furthermore, the device management component creates an instance through the device identifier in the instance creation request sent by the application, rather than directly interacting with the hardware. This level of abstraction decouples the application layer from the hardware layer, improving the maintainability and scalability of the system. In addition, the instantiation process is based on a clear device identifier, which can limit access rights to specific devices, enhance the security of the system, and prevent unauthorized device access and operation. Moreover, through peripheral instances, users can quickly and seamlessly connect and use new external devices, improving the user experience, especially in scenarios where multiple devices are working at the same time or devices are switched frequently.

[0048] In some embodiments, the instance creation request may include a device identifier, device configuration parameters, and a handle pointer, wherein the device configuration parameters include one or more of an interface type, a working mode, and a collection interval.

[0049] Among them, the device configuration parameters can represent a set of parameters used to define and initialize the device's operating characteristics when creating a peripheral instance. These parameters can be used to guide the operation of the external device and interact with the device management component. The device configuration parameters may include but are not limited to: interface type, operating mode, and acquisition interval. The handle pointer may represent a reference to a specific external instance provided by the device management component to the application, so that the application can uniquely identify and access the created peripheral instance.

[0050] Furthermore, the interface type can be used to define the interface form for communication between the external device and the device management component. The working mode can represent continuous acquisition mode, triggered acquisition mode, energy saving mode, etc. The working mode affects the device's energy consumption, data acquisition frequency and accuracy, and the interaction mode with other system components. The acquisition interval can represent the minimum time interval between two data acquisitions of the external device.

[0051] In some embodiments, a peripheral instance corresponding to an external device is created according to the device identifier of the external device included in the instance creation request, specifically including the following steps: determining the type and attribute information of the external device by querying a preset device identifier list; based on the type and attribute information, calling the corresponding instance creation interface to create a peripheral instance, the instance creation interface including Screat().

[0052] In step S120 , a peripheral handle corresponding to each peripheral instance is established.

[0053] The peripheral handle can represent a unique identifier assigned by the device management component to each created peripheral instance, so that the application can access and control a specific peripheral instance through the peripheral handle. The peripheral handle does not directly expose the internal structure of the peripheral instance or its actual location in memory, but serves as an indirect reference, which can ensure the security of resources and simplify the operation of the application.

[0054] Specifically, when the peripheral instance is created, a peripheral handle associated with the peripheral instance will be automatically generated. The generated peripheral handle will be bound to the corresponding peripheral instance to form a one-to-one mapping relationship. The peripheral handle will then be passed to the application that requested to create the instance. Furthermore, the peripheral handle ensures that different applications will not mistakenly operate each other's peripheral instances, improving the stability and security of the system. Regardless of how the underlying hardware or operating system changes, as long as the handle interface remains unchanged, the application can maintain good compatibility and portability, and can run in different hardware or system environments without modification.

[0055] In some embodiments, a peripheral handle corresponding to each peripheral instance is established, specifically comprising the following steps: allocating a unique peripheral handle to each peripheral instance; storing references to the peripheral handle and the peripheral instance in a handle table so that the corresponding peripheral instance can be quickly located and called through the peripheral handle.

[0056] The handle table may represent a data structure storing a mapping relationship between a peripheral handle and a peripheral instance reference.

[0057] Specifically, when a peripheral instance is created, the system generates a unique peripheral handle. The handle can be an integer or a pointer to uniquely identify a peripheral instance. The generation of the peripheral handle can be random or based on a certain algorithm, such as a hash algorithm, to ensure its uniqueness and unpredictability. The created peripheral handle needs to be associated with the corresponding peripheral instance. This process can be recorded in the data structure inside the device management component, such as a hash table, array, or linked list. The peripheral handle is used as the key and the reference of the peripheral instance is used as the value to form a key-value pair storage. Whenever a new peripheral instance is created, the handle table needs to be updated, and the newly generated peripheral handle and peripheral instance reference are added to the handle table. Similarly, when the peripheral instance is destroyed, the handle table should also remove the relevant entries accordingly to maintain the integrity and validity of the data structure. In addition, through the handle table, the system can quickly locate any peripheral instance, greatly improving the efficiency of search and access. The application does not need to care about the specific implementation and storage location of the peripheral instance, but only needs to operate through the handle, which greatly simplifies application development and improves the readability and maintainability of the code.

[0058] In step S130, at least one callback function corresponding to each peripheral handle is established.

[0059] Among them, the callback function can be called by the system to perform a specific operation when a specific event occurs, which can be used to handle events related to external devices, such as receiving and processing data sent by the device, updating device status, error handling, resource management, etc.

[0060] Specifically, one or more callback functions can be defined to handle specific device events, such as data reception, state change, etc. Then, these callback functions are bound to the corresponding peripheral handles through the API provided by the system. The device management component can store this information in a mapping table so that when an event related to the handle is received, the corresponding callback function can be quickly located and called for event processing, thereby achieving efficient response and management of peripheral events. This process not only strengthens the interaction between the application and the external device, but also improves the system's response speed and resource utilization efficiency.

[0061] In step S140, the external device is controlled through the peripheral instance and the callback function based on the peripheral handle.

[0062] Specifically, the device management component can continuously monitor events related to the peripheral instance. Once events such as data reception and status change are detected, the corresponding callback function will be automatically called to handle these events based on the pre-established association between the peripheral handle and the callback function, thereby achieving instant response and control of the external device. At the same time, the application can also actively send control instructions to the external device through the peripheral instance, forming a two-way interaction mechanism. This process not only ensures the flexibility and efficiency of device control, but also strengthens the real-time monitoring and management of the device status by the device management component, realizing the automation and intelligence of device operation.

[0063] In some embodiments, based on the peripheral handle, the external device is controlled through the peripheral instance and the callback function, which specifically includes the following steps: in response to the instance start instruction issued by the application, the corresponding peripheral instance is located and called through the peripheral handle, and Sstart() is called to control the operation of the external device according to the set parameters in the peripheral instance; in response to the operation of the external device, a start event and a data update event are generated; and the callback function is called through the peripheral handle to obtain relevant data in the start event and the data update event.

[0064] Specifically, when receiving an instance startup instruction from an application, the device management component will parse the embedded setting parameters of the peripheral instance, and use these parameters to guide the startup and operation configuration of the external device to ensure that the device runs in the expected mode; subsequently, during the operation of the external device, the device management component will continue to monitor and automatically generate two key events, namely startup events and data update events. The startup event indicates that the device has been successfully started, and the data update event reflects the data changes during the operation of the device; finally, through pre-defined callback functions, the device management component can automatically capture and process specific data in these events, such as device status, sensor readings, etc., thereby achieving real-time data feedback and device status monitoring, and tightly coupling the needs of the application with the actual operation of the external device, ensuring the accuracy and efficiency of device control.

[0065] In some embodiments, in response to the operation of an external device, a startup event and a data update event are generated, which specifically includes the following steps: in response to the startup of the external device, a startup event is generated; in response to the external device completing a data collection task, a data update event corresponding to the data collection task is generated.

[0066] Specifically, when the external device is activated and started, the device management component generates a startup event to record the startup status of the device; subsequently, as the external device performs its data collection task, each time a task is completed, the device management component generates a corresponding data update event, which contains specific information about the data collection, such as the collection time, the amount of collected data, and possible abnormal conditions. This two-stage event generation mechanism not only ensures the effective confirmation of the external device startup, but also provides real-time data update notifications, thereby achieving comprehensive monitoring and data management of the external device's operating status.

[0067] In some embodiments, the above-mentioned external device control method also includes the following steps: in response to a stop instruction issued by the application, controlling the external device to stop running through the peripheral handle; in response to a delete instruction issued by the application, deleting the corresponding external device through the peripheral handle.

[0068] Specifically, when the application issues a stop command, the device management component will respond immediately, using the pre-established peripheral handle to directly control the external device, causing it to enter a stop state, effectively interrupting the ongoing operation or task. In addition, if the application decides to remove an external device, it only needs to send a delete command, and the device management component will also accurately identify and execute the delete operation through the peripheral handle, completely disconnecting the target device, and achieving instant updates and optimized configurations of the device list. This not only strengthens the application's ability to schedule hardware resources, but also ensures the effective management and reasonable allocation of system resources.

[0069] Figure 2 A schematic diagram of an exemplary system architecture of a control system of an external device to which the present application can be applied is shown. The control system of the external device can be built based on a general device control platform, which can be applicable to a single-chip microcomputer architecture, and can also be applicable to ARM, RICS, etc.

[0070] like Figure 2As shown, the control system of the external device may include an application (Application) module, an event control management (Event Task) module, a device control management (Device Task) module, an event list (Event List) module, a device hardware abstraction (Device HAL) module, a device list (Device List) module, and a variety of external devices including but not limited to temperature and humidity sensors, inertial sensors, ambient light sensors, pressure sensors, digital tubes, display screens, relays and buttons. Among them, the event control management module can be used to process various events from the application, such as starting / stopping the device, data ready, etc., which receives API calls and then triggers corresponding events. The device control management module can be used to process operations related to external devices, such as creating, starting, stopping and deleting device instances. The event list can be used to store all events, including events such as device start, stop and data ready. The device hardware abstraction can be used to provide a consistent interface for the application to access and control external devices. The device list can be used to store all available external devices.

[0071] In addition, the application interacts with the system through API calls, which provide access to and control of external devices. Specifically, Estarted, Estoped, and Edataready represent event types. Estarted means device startup, Estoped means device stop, and Edataready means data is ready. Screat, Sstart, Sstop, and Sde l ete represent different API calls. Screat is used to create a peripheral instance, Sstart is used to start a peripheral instance, Sstop is used to stop a peripheral instance, and Sde l ete is used to delete a device instance. The two API calls, register and register_with_type, are used to register callback functions so that they can be called when a specific event occurs.

[0072] Exemplarily, during the operation of the control system of the external device, the five steps of creating a peripheral instance, registering an event callback function, starting the peripheral, stopping the peripheral and deleting the peripheral may be included but not limited to.

[0073] Among them, when creating a peripheral instance, the application creates a new external device instance through the API call Screat(). This call requires the device's unique identifier (SID), configuration parameters (Sconfig), and a pointer to the peripheral handle (Shandler). The Dtype field in Sconfig is used to indicate the interface type of the device, the Dmode field specifies the device's operating mode, and the Dtime field sets the device's sampling interval. After receiving the request, the device control management module searches and loads the corresponding driver according to the provided SID, and then creates a new device instance. If the creation is successful, the device control management module will return the peripheral handle to the application.

[0074] When registering an event callback function, the application can use the regist() API call to register the callback function by peripheral handle, or use regist_with_type() to register the callback function by device type. After successful registration, the system will return an event callback function instance handle. These callback functions will be called when a specific event occurs to process and distribute data.

[0075] When starting a peripheral, the application can call Sstart() to start the external device. At this time, the event control management module will send an Estarted event notification. The external device starts to transmit data according to the preset parameters and sends an Edatarady event every time the data is ready. The application can obtain specific data from the event through the event_data parameter.

[0076] When an external device needs to be temporarily shut down, the application can call Sstop() to stop it, so that the external device stops collecting data and sends an Estoped event to the system.

[0077] If an external device is no longer needed, the application can call Sdelete() to delete the external device and release the memory and other system resources previously allocated for it.

[0078] In the above-mentioned example embodiment, the control method of the external device, on the one hand, when the application requests to create an external device instance, the device management component creates an instance corresponding to the specific external device according to the provided device identifier to ensure correct communication with the external device; in addition, after the creation of the external device instance, a peripheral handle associated with it is generated, and the peripheral handle is used as an identifier for subsequent interactions, so that the application can identify and operate the specific device instance; on the other hand, a callback function associated with the peripheral handle is generated, and the callback function will be called when the device state changes or the data collection is completed, and is responsible for further processing and distribution of the data; on the other hand, the device management component controls the external device according to the created peripheral instance and the registered callback function, including functions such as start, stop, data collection and event notification. Thus, the unification and automation of the control of the external device is realized, the cumbersome manual configuration process in the traditional method is avoided, the flexibility and efficiency of the device management are improved, and at the same time, the need for repeated code writing is reduced, and the portability and maintainability of the system are enhanced. In addition, the centralized management strategy simplifies the development of the upper-level application, so that it does not need to make a lot of modifications when changing the external device model, thereby saving development time and improving the operation efficiency and reliability of the overall system. Furthermore, hardware abstraction of external devices is achieved, which facilitates the addition of new peripherals through the interface of the hardware abstraction layer. Centralized management of external devices is also achieved. When switching peripheral models, there is no need to modify the upper-level application, which simplifies operations, improves operating efficiency, and greatly enhances system portability.

[0079] It should be noted that, although the steps of the method in the present application are described in a specific order in the drawings, this does not require or imply that the steps must be performed in the specific order, or that all the steps shown must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps, etc.

[0080] Next, in the embodiment of the present application, a control device for an external device is also provided, referring to Figure 4As shown in , the control device 300 of the external device can be composed of a peripheral instance creation module 301, a peripheral handle establishment module 302, a callback function establishment module 303 and an external device control module 304. Among them: the peripheral instance creation module 301 can be used to respond to the instance creation request issued by the application, and create a peripheral instance corresponding to the external device according to the device identifier of the external device included in the instance creation request, so as to realize the decoupling of the application layer and the hardware layer, wherein the peripheral instance is an object instance at the software level; the peripheral handle establishment module 302 can be used to establish a peripheral handle corresponding to each peripheral instance; the callback function establishment module 303 can be used to establish at least one callback function corresponding to each peripheral handle, and the callback function is used to process the relevant events of the external device; the external device control module 304 can be used to control the external device through the peripheral instance and the callback function based on the peripheral handle.

[0081] In an exemplary embodiment of the present application, the peripheral instance creation module may include a list query unit, which can be used to determine the type and attribute information of the external device by querying a preset device identifier list; based on the type and attribute information, call the corresponding instance creation interface to create a peripheral instance, and the instance creation interface includes Screat().

[0082] In an exemplary embodiment of the present application, the peripheral handle establishment module can be configured to: assign a unique peripheral handle to each peripheral instance; store the references of the peripheral handle and the peripheral instance in a handle table so that the corresponding peripheral instance can be quickly located and called through the peripheral handle.

[0083] In an exemplary embodiment of the present application, the above instance creation request includes a device identifier, device configuration parameters and a handle pointer, wherein the device configuration parameters include one or more of an interface type, a working mode and a collection interval.

[0084] In an exemplary embodiment of the present application, the external device control module may include: a device operation control unit, which can be used to respond to an instance startup instruction issued by an application, locate and call the corresponding peripheral instance through the peripheral handle, and call Sstart() to control the operation of the external device according to the set parameters in the peripheral instance; an event generation unit, which can be used to generate startup events and data update events in response to the operation of the external device; and a data acquisition unit, which can be used to call a callback function through the peripheral handle to obtain relevant data in the startup event and the data update event.

[0085] In an exemplary embodiment of the present application, the event generation unit may be configured to: generate a startup event in response to the external device being started; and generate a data update event corresponding to the data collection task in response to the external device completing the data collection task.

[0086] In an exemplary embodiment of the present application, the control device of the above-mentioned external device also includes an instruction execution unit, which can be used to respond to a stop instruction issued by the application and control the external device to stop running through the external handle; respond to a delete instruction issued by the application and delete the corresponding external device through the external handle.

[0087] It should be noted that the specific details of each part of the control device of the above-mentioned external device have been described in detail in the implementation method of the external device control method part. The undisclosed details can be found in the implementation method part, and will not be repeated here.

[0088] In addition, in an exemplary embodiment of the present application, an electronic device capable of implementing the above-mentioned external device control method is also provided.

[0089] Those skilled in the art will appreciate that various aspects of the present application may be implemented as a system, method or program product. Therefore, various aspects of the present application may be specifically implemented in the following forms, namely: a complete hardware embodiment, a complete software embodiment (including firmware, microcode, etc.), or an embodiment combining hardware and software aspects, which may be collectively referred to as a "circuit", "module" or "system" herein.

[0090] Refer to the following Figure 4 hereinafter describes an electronic device 400 according to such an embodiment of the present application. Figure 4 The electronic device 400 shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0091] like Figure 4 As shown, the electronic device 400 is in the form of a general computing device. The components of the electronic device 400 may include but are not limited to: the at least one processing unit 410, the at least one storage unit 420, a bus 430 connecting different system components (including the storage unit 420 and the processing unit 410), and a display unit 440.

[0092] The storage unit stores program codes, which can be executed by the processing unit 410, so that the processing unit 410 performs the steps according to various exemplary embodiments of the present application described in the above “Exemplary Method” section of this specification. For example, the processing unit 410 can perform the following steps: Figure 1In step S110 shown in the figure, in response to an instance creation request issued by an application, a peripheral instance corresponding to the external device is created according to the device identifier of the external device; in step S120, a peripheral handle corresponding to the peripheral instance is established; in step S130, a callback function corresponding to the peripheral handle is established; in step S140, the external device is controlled according to the peripheral instance and the callback function.

[0093] The storage unit 420 may include a readable medium in the form of a volatile storage unit, such as a random access memory unit (RAM) 421 and / or a cache memory unit 422 , and may further include a read-only memory unit (ROM) 423 .

[0094] The storage unit 420 may also include a program / utility 424 having a set (at least one) of program modules 425, such program modules 425 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.

[0095] Bus 430 may represent one or more of several types of bus structures, including a memory unit bus or memory unit controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.

[0096] The electronic device 400 may also communicate with one or more external devices 470 (e.g., keyboards, pointing devices, Bluetooth devices, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 400, and / or may communicate with any device that enables the electronic device 400 to communicate with one or more other computing devices (e.g., routers, modems, etc.). Such communication may be performed via an input / output (I / O) interface 450. Furthermore, the electronic device 400 may also communicate with one or more networks (e.g., local area networks (LANs), wide area networks (WANs), and / or public networks, such as the Internet) via a network adapter 460. As shown, the network adapter 460 communicates with other modules of the electronic device 400 via a bus 430. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 400, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, etc.

[0097] Through the description of the above embodiments, it is easy for those skilled in the art to understand that the example embodiments described here can be implemented by software or by combining software with necessary hardware. Therefore, the technical solution according to the embodiment of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, and includes several instructions to enable a computing device (which can be a personal computer, a server, a terminal device, or a network device, etc.) to execute the method according to the embodiment of the present application.

[0098] In an exemplary embodiment of the present application, a computer-readable storage medium is also provided, on which a program product capable of implementing the above method of the present specification is stored. In some possible embodiments, various aspects of the present application can also be implemented in the form of a program product, which includes a program code. When the program product is run on a terminal device, the program code is used to enable the terminal device to execute the steps according to various exemplary embodiments of the present application described in the above "Exemplary Method" section of the present specification.

[0099] refer to Figure 5 As shown, a program product 500 for implementing the control method of the external device according to an embodiment of the present application is described, which can adopt a portable compact disk read-only memory (CD-ROM) and include program code, and can be run on a terminal device, such as a personal computer. However, the program product of the present application is not limited thereto. In this document, a readable storage medium can be any tangible medium containing or storing a program, which can be used by or in combination with an instruction execution system, an apparatus or a device.

[0100] The program product may use any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of readable storage media (a non-exhaustive list) include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.

[0101] Computer readable signal media may include data signals propagated in baseband or as part of a carrier wave, in which readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Readable signal media may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.

[0102] The program code contained on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wired, optical cable, electromagnetic waves, etc., or any suitable combination of the foregoing.

[0103] Program code for performing the operations of the present application may be written in any combination of one or more programming languages, including object-oriented programming languages ​​such as Java, C++, etc., and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., via the Internet using an Internet service provider).

[0104] In addition, the above-mentioned figures are only schematic illustrations of the processes included in the method according to the exemplary embodiments of the present application, and are not intended to be limiting. It is easy to understand that the processes shown in the above-mentioned figures do not indicate or limit the time sequence of these processes. In addition, it is also easy to understand that these processes can be performed synchronously or asynchronously, for example, in multiple modules.

[0105] Through the description of the above embodiments, it is easy for those skilled in the art to understand that the example embodiments described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the embodiment of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, and includes several instructions to enable a computing device (which can be a personal computer, a server, a touch terminal, or a network device, etc.) to execute the method according to the embodiment of the present application.

[0106] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any variations, uses or adaptations of the present application, which follow the general principles of the present application and include common knowledge or customary technical means in the art that are not disclosed in the present application. The specification and embodiments are to be regarded as exemplary only, and the true scope and spirit of the present application are indicated by the claims.

[0107] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.

Claims

1. A method for controlling an external device, characterized in that: Applied to a device management component, the method comprises: In response to an instance creation request issued by an application, a peripheral instance corresponding to the external device is created according to a device identifier of the external device included in the instance creation request, so as to achieve decoupling of the application layer and the hardware layer, wherein the peripheral instance is an object instance at the software level; Establishing a peripheral handle corresponding to each of the peripheral instances; Establishing at least one callback function corresponding to each of the peripheral handles, wherein the callback function is used to process events related to the external device; Based on the peripheral handle, the external device is controlled through the peripheral instance and the callback function.

2. The method for controlling an external device according to claim 1, characterized in that: The step of creating a peripheral device instance corresponding to the external device according to the device identifier of the external device included in the instance creation request includes: Determine the type and attribute information of the external device by querying a preset device identifier list; Based on the type and attribute information, a corresponding instance creation interface is called to create the peripheral instance, and the instance creation interface includes Screat().

3. The method for controlling an external device according to claim 1, characterized in that: The step of establishing a peripheral handle corresponding to each of the peripheral instances comprises: Allocating a unique peripheral handle to each of the peripheral instances; The references of the peripheral handle and the peripheral instance are stored in a handle table, so as to quickly locate and call the corresponding peripheral instance through the peripheral handle.

4. The method for controlling an external device according to claim 1, characterized in that: The instance creation request includes a device identifier, device configuration parameters and a handle pointer, wherein the device configuration parameters include one or more of an interface type, a working mode and a collection interval.

5. The method for controlling an external device according to claim 1, characterized in that: Based on the peripheral handle, controlling the external device through the peripheral instance and the callback function includes: In response to an instance start instruction issued by the application, locate and call the corresponding peripheral instance through the peripheral handle, and call Sstart() to control the operation of the external device according to the set parameters in the peripheral instance; In response to the external device running, generating a start event and a data update event; The callback function is called through the peripheral handle to obtain relevant data in the start event and the data update event.

6. The method for controlling an external device according to claim 5, characterized in that: The generating of a start event and a data update event in response to the external device running includes: In response to the external device being started, generating the start event; In response to the external device completing the data collection task, the data update event corresponding to the data collection task is generated.

7. The method for controlling an external device according to claim 1, characterized in that: The method further comprises: In response to a stop instruction issued by the application, controlling the external device to stop running through the peripheral handle; In response to the deletion instruction sent by the application, the corresponding external device is deleted through the peripheral handle.

8. A control device for an external device, characterized in that: include: A peripheral instance creation module, configured to respond to an instance creation request issued by an application program, create a peripheral instance corresponding to the external device according to a device identifier of the external device included in the instance creation request, and implement decoupling of the application layer and the hardware layer, wherein the peripheral instance is an object instance at the software level; A peripheral handle establishment module, used for establishing a peripheral handle corresponding to each of the peripheral instances; A callback function establishment module, used to establish at least one callback function corresponding to each of the peripheral handles, wherein the callback function is used to process related events of the external device; The external device control module is used to control the external device based on the external device handle through the external device instance and the callback function.

9. An electronic device, characterized in that: include: processor; as well as A memory, configured to store executable instructions of the processor; The processor is configured to execute the method for controlling an external device according to any one of claims 1 to 7 by executing the executable instructions.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method for controlling an external device according to any one of claims 1 to 7 is implemented.

Citation Information

Cited By

  • Security chip, multi-application management method and device thereof and storage medium

    CN121561988A