Debugging: Difference between revisions

From SweepMe! Wiki
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
Whenever you create a Device Class or a Module, you might need to access error messages to debug your code.  
Whenever you create a SweepMe! driver or a [[CustomFunction] script you might need to access error messages to debug your code. For this reason, the [[Debug]] widget can be shown in the [[Dashboard]] that prints out all messages. In general, all Python errors in SweepMe!, that are not already catched and handled, are shown in this widget.


== Debug console ==
== Debug widget ==
SweepMe! redirects all error and print messages to the Debug console which can be accessed via the key 'F2' or the menu 'Window' -> 'Debug'. Furthermore, the Debug console is a permanent widget of the Docking station window. If you cannot see it, then it is simply hidden. You can show the Debug console if you right-click on the header of any DockWidget in the DockingStation and select 'Debug' again.
SweepMe! redirects all error and print messages to the Debug widget which can be accessed via the key 'F2' or the menu 'Window' -> 'Debug'. Furthermore, the Debug console is a permanent widget of the [[Dashboard]] window. If you cannot see it, then it is simply hidden. You can show the Debug widget if you right-click on the header of any DockWidget in the DockingStation and select 'Debug' again.


== debug.log ==
== debug.log ==
All debug messages will also be saved to the file 'debug.log' that you can find in the installation path of your SweepMe! version.
All debug messages will also be saved to the file 'debug.log' that you can find in the installation path of your SweepMe! version.
This file can be used to create a support ticket. Please make sure that no personal information are sent. Furthermore, whenever SweepMe! starts, the debug.log will be emptied. Please make sure that you do not overwrite delete any debug message by restarting  
This file can be used to create a support ticket. Please make sure that no personal information are sent. Furthermore, whenever SweepMe! starts, the debug.log will be emptied. Please make sure that you do not overwrite delete any debug message by restarting.
As SweepMe! opens the file debug.log, the content cannot be accessed until SweepMe! is closed. To check whether the file debug.log contains all error messages, you can make a copy of it.
As SweepMe! opens the file debug.log, the might not be complete until SweepMe! is closed. To check whether the file debug.log contains all error messages, you can make a copy of it.
If multiple instances of SweepMe! are open, you will find multiple debug.log files with an additional instance id in the file name. The Debug widget now contains a button in its top-right toolbar to open the file.


== Program startup ==
== Program startup ==
Line 13: Line 14:
The option '-d' will result in further debug messages that might help us to identify your problem if you create a support ticket. In this case, you have to use "SweepMe!.exe -d"
The option '-d' will result in further debug messages that might help us to identify your problem if you create a support ticket. In this case, you have to use "SweepMe!.exe -d"


== Instrument drivers ==
== Programming ==
Any print-statement inside your SweepMe! driver will lead to an output via the the Debug widget. Thus, you can output whatever is needed to debug your code. Whenever, your driver is used, e.g. by running a measurement or pushing buttons like 'Retrieve' or "Apply', SweepMe! checks whether the code has been changed and reloads the driver. A restart of SweepMe! is not needed.
Any print-statement inside your SweepMe! driver will lead to an output via the the Debug widget. Thus, you can output whatever is needed to debug your code. Whenever, your driver is used, e.g. by running a measurement or pushing buttons like 'Retrieve' or "Apply', SweepMe! checks whether the code has been changed and reloads the driver. A restart of SweepMe! is not needed.


== Modules ==
tbd


== ErrorMessage ==
== ErrorMessage ==
You can import from SweepMe!'s module ErrorMessage two convenience functions called 'error' and 'debug'
You can import from the modeule ErrorMessage from the pysweepme package that comes with SweepMe!. Two convenience functions called 'error' and 'debug' that can be used to output the last error traceback or debug messages with timestamp.


{{syntaxhighlight|lang=python|code=
{{syntaxhighlight|lang=python|code=
Line 29: Line 28:


{{syntaxhighlight|lang=python|code=
{{syntaxhighlight|lang=python|code=
from pysweepme.ErrorMessage import error
error("<your message>")
error("<your message>")
}}
}}
Line 34: Line 34:


{{syntaxhighlight|lang=python|code=
{{syntaxhighlight|lang=python|code=
from pysweepme.ErrorMessage import debug
debug("<your message>")
debug("<your message>")
}}
}}
will print <your message> starting with a time stamp
will print <your message> starting with a time stamp

Revision as of 10:52, 15 January 2025

Whenever you create a SweepMe! driver or a [[CustomFunction] script you might need to access error messages to debug your code. For this reason, the Debug widget can be shown in the Dashboard that prints out all messages. In general, all Python errors in SweepMe!, that are not already catched and handled, are shown in this widget.

Debug widget

SweepMe! redirects all error and print messages to the Debug widget which can be accessed via the key 'F2' or the menu 'Window' -> 'Debug'. Furthermore, the Debug console is a permanent widget of the Dashboard window. If you cannot see it, then it is simply hidden. You can show the Debug widget if you right-click on the header of any DockWidget in the DockingStation and select 'Debug' again.

debug.log

All debug messages will also be saved to the file 'debug.log' that you can find in the installation path of your SweepMe! version. This file can be used to create a support ticket. Please make sure that no personal information are sent. Furthermore, whenever SweepMe! starts, the debug.log will be emptied. Please make sure that you do not overwrite delete any debug message by restarting. As SweepMe! opens the file debug.log, the might not be complete until SweepMe! is closed. To check whether the file debug.log contains all error messages, you can make a copy of it. If multiple instances of SweepMe! are open, you will find multiple debug.log files with an additional instance id in the file name. The Debug widget now contains a button in its top-right toolbar to open the file.

Program startup

The debug.log also contains all error message that occur during the startup of your program. Thus, if SweepMe! does not start correctly, you can check the error messages using the debug file. Alternatively, you can start SweepMe! by open Windows command line in the the SweepMe! installation folder and type in "SweepMe!.exe". The option '-d' will result in further debug messages that might help us to identify your problem if you create a support ticket. In this case, you have to use "SweepMe!.exe -d"

Programming

Any print-statement inside your SweepMe! driver will lead to an output via the the Debug widget. Thus, you can output whatever is needed to debug your code. Whenever, your driver is used, e.g. by running a measurement or pushing buttons like 'Retrieve' or "Apply', SweepMe! checks whether the code has been changed and reloads the driver. A restart of SweepMe! is not needed.


ErrorMessage

You can import from the modeule ErrorMessage from the pysweepme package that comes with SweepMe!. Two convenience functions called 'error' and 'debug' that can be used to output the last error traceback or debug messages with timestamp.

from ErrorMessage import error, debug

Usage

from pysweepme.ErrorMessage import error
error("<your message>")

will print <your message> and the last Exception that has been raised. It is typically used in combination with try-except

from pysweepme.ErrorMessage import debug
debug("<your message>")

will print <your message> starting with a time stamp