Text Logging Basic

Motivation

The text logging allows to write textual messages to the PC similar to printf. This helps to debug the miniHIL application or to output any interesting information.

Pre-requisites

  • Connect to USB-1 at miniHIL board

  • Open the GUI and connect to the COM port of USB-1

Logging in ROOM

The protocol for logging is PLogger. The usage is depicted in the example below:

examples/logging.room
import etrice.api.logger.PLogger

ActorClass ALoggingExample {
	Structure {
		SAP logger: PLogger 1
		SAP timer: PTimer
		Attribute counter: int32
	}
	Behavior {
		StateMachine {
			State state0
			Transition init0: initial -> state0 {
				action '''
					timer.startTimer(1000);
				'''
			}
			Transition tr0: state0 -> state0 {
				triggers {
					<timeout: timer>
				}
				action '''
					logger.log("Hello from ALoggingExample"); 2
					logger.logF("This is the %d-th message", ++counter);
				'''
			}
		}
	}
}
1 Declare a SAP of protocol PLogger
2 Call one of the port operations
Note Log message will only be sent if there is an actual connection - otherwise they are dropped. This can also happen to messages that are sent too early, e.g. on startup or initial transition. In addition, the simulator mcu has to be flashed and running, in particular not suspended on a breakpoint.

Logging in CaGe files

In CaGe files two c functions may be used within target code blocks: TestLog_testTrace(const char* format, …​) and TestLog_println(const char* format, …​).

Both functions internally use printf to print the passed parameters.

TestLog_println(const char* format, …​) prints the string into the text log.

TestLog_testTrace(const char* format, …​) prints the string into the text log and into the generated CaGe traces.

Activate the logging example

The example above is available from

MiniHilProject_Examples\MiniHilProject\model-user\examples\logging.room

To try it do the following steps:

  1. Open the file

    MiniHilProject_Examples\MiniHilProject\model-user\examples\logging.room
  2. Uncomment the example actor reference

    MiniHilProject.room
    //
    //  Logging HowTo
    //
    ActorRef loggingExample : ALoggingExample
  3. After building and flashing the example project, you should see the output in the GUI text console:

    GUI TextConsole

Summary

  • Connect to USB-1

  • Declare a SAP of PLogger and call its logging operations

  • The output is display in the GUI text console

See Also