Patent Publication Number: US-2009241130-A1

Title: Virtual Interfacing Device and Related Method for Controlling the Same

Description:
BACKGROUND OF THE INVENTION 
     1. Field of the Invention 
     The present invention relates to a virtual interfacing device and related method, and more particularly to a virtual interfacing device and related method capable of communicating with Java applications. 
     2. Description of the Prior Art 
     Java is one of the most widely used programming languages nowadays, having a dominant advantage of “Write Once, Run Anywhere”. That is, a Java binary code is operable in Unix, Linux, Macintosh and Windows operating systems (OSs), needless of further program modification. With flexible OS compatibility, a trade-off is that the Java code cannot directly access drivers of an electronic device in any of the OSs, and can only achieve this with a Java Virtual Machine (JVM). 
     During researching and development of medical and consumer electronic products, a developer needs to establish an OS, install drivers of embedded electronic devices, and then introduce the JVM and needed Java applications for hardware and software functions. Some functions are difficult to be carried out by indirect means that communicates through the JVM between the Java application and the drivers of the OS. In this situation, Java Native Interface (JNI) is provided as a solution. 
     JNI utilizes a function library of the C/C++ programming language to solve the problem of few direct conversations between the Java application and the OS. The Java application is allowed to use the C/C++ library and instructions to control the electronic devices and kernel programs of the OS. However, the JNI eliminates the dominant advantages of Java. Combining the Java program with the C/C++ program through the JNI causes more programming complexity and degrades an ability of object oriented modeling and design. In addition, although JNI provides tight association between the Java application and the OS, the Java application loses the cross-platform ability. 
     By means of JNI, the product developer has to import needed C/C++ library and instructions according to internal devices of the electronic product. Therefore, the product developer needs to be familiar with Java applications and JNI and modify the Java applications, thereby increasing development cost and eliminating the cross-platform ability of the Java applications. 
     SUMMARY OF THE INVENTION 
     The present invention therefore provides a virtual interfacing device and related method for virtualization of a hardware device to achieve communication between a Java application and the hardware device. 
     An embodiment of the invention discloses a virtual interfacing device of a hardware device for virtualizing the hardware device to relay communication between the hardware device and a Java application. The hardware device operates with an operating system including a driving unit corresponding to the hardware device. The virtual interfacing device includes a virtualization unit and an event unit. The virtualization unit includes virtual data corresponding to the hardware device and is configured for modifying the virtual data or providing the virtual data for the Java application according to access information generated by the Java application. The event unit is used for generating Java event information for the driving unit according to the virtual data, and reading and writing the virtual data according to device event information generated by the driving unit. 
     An embodiment of the invention further discloses a virtualization method of virtualizing a hardware device to relay communication between the hardware device and a Java application. The hardware device operates with an operating system including a driving unit corresponding to the hardware device. The virtualization method includes providing virtual data corresponding to the hardware device and an event layer, modifying the virtual data or providing the virtual data for the Java application according to access information generated by the Java application, utilizing the event layer to generate Java event information for the driving unit according to the virtual data, and then utilizing the event layer to read and write the virtual data according to device event information generated by the driving unit. 
     These and other objectives of the present invention will no doubt become obvious to those of ordinary skill in the art after reading the following detailed description of the preferred embodiment that is illustrated in the various figures and drawings. 
    
    
     
       BRIEF DESCRIPTION OF THE DRAWINGS 
         FIG. 1  is a schematic diagram of an electronic product according to an embodiment of the invention. 
         FIG. 2  is a schematic diagram of a virtualization process according to an embodiment of the invention. 
         FIG. 3  is a schematic diagram of a virtualization process according to another embodiment of the invention. 
     
    
    
     DETAILED DESCRIPTION 
     Please refer to  FIG. 1 , which is a schematic diagram of an electronic product  100  according to an embodiment of the invention. The electronic product  100  can operate in a Linux, Windows, or other operating system and includes Java applications J_Ap(1)-J_Ap(n), a virtual interfacing unit  110 , a kernel module  120  and hardware devices Ph_Dev(1)-Ph_Dev(m). The Java applications J_Ap(1)-J_Ap(n) operating in a JVM (Java Virtual Machine)  124  generate access information RW_info(1)-RW_info (n) according to embedded Java functions to exchange information with the virtual interfacing unit  110 . The kernel module  120  includes a system call interface  122  and driving units DVR_Dev(1)-DVR_Dev (m) that drive the hardware devices Ph_Dev(1)-Ph_Dev(m) and generate device event information EVT_Dev(1)-EVT_Dev(m) according to operations of the hardware devices Ph_Dev(1)-Ph_Dev(m), respectively. 
     The virtual interfacing unit  110  virtualizes the hardware devices Ph_Dev(1)-Ph_Dev(m) and includes a virtualization unit  112  and an event unit  114 . The virtualization unit  112  includes virtual data VDATA corresponding to the hardware devices Ph_Dev(1)-Ph_Dev(m) and is configured for modifying the virtual data VDATA or providing the virtual data VDATA for the corresponding Java application according to any of the access information RW_info(1)-RW_info (n). The event unit  114  generates Java event information EV_Jap according to the virtual data VDATA and outputs the Java event information EV_Jap to the corresponding driving unit through the system call interface  122 . Furthermore, the event unit  114  reads and writes the virtual data VDATA according to any of the device event information EVT_Dev(1)-EVT_Dev(m). 
     In addition, the event unit  114  outputs a first awaking signal SWUP 1  for controlling the involved Java application to generate the access information or receives a second awaking signal SWUP 2  outputted by the involved Java application for reading and writing the virtual data VDATA and generating the Java event information EV_Jap according to the virtual data VDATA. 
     The virtual data VDATA includes virtual device data VirDev_DATA for storing hardware and software information of the hardware device Ph_Dev(1)-Ph_Dev(m), and event device data EVT_DATA for providing the event unit  114  or the Java applications J_Ap(1)-J_Ap(n) with the associated hardware information of the hardware device when the event unit  114  or the Java application J_Ap(1)-J_Ap(n) modifies the virtual device data VirDev_DATA. An exemplary embodiment of the virtual data VDATA is described with Extensible Markup Language (XML) as follows. 
     
       
         
           
               
             
               
                   
               
               
                 1. The virtual device data VirDev_DATA: 
               
               
                   
               
             
            
               
                   
               
            
           
           
               
               
            
               
                   
                 File Context(XML)(Device Info) 
               
               
                   
                 W3C XML 
               
               
                   
                 &lt;device_Info&gt; 
               
               
                   
                 &lt;device_name&gt; 
               
               
                   
                 &lt;device_type&gt; 
               
               
                   
                 &lt;device_site&gt; 
               
               
                   
                 &lt;device_ioctl_cmd&gt; 
               
               
                   
                 &lt;device_ioctl_cmd_num&gt; 
               
               
                   
                 &lt;devuce_ioctl_cmd&gt; 
               
               
                   
                 &lt;device_status&gt; 
               
               
                   
                 &lt;device_cmding&gt; 
               
               
                   
                 &lt;device_cmding_ioctl&gt; 
               
               
                   
                 &lt;ioctl_cmd&gt; 
               
               
                   
                 &lt;ioctl_cmd_parameter&gt; 
               
               
                   
                 &lt;device_cmding_read&gt; 
               
               
                   
                 &lt;device_cmding_open&gt; 
               
               
                   
                 &lt;device_cmding_close&gt; 
               
               
                   
                 &lt;device_cmding_write&gt; 
               
               
                   
                 &lt;write_type&gt; 
               
               
                   
                 &lt;write_context&gt; 
               
               
                   
                 &lt;device_response&gt; 
               
               
                   
                 &lt;device_request&gt; 
               
               
                   
                 &lt;device_cmd_type&gt; 
               
               
                   
                 &lt;device_cmd_cmd&gt; 
               
               
                   
                 &lt;device_cmd_parameter&gt; 
               
               
                   
                 &lt;device_cmd_response&gt; 
               
               
                   
                 &lt;device_return_value&gt; 
               
               
                   
                 &lt;device_return_parameter&gt; 
               
               
                   
                 &lt;device_return_context&gt; 
               
               
                   
                   
               
            
           
         
       
     
     The abovementioned program of the virtual device data VirDev_DATA includes a device information block &lt;device_Info&gt;, a command information block &lt;device_cmding&gt; and a response information block &lt;device_response&gt;. The device information block &lt;device_Info&gt; stores identity information &lt;device_name&gt;, control information &lt;device_ioctl_cmd&gt;, an address &lt;device_site&gt;, a type &lt;device_type&gt;, and a status &lt;device_status&gt; of any of the involved hardware devices Ph_Dev(1)-Ph_Dev(m). Each time the event unit  114  finishes reading the device information block &lt;device_Info&gt;, content of the device information block &lt;device_Info&gt; is cleared. The command information block &lt;device_cmding&gt; stores commands generated by the Java application attempting to control any of the hardware devices Ph_Dev(1)-Ph_Dev(m), and the commands include a reading command &lt;device_cmding_read&gt;, a writing command &lt;device_cmding_write&gt;, an opening command &lt;device_cmding_open&gt;, and so on. The response information block &lt;device_response&gt; stores values or parameters returned by the event unit  114 . The involved Java application clears content of the response information block &lt;device_response&gt; after reading is finished. 
     
       
         
           
               
             
               
                   
               
               
                 2. The event device data EVT_DATA: 
               
               
                   
               
             
            
               
                   
               
            
           
           
               
               
            
               
                   
                 File Context(XML) 
               
               
                   
                 W3C XML 
               
               
                   
                 &lt;device_Java&gt; 
               
               
                   
                 &lt;device_name&gt; 
               
               
                   
                 &lt;device_real_name&gt; 
               
               
                   
                 &lt;device_type&gt; 
               
               
                   
                 &lt;device_status&gt; 
               
               
                   
                 &lt;device_Event&gt; 
               
               
                   
                 &lt;device_name&gt; 
               
               
                   
                 &lt;device_real_name&gt; 
               
               
                   
                 &lt;device_type&gt; 
               
               
                   
                 &lt;device_status&gt; 
               
               
                   
                   
               
            
           
         
       
     
     The abovementioned program of the event device data EVT_DATA includes a Java block &lt;device_java&gt; and an event block &lt;device_Event&gt;. When the event unit  114  uses the first awaking information SWUP 1  to notify one of the Java applications J_Ap(1)-J_Ap(n), the Java block &lt;device_java&gt; provides the involved Java application with identity information, a type, and a status of the destined hardware device, and the Java application clears the content of the Java block &lt;device_java&gt; after receiving the information. Similarly, when one of the Java applications J_Ap(1)-J_Ap(n) uses the second awaking information SWUP 2  to notify the event unit  114 , the event block &lt;device_Event&gt; provides the event unit  114  with the identity information, the type, and the status of the destined hardware device, and the event unit  114  clears the content of the event block &lt;device_Event&gt; after receiving the information. In addition, the event device data EVT_DATA is preferably a part of the virtual device data VirDev_DATA, occupying less memory space, so that data transmission payload can be reduced during notification. 
     Please refer to  FIG. 2 , which is a schematic diagram of a virtualization process  20  according to an embodiment of the invention. The virtualization process  20  is utilized for virtualizing an electronic device operating with an operating system and thereby provides virtual data corresponding to the electronic device and an event layer to relay communication between the electronic device and a Java application. The virtualization process  20  is preferably realized in the electronic device  100  and includes the following steps: 
     Step  200 : Start. 
     Step  202 : Modify the virtual data or provide the virtual data for the Java application according to access information generated by the Java application. 
     Step  204 : Utilize the event layer to generate Java event information for the driving unit according to the virtual data. 
     Step  206 : Utilize the event layer to read and write the virtual data according to device event information generated by the driving unit. 
     Step  208 : End. 
     According to the virtualization process  20 , the event layer correspondingly generates the Java event information, including operations indicated by the Java application, according to the virtual data, when the Java application modifies the virtual data according to the access information. As a result, the event layer can control the destined hardware device through the driving unit. Preferably, the event layer is triggered to generate the Java event information by second awaking information outputted from the Java application. When the hardware device activates a specific operation spontaneously or in response to the operations indicated by the Java application, the driving unit generates and outputs the device event information to the event layer, and accordingly the event layer modifies the Java event information. In addition, the event layer outputs first awaking information to trigger the Java application to generate the access information, so as to obtain the virtual data. 
     For further concrete understanding of the invention concept, please refer to  FIG. 3 , which is a schematic diagram of a virtualization process  30  according to an embodiment of the invention. The virtualization process  30  provides virtual data corresponding to a hardware device and an event layer to virtualize the hardware device operating with an operating system and thereby relay communication between the hardware device and a Java application. The virtualization process  30  is mainly used in a situation where a Java application attempts to control the hardware device, and includes the following steps: 
     Step  300 : Start. 
     Step  302 : Modify the virtual data according to access information. 
     Step  304 : Notify the event layer. 
     Step  306 : Utilize the event layer to check and obtain hardware information of the hardware device included in the virtual data. 
     Step  308 : Obtain control information of the hardware device included in the virtual data according to the hardware information. 
     Step  310 : Generate and output Java event information to the hardware device according to the control information. 
     Step  312 : Receive response information from the hardware device. 
     Step  314 : Utilize the event layer to modify the virtual data according to the response information. 
     Step  316 : Provide the modified virtual data for the Java application. 
     Step  318 : End. 
     Preferably, the virtualization process  30  is carried out in the virtual interfacing device  110 . In this situation, the virtual data and the event layer is seen as the virtual unit  112  of the virtual data VDATA and the event unit  114  in the virtual interfacing device  110 , respectively. 
     Take a scenario where the Java application J_Ap(1) attempts to control the hardware device Ph_Dev(m) for example. The Java application J_Ap(1) first generates the access information RW_info(1). According to the virtualization process  30 , the virtual unit  112  writes the device identity, the device type, the control and the device status of the hardware device Ph_Dev(m) into both the virtual device data VirDev_DATA and the event block &lt;device_Event&gt; of the event device data EVT_DATA&lt;device_Event&gt; in accordance with the access information RW_info(1). The Java application J_Ap(1) generates the second awaking information SWUP 2  to awake the event unit  114  to read the event block &lt;device_Event&gt;. Finally, the event unit  114  obtains the identity and status information of the hardware device Ph_Dev(m), and thereby generates the Java event information EV_Jap. The driving unit DVR_Dev(m) notifies the hardware device Ph_Dev(m) of corresponding operations after receiving the Java event information EV_Jap through the system call interface  122 . 
     According to the operating state of the hardware device Ph_Dev(m), the driving unit DVR_Dev(m) returns the device event information EVT_Dev(m) to the event unit  114 . Then, the event unit  114  modifies the virtual device data VirDev_DATA and the Java block &lt;device_java&gt; of the event device data EVT_DATA. Finally, the event unit  114  outputs the first awaking information SWUP 1  to notify the Java application J_Ap(1), and thereby the Java application J_Ap(1) obtains corresponding control information from the virtual device data VirDev_DATA. 
     When the hardware device spontaneously changes its operation, the event unit  114  can perform a process to transfer control information to the destined Java application. The process is similar to the virtualization process  30  and detailed description thereof is omitted herein. 
     In conclusion, the embodiments of the invention provide a virtual interface between the hardware device and the Java application, including the following advantages: 1. It is not necessary to combine the Java application with C/C++ functions, thereby maintaining program integrity and unity; 2. The Java application and the virtual interface can be implanted with individual modules; 3. A product developer does not have to modify the Java application according to the hardware devices in the electronic product, thereby maintaining the cross-platform ability of the Java application. 
     Those skilled in the art will readily observe that numerous modifications and alterations of the device and method may be made while retaining the teachings of the invention.