Difference between revisions of "HANtune/Scripting"

From OpenMBD
Jump to: navigation, search
(Scripts)
(Scripts)
Line 15: Line 15:
  
 
[[File:Start_Script.png|Starting a script]]
 
[[File:Start_Script.png|Starting a script]]
 +
  
 
Alternatively, you can start a script by first dragging it from the 'Project Data' side panel to the layout and clicking the newly created button.
 
Alternatively, you can start a script by first dragging it from the 'Project Data' side panel to the layout and clicking the newly created button.
 
  
 
[[File:Start_Script_Button.png|Script running]]
 
[[File:Start_Script_Button.png|Script running]]

Revision as of 07:42, 17 January 2018

HANtune offers the ability to run your own scripts by integrating a Jython interpreter. Jython is a Java implementation of a Python interpreter, which means that it runs inside the Java Virtual Machine (JVM). This makes it very easy to interface with HANtune and enables us to automate its functionality. Jython currently corresponds to CPython 2.7 and can run any pure Python module, but does not support the use of native libraries (CPython extension modules written in C). However, this has been made available in HANtune by integrating JyNI, but is currently still limited.

Scripts

Adding a script to a project

To add a script to your project right click the 'Scripts folder' in the 'Project Data' side panel and click 'Add Script'. Browse to the right directory, select your script and click 'Add Script'.

Adding a script


Starting a script

To start a script right click on it in the 'Project Data' side panel and click 'Start'

Starting a script


Alternatively, you can start a script by first dragging it from the 'Project Data' side panel to the layout and clicking the newly created button.

Script running

To indicate that a script is running, its icon in the 'Project Data' side panel will change its appears.

Script running


Stopping a script

To stop a script right click on it in the 'Project Data' side panel and click 'Stop'.

Stopping a script


Alternatively, if you have added a button to your layout you can stop a script by click it.

Script running

Startup scripts

If you want to expand the default behavior of HANtune or one of its projects, you can use startup scripts. Inside the HANtune directory you will find a file called Startup.py. This file is executed each time you start HANtune. For example, if you want to let the Jython interpreter know where to look for modules, you put the following lines into Startup.py.

import sys
sys.path.append('C:\Users\User\Scripts')

Note: the path used is just an example and must be replaced by an actual location on your hard drive.

Console and Interactive Interpreter

HANtune also integrates an interactive interpreter and console to which all scripts can print.

HANtune Console

Signals and Parameters

Scripted Signals

Scripted Elements

Creating a new signal:

mySignal = createSignal('MySignal')

Setting its attributes:

mySignal.minimum = 0
mySignal.maximm = 255

Tip: enter dir(mySignal) into the console for a full list of attributes.

Triggers

mySignal = createSignal('MySignal')

def myTriggerFunction():
	if (mySignal.value > 50):
		print 'mySignal out of bounds'

createTrigger(mySignal, myTriggerFunction)
mySignal = createSignal('MySignal')
canSignal = getSignal('CanSignal')

def myTriggerFunction():
	mySignal.value = canSignal.value * 2

createTrigger(canSignal, myTriggerFunction)

Communication

FTP

SSH