[Serialization] C # communication (Serial Port and network) Framework Design and Implementation-11. Debugger design,
Contents
Chapter 2 debugger design... 2
11.1 debugging interface... 2
11.2 interface debugging... 3
11.3 Command Line Debugging... 5
11.4 summary... 6
Chapter 2 debugger Design
After the SuperIO framework platform is designed and developed, you want to compile the code into an assembly (DLL). The second development is to develop the driver and plug-in by referencing the DLL implementation interface and inheriting the class library, the code of the SuperIO framework will not be changed easily. This is the final result of the framework design, but it is inconvenient in the secondary development process. It mainly involves two problems: 1. How to verify the final effect of the driver after the development of the driver? For example, the parsing of raw data, the data processing process and the implementation of functions, etc. Therefore, you must be able to Debug the driver's source code in Debug mode, rather than debugging the code of SuperIO itself. It is impossible to mount the developed driver to the configuration file repeatedly, and start the Software Repeatedly to verify the effect of the driver development. This is a time-consuming task. 2. in the Debug mode, in the debugging process, the SuperIO framework must selectively interact with the configuration file information, even though it is only the source code of the debugging driver module, however, the entire framework Platform is in the debugging mode. For example, in the debugging mode, the driver in the preparation file is not loaded, and in the debugging mode, the device driver information is not written to the preparation file.
Based on actual application situations, the debugger function is added to the Framework Platform. The implementation of this code is not complex, but it is a necessary part of the Framework Platform System. It is like a person who lacks a part of it is always not so perfect.
11.1 debugging Interface
The IDebugDevice interface defines four debugging interface functions, which are mainly used for source code debugging of device drivers, interface views, data export, and service components. The interface definition is as follows:
11.2 interface debugging
Secondary developers can inherit the SuperIO. UI. MainForm form class to create their own host programs, which can be extended on this basis. The SuperIO. UI. MainForm class inherits the IDebugDevice interface and implements each debugging interface. The implementation of the debugging interface is essentially an operation on the controller (SuperIO. DeviceController). The interface implementation code is as follows:
/// <Summary> /// debug the device, input the IRunSCLDevice interface // </summary> /// <param name = "dev"> </param> public void DebugDevice (IRunDevice dev) {this. _ DeviceController. addDevice (dev) ;}/// <summary> // debug view form, which must inherit SuperIO. show. IRTDataShow interface // </summary> // <param name = "rtdataform"> </param> public void DebugGraphicsShow (SuperIO. show. IGraphicsShow show) {if (show is System. windows. forms. form) {System. windows. forms. form from = show as System. windows. forms. form; from. mdiParent = this; from. show (); this. _ DeviceController. addGraphicsShow (show);} else {MessageBox. show ("while implementing IGraphicsShow, the instance must also be of the Form Type") ;}/// <summary> /// debug the export data interface, which must inherit SuperIO. middleData. IExportData // </summary> /// <param name = "export"> </param> public void DebugExportData (IExportData export) {this. _ DeviceController. addExportData (new List <IExportData> (new IExportData [] {export }));} /// <summary> ///// </summary> /// <param name = "appService"> </param> public void DebugAppService (IAppService appService) {if (appService. serviceType = ServiceType. show) {BarButtonItem bt = new BarButtonItem (this. barManager1, appService. thisName); Font font = new Font ("Tahoma", 12); bt. itemAppearance. setFont (font); bt. tag = appService. thisKey; bt. itemClick + = new ItemClickEventHandler (ServiceItem_ItemClick); barServices. addItem (bt);} _ DeviceController. addAppService (new List <IAppService> (new IAppService [] {appService }));}
Interface debugging requires interaction with the configuration file, so you need to set whether the current debugging mode is in use. You can identify it by using the IsDebug attribute of the SuperIO. Device. DebugDevice static class.
We recommend that you use this method to debug secondary development components.
11.3 Command Line Debugging
You can also debug the secondary development component through the command line, which is actually SuperIO. device. the DebugDevice static class creates SuperIO in singleton mode. UI. mainForm form instance, and return the IDebugDevice interface instance. This debugging mode can be used for simple driver and plug-in debugging, which is fast and efficient. The code is defined as follows:
Namespace SuperIO. device {public class DebugDevice {private static object _ LockObj = new object (); private static SuperIO. device. IDebugDevice _ DebugInstance = null; // <summary> // get the debugging device instance /// </summary> /// <returns> </returns> public static SuperIO. device. IDebugDevice GetDebugInstance () {if (_ DebugInstance = null) {lock (_ LockObj) {if (_ DebugInstance = null) {_ DebugInstance = (new SuperIO. UI. mainForm () as SuperIO. device. IDebugDevice ;}}return _ DebugInstance;} private static bool _ IsDebug = false; // <summary> /// whether it is the debugging mode, if you do not call the configuration file information /// </summary> public static bool IsDebug {get {return _ IsDebug;} set {_ IsDebug = value ;}}}}
This debugging mode does not need to be set to the debugging mode through the SuperIO. Device. DebugDevice. IsDebug attribute.
Conclusion 11.4
The design of any component may not be complex, but it brings great convenience to the work. The debugger is more of a concept and does not have much actual code, but it is much more convenient in the secondary development process.
The next chapter introduces Chapter 12th secondary development and application.