Python API
Program Structure and Events |
Package = N/A |
||
Function |
Return Type | Description |
Example |
cleanUp() |
N/A | If defined, this function is called once just before the program stops. | def cleanUp(): |
mouseEvent(pressed, x, y, firstPress) |
N/A | If defined, this function is called when the user clicks and/or moves the mouse on the workspace icon of this device.
|
def mouseEvent(pressed, x, y, firstPress): |
| measurementSystemChangeEvent() | N/A | If defined, this function is called when the user changes the measurement system between Metric and Imperial in Preferences. Use Options.isUsingMetric() in the options package to get the current setting. | from options import * |
Digital I/O |
Package = gpio |
||
Function |
Return Type | Description |
Example |
pinMode(slot, mode) |
N/A | Set a digital slot to INPUT or OUTPUT. |
pinMode(1, OUT) pinMode(2, IN) |
digitalRead(slot) |
int | Reads from a digital slot, returns HIGH or LOW. |
val = digitalRead(1) |
digitalWrite(slot, value) |
N/A | Writes to a digital slot with HIGH or LOW. |
digitalWrite(1, HIGH) |
Analog I/O |
Package = gpio |
||
Function
|
Return Type | Description |
Example |
analogRead(slot) |
int | Reads from an analog slot, returns 0 to 1023. |
val = analogRead(A1) |
analogWrite(slot, value) |
N/A | Writes a PWM wave to a digital slot, from 0 to 255. |
analogWrite(A1, 128) |
Custom I/O |
Package = gpio |
||
| Function | Return Type | Description | Example |
| customRead(slot) | str | Reads from an custom slot, returns a String | val = customRead(1) |
| customWrite(slot, value) | N/A | Writes a string to a digital slot. You can use customRead directly from the other side | customWrite(1, "hello") |
Input Interrupts/Events |
Package = gpio |
||
| Function | Return Type | Description | Example |
| add_event_detect(slot, callback) | N/A | Registers a function to be called when the input of a slot changes. This works for analog, digital and custom inputs. Whenever the input changes, the callback is called. Only one function is registered per slot. Calling this a second time for the same slot will remove the first callback. |
def detect(): |
| remove_event_detect(slot) | N/A | Unregisters the slot for input changes. | remove_event_detect(0) |
Time |
Package = time |
||
Function |
Return Type | Description |
Example |
|
delay(tmsec) |
N/A |
Pauses the program for tmsec milliseconds. Value of 0 has the meaning of sleeping until the next execution cycle, as determined by the run-time. |
delay(1700) |
| sleep(tsec) | N/A | Pauses the program for tsec seconds. Fractional seconds values for tsec are acceptable. Value of 0 has the meaning of sleeping until the next execution cycle, as determined by the run-time. | sleep(0.25) same as delay(250) |
| uptime() | float | Returns the time since the device was started in seconds. | print(uptime()) |
Basic Networking |
Package = networking |
||
Function |
Return Type | Description |
Example |
localIP() |
str | Returns the local IP. |
ip = localIP() |
subnetMask() |
str | Returns the subnet mask. |
mask = subnetMask() |
gatewayIP() |
str | Returns the gateway IP. |
gateway = gatewayIP() |
HTTP Client |
Package = http |
||
Function |
Return Type | Description |
Example |
HTTPClient() |
HTTPClient |
Creates a HTTP Client. |
http = HTTPClient() |
open(url) |
N/A |
Gets an URL. |
http.open(“http://www.cisco.com”) |
stop() |
N/A |
Stops the request. |
http.stop() |
onDone(callback) |
N/A |
Sets the callback for when the request is done. |
def onHTTPDone(status, data): ... http.onDone(onHTTPDone) |
HTTP Server (SBC only) |
Package = http | ||
| Function | Return Type | Description | Example |
route(path, callback); |
N/A |
Sets up a route for path and calls callback when it is requested. Routes also support wildcards using *. |
def onRouteHello(url, response):
def onRouteAll(url, response): |
start(port) |
bool |
Starts listening on port. |
HTTPServer.start(80) |
stop() |
N/A |
Stops listening. |
HTTPServer.stop() |
| Response class | Passed into the HTTPServer route handler. | ||
| send(content) | N/A | Sends content back as response. | response.send("hello") |
| setContentType(type) | N/A | Sets the content type in the response. | response.setContentType("text/plain") |
| sendFile(filePath) | N/A | Sends a file back as response. The file path is in the device's file manager, not relative to the source code of the current project/script. | response.sendFile("/test.txt") |
| sendNotFound() | N/A | Sends a file not found as response. | response.sendNotFound() |
Package = email |
|||
Function |
Return Type | Description |
Example |
setup(email, server, username, password) |
N/A |
Sets up the email client to be used. |
EmailClient.setup(“user@cisco.com”, "cisco.com", "username", "password") |
send(address, subject, body) |
N/A |
Sends an email. |
EmailClient.send("pt@cisco.com", "subject", "body) |
receive() |
N/A |
Receives emails. |
EmailClient.receive() |
onSend(callback) |
N/A |
Sets the callback for when sending an email is done. |
def onEmailSend(success): ... EmailClient.onSend(onEmailSend) |
onReceive(callback) |
N/A |
Sets the callback for when emails are received. |
def onEmailReceive(sender, subject, body):
print(body) ...
EmailClient.onReceive(onEmailReceive) |
TCP |
Package = tcp |
||
Function |
Return Type | Description |
Example |
TCPClient() |
TCPClient | Creates a TCP Client. |
client = TCPClient() |
connect(ip, port) |
bool | Connects to ip and port. |
client.connect("1.1.1.1", 2000) |
| connected() | bool | Returns true if connected | client.connected() |
close() |
N/A | Disconnects. |
client.close() |
state() |
int | Returns the state of the connection. |
client.state() |
remoteIP() |
str | Returns the remote IP. |
client.remoteIP() |
remotePort() |
int | Returns the remote port. |
client.remotePort() |
| localIP() | str | Returns the local IP | client.localIP() |
| localPort() | int | Returns the local port | client.localPort() |
send(data) |
N/A | Sends data to remote connection |
client.send("hello") |
|
sendWithPDUInfo(data, pduInfo) |
bool |
Sends data to remote connection with PDU info. |
data = "hello" |
onReceive(callback) |
N/A | Sets the callback for when data is received. |
def onTCPReceive(data):
print(data) ...
client.onReceive(onTCPReceive)
|
|
onReceiveWithPDUInfo(callback) |
N/A |
Sets the callback for when data is received and includes the PDU info. |
client = TCPClient() client.onReceiveWithPDUInfo(onTCPReceiveWithPDUInfo) |
onConnectionChange(callback) |
N/A | Sets the callback for when the connection changes. |
def onTCPConnectionChange(type):
print(type) ...
client.onConnectionChange(onTCPConnectionChange)
|
|
|
|
|
TCPServer() |
TCPServer | Creates a TCP Server. |
server = TCPServer() |
listen(port) |
N/A | Starts listening on port. |
server.listen(2000) |
stop() |
N/A | Stops listening. |
server.stop() |
onNewClient(callback) |
N/A | Sets the callback for when a new client comes in. |
def onTCPNewClient(client):
print(client) ...
server.onNewClient(onTCPNewClient)
|
UDP |
Package = udp |
||
Function |
Return Type | Description |
Example |
UDPSocket() |
UDPSocket | Creates an UDP Socket. |
udp = UDPSocket() |
begin(port) |
bool | Starts listening on port. |
udp.begin(2000) |
stop() |
N/A | Stops listening. |
udp.stop() |
send(ip, port, data) |
bool | Sends data. |
udp.send("1.1.1.1", 2000, "hello") |
|
sendWithPDUInfo(ip, port, data, pduInfo) |
bool |
Sends data with PDU info. |
data = "hello" |
onReceive(callback) |
N/A | Sets the callback for when data is received. |
def onUDPReceive(ip, port, data):
print(data)
...
udp.onReceive(onUDPReceive) |
|
onReceiveWithPDUInfo(callback) |
N/A |
Sets the callback for when data is received and includes PDU info. |
def onUDPReceiveWithPDUInfo(ip, port, data, pduInfo): pduInfo.addInMessage("I got some data.")
udp.onReceiveWithPDUInfo(onUDPReceiveWithPDUInfo) |
File (SBC only) |
Package = file, os, os.path |
||
Function |
Return Type | Description |
Example |
bool exists(path) |
bool | Returns whether a file exists in the file system. |
exists("/file.txt") |
File open(path, mode) |
File | Opens a file for reading or writing. |
file = open("/file.txt", "r") |
bool remove(path) |
bool | Removes a file. |
remove("/file.txt") |
bool mkdir(path) |
bool | Creates a directory including all intermediate directories. |
mkdir("/dir1/dir2") |
bool rmdir(path) |
bool | Removes a directory. |
rmdir("/dir1/dir2") |
listdir(path) |
list | Lists all files in a directory. |
files = listdir("/dir1") |
exists(path) |
bool | Test if path exists |
val = exists("/file") |
| isfile(path) | bool | Test if path is a file | val = exists("/file") |
| isdir(path) | bool | Test if path is a directory | val = exists("/file") |
tell() |
int | Return read/write pointer of the file |
file.tell() |
close() |
N/A | Closes the file. |
file.close() |
seek(position) |
bool | Seeks to position in file. |
file.seek(0) |
readline() |
str | Reads a line of string or to the end of file. |
val = file.readline() |
read(length) |
str | Reads the length of byte into string |
val = file.read() |
write(val) |
N/A | Writes as binary. |
file.write(val) |
USB |
Package = usb |
||
Function |
Return Type | Description |
Example |
| USB( usbNum, speed) | USB | The variable for USB port. | usb = USB(0, 9600); |
close() |
N/A | Ends communication. |
usb.close(); |
inWaiting() |
int | # of bytes available for reading in buffer. |
bytes = usb.inWaiting(); |
readLine() |
string | Reads a line of string or to the end of stream. |
val = usb.readLine(); |
read() |
string | Reads the first character and removes from buffer. |
val = usb.read(); |
| peek() | string | Reads one character without removing from buffer. | val = usb.peek(); |
write(val) |
int | Prints to USB, returns the number of bytes written. |
val = usb.write(val); |
| PTmata(usbNum, speed) | PTmata | The variable for PTmata communication over USB port. | ptmata = PTmata(0, 9600) |
close() |
N/A | Ends communication. |
ptmata.close() |
pinMode(slot, mode) |
N/A | Set a digital slot on other side to INPUT or OUTPUT. |
ptmata.pinMode(1, OUT) ptmata.pinMode(2, IN) |
digitalRead(slot) |
int | Reads from a digital slot on other side, returns HIGH or LOW. |
val = ptmata.digitalRead(1) |
digitalWrite(slot, value) |
N/A | Writes to a digital slot on other side with HIGH or LOW. |
ptmata.digitalWrite(1, HIGH) |
analogRead(slot) |
int | Reads from an analog slot on other side, returns 0 to 1023. |
val = ptmata.analogRead(A1); |
analogWrite(slot, value) |
N/A | Writes a PWM wave to a digital slot on other side, from 0 to 255. |
ptmata.analogWrite(A1, 128); |
customRead(slot) |
string | Reads from an custom slot on other side, returns a String |
val = ptmata.customRead(1); |
customWrite(slot, value) |
N/A | Writes a string to a digital slot on other side. You can use customRead directly from the other side |
ptmata.customWrite(1, "hello"); |
inWaiting() |
int | # of bytes available for reading in buffer. |
bytes = ptmata.inWaiting(); |
processInput() |
N/A | Reads from buffer and processes inputs for commands and reports of states. | def loop() : |
readAndReportData() |
N/A | Reads this side's slot values and report to other side if they are changed. | ptmata.readAndReportData(); |
IoE Client (SBC only) |
Package = ioeclient |
||
Function |
Return Type | Description |
Example |
| IoEClient.setup(api) | N/A | Sets up the API for remote monitor and control from IoE server. The api is an object with the following properties describing the device:
For measurement systems other than Metric and Imperial, use only the "unit" property. That means if you want a device to show more than Metric and Imperial, you need to create another device for other measurement systems.
|
IoEClient.setup({
IoEClient.setup({ |
| IoEClient.reportStates(states) | N/A | Reports the states of this device to the IoE server. |
IoEClient.reportStates("0,1") IoEClient.reportStates([0, 1, "str"]) |
| IoEClient.onInputReceive(callback) | N/A | Sets the callback for processing inputs received from IoE server. This is called with all states info. onStateSet is called with only the state that was changed. |
def onInputReceiveDone(input): ... |
| IoEClient.onStateSet(callback) | N/A | Sets the callback for processing inputs received from IoE server. This is called with only the state that was changed. onInputReceive is called with all states info. |
def onStateSet(stateName, value): |
Physical |
Package = physical |
||
Function |
Return Type | Description |
Example |
move(x,y) |
N/A | Move thing to position x and y in screen coordinates. The parameters expect x and y are ints. Casting may be required. |
move(200,200) |
moveBy(x,y) |
N/A | Increment position of thing by x and y in screen coordinates. The parameters expect x and y are ints. Casting may be required. |
moveBy(1,0) |
| moveItemInWorkspace(name, x, y) | bool | Moves the item defined by name to x and y in screen coordinates in the active workspace | moveItemInWorkspace("building", 300,300) |
getX() |
float | Gets the x position of thing in screen coordinates. |
x = getX() |
getY() |
float | Gets the y position of thing in screen coordinates. |
y = getY() |
devicesAt(x, y, width, height) |
list | Gets a list of devices at position x and y with a boundary of width and height. The parameters expect x and y are ints. Casting may be required. | devices = devicesAt(10,10,100,100) |
| devicesIncludingClustersAt(x, y, width, height) | Array of string | Gets a list of devices at position x and y with a boundary of width and height including clusters | devicesIncludingClustersAt(10, 10, 100, 100) |
| getName() | str | Gets the name of the thing | devName = getName() |
| getDeviceProperty(deviceName, property) | str | Gets the property of a device with the specified property | prop = getDeviceProperty("Car", "material") |
| setDeviceProperty(deviceName, property, value) | N/A | Set property for device | prop= setDeviceProperty("Car", "material", "metal") |
| setComponentOpacity(componentName, value) | N/A | Set the opacity of a component in the thing. The value is from 0 to 1, where 1 is opaque. | setComponentOpacity("light", 0.5) |
| setComponentRotation(componentName, value) | N/A | Sets the component rotation in degrees | setComponentRotation("hourHand", 90) |
| setThingRotation(value) | N/A | Sets the entire thing rotation in degrees | setThingRotation(180) |
| getSerialNumber() | str | Gets the serial number of the thing | serialNo = getSerialNumber() |
| setCustomText(x,y,width,height,text) | N/A | Write some text on the Thing viewable on the workspace. | setCustomText(0,0,100,100,"Device is On") |
| fillColor(componentName, red, green, blue) | N/A | Fill the component with the specified RGB values. The component original image will have to be transparent for the color to show up. | fillColor("led", 0,0,255) |
| addSound(soundID, soundPath) | N/A |
Adds a sound to the device so it can be used. Sound is referenced by the ID for later use. PT sound folder is: "/../Sounds/" |
addSound('sound1', '/../Sounds/buzzLow.wav'); |
| playSound(soundID, playLength) | N/A |
Plays a sound that has been added to the device. soundID references the ID the sound was added with, playLength is how many times the sound should run. -1 will make the sound loop forever. | playSound('sound1', 2); |
| stopSound(soundID) | N/A |
Stops a sound. soundID references the ID the sound played. | stopSound('sound1'); |
| destroySounds() | N/A |
Stops any sounds playing in the devices and removes them. They can't be played again unless re-added. | destroySounds(); |
| setParentGraphicFromComponent(componentName, index) | N/A | Sets the parent container of both physical and logical view to a graphic from component. | setParentGraphicFromComponent("name", 0) |
| setLogicalParentGraphicFromComponent(componentName, index) | N/A | Sets the parent container of logical view to a graphic from component. | setLogicalParentGraphicFromComponent("name", 0) |
| setPhysicalParentGraphicFromComponent(componentName, index) | N/A | Sets the parent container of physical view to a graphic from component. | setPhysicalParentGraphicFromComponent("name", 0) |
| setLogicalBackgroundPath(path) | N/A | Sets the logical view background to an image at path. | setLogicalBackgroundPath("path") |
| getAttributeOfDeviceAtSlot(attribute, slot) | float | Returns the attribute value of the device connected at the specified slot. | value = getAttributeOfDeviceAtSlot("name", 0) |
| getAttributeOfDevice(attribute) | float | Returns the attribute value of this device. | value = getAttributeOfDevice("name") |
| getSlotsCount() | int | Returns the number of slots this device has. | slots = getSlotsCount() |
Environment |
Package = environment (from environment import *) or (from environment import Environment) |
||
| Function | Return Type | Description | Example |
get(environmentID) |
float | Gets the value of the environment by its ID. You can get the ID by placing your mouse over the environment name in the Environment GUI. If the environment does not exist, it will return -1. |
Environment.get("Ambient Temperature") |
setGlobalProperty(propertyName, value) |
N/A | Sets a global property with a value. Both are strings. |
Environment.setGlobalProperty("CLOCK", "12:00:00 pm") |
| getGlobalProperty(propertyName) | string | Returns the global property value. | Environment.getGlobalProperty("CLOCK") |
| hasGlobalProperty(propertyName) | boolean | Returns true if the property name exists, otherwise false. | Environment.hasGlobalProperty("CLOCK") |
| setContribution(environmentID, rate, limit, bCumulative) | Set the things contribution to an environment based on it's environment ID. You do not need to worry about how much time has passed and you only need to call this function when you need different parameters. rate: the rate to add or subtract from the total environment value in value/second. Value should be in metric. limit: the maximum or minimum this thing is allowed to contribute. The limit should be in metric. bCumulative: add up contributed values over time. For environments like light sources that disappear when off, bCumulative should be set to false. |
// increase the Ambient Temperature at 0.05C/second until 100C. Environment.setContribution("Ambient Temperature", 0.05, 100, true) |
|
| removeCumulativeContribution(environmentID) | Remove the overall cumulative contribution from the Thing. In most cases, you do not need to do this. Rather, you should set up the container to use transference or other things to remove accumulated contributions. | Environment.removeCumulativeContribution("Ambient Temperature") | |
| setTransferenceMultiplier(environmentID, multiplier) | Increase or decrease the current transference value by multiplier. For example, if you open the door to the house, you may want to speed up the Ambient Temperature convergence with the outside by increasing the container's transference by the multiplier. |
Environment.setTransferenceMultiplier("Ambient Temperature", 2) | |
| getTotalContributions(environmentID) | float | Returns the total value of contributions by all things | Environment.getTotalContributions("Wind Speed") |
| getCumulativeContribution(environmentID) | Returns the cumulativeContribution for just the thing that is calling the function | Environment.getCumulativeContribution("Wind Speed") | |
| getMetricValue(environmentID) | float | Returns the metric value of the environmentID regardless of user preference | Environment.getMetricValue("Ambient Temperature") |
| getValueWithUnit(environmentID) | string | Returns the value in metric or imperial based on the user preference and also append the unit | Environment.getValueWithUnit("Ambient Temperature") |
| getUnit(environmentID) | string | Returns the unit for the environmentID. The unit can be metric or imperial based on the user preferences | Environment.getUnit("Ambient Temperature") |
| getVolume() | float | Returns the volume size of the container in meters^3 that caller of the function is in | Environment.getVolume() |
| getTimeInSeconds() | int | Returns the current time | Environment.getTimeInSeconds(); |
| getElapsedTime(lastTime) | int | Returns the time passed since the lastTime value | var time = Environment.getTimeInSeconds(); delay(1000); Environment.getElapsedTime(time); |
Real HTTP |
Package = realhttp |
||
Function |
Return Type | Description |
Example |
RealHTTPClient() |
RealHTTPClient |
Creates a Real HTTP Client. |
http = RealHTTPClient() |
get(url) |
N/A |
Gets an URL. |
http.get(“http://www.cisco.com”) |
| post(url, data) | N/A |
Posts data to an URL. data can be a string or a dictionary; if dictionary, it will be URL-encoded into the body. |
http.post(url, {"num":1, "str":"hello"}) |
| put(url, data) | N/A |
Puts data to an URL. data can be a string or a dictionary; if dictionary, it will be URL-encoded into the body. |
http.put(url, {"num":1, "str":"hello"}) |
| deleteResource(url) | N/A | Sends a delete to an URL. | http.deleteResource(url) |
| getWithHeader(url, header) | N/A | Gets an URL with custom header fields as a dictionary. | http.getWithHeader("https://api.ciscospark.com/v1/people/me", {"Authorization": "Bearer xxyyzz"}) |
| postWithHeader(url, data, header) | N/A |
Posts data to an URL with custom header fields as a dictionary. data can be a string or a dictionary; if dictionary and custom header field has "application/json" as the "content-type", it will be json-encoded, otherwise it will be URL-encoded into the body. |
http.postWithHeader("https://api.ciscospark.com/v1/messages", {"toPersonId": "722bb271-d7ca-4bce-a9e3-471e4412fa77", "text": "Hi Sparky"}, {"Authorization": "Bearer xxyyzz", "Content-Type": "application/json"}) |
| putWithHeader(url, data, header) | N/A |
Puts data to an URL with custom header fields as a dictionary. data can be a string or a dictionary; if dictionary and custom header field has "application/json" as the "content-type", it will be json-encoded, otherwise it will be URL-encoded into the body. |
http.putWithHeader("https://api.ciscospark.com/v1/rooms/xxyyzz", {"title": "New room name"}, {"Authorization": "Bearer xxyyzz"}) |
| deleteResourceWithHeader(url, header) | N/A | Sends a delete to an URL with custom header fields as a dictionary. | http.deleteResourceWithHeader("https://api.ciscospark.com/v1/messages/xxyyzz", {"Authorization": "Bearer xxyyzz"}) |
|
onDone(callback) |
N/A |
Sets the callback for when the request is done. replyHeader is a dictionary of header fields in the reply. It is added to 7.1 and is optional. |
def onHTTPDone(status, data, replyHeader): ... http.onDone(onHTTPDone) |
Real TCP |
Package = realtcp |
||
Function |
Return Type | Description |
Example |
RealTCPClient() |
RealTCPClient | Creates a Real TCP Client. |
client = RealTCPClient() |
connect(ip, port) |
N/A | Connects to ip and port. |
client.connect("1.1.1.1", 2000) |
| connected() | bool | Returns true if connected. | client.connected() |
close() |
N/A | Disconnects. |
client.close() |
state() |
int | Returns the state of the connection. |
client.state() |
remoteIP() |
str | Returns the remote IP. |
client.remoteIP() |
| remoteHost() | str | Returns the remote server host name. | client.remoteHost() |
remotePort() |
int | Returns the remote port. |
client.remotePort() |
| localIP() | str | Returns the local IP. | client.localIP() |
| localPort() | int | Returns the local port. | client.localPort() |
send(data) |
N/A | Sends data to remote connection. |
client.send("hello") |
| error() | int | Returns the last error code. | client.error() |
| errorString() | str | Returns the last error in string. | client.errorString() |
onReceive(callback) |
N/A | Sets the callback for when data is received. |
def onTCPReceive(data):
print(data) ...
client.onReceive(onTCPReceive)
|
onConnectionChange(callback) |
N/A | Sets the callback for when the connection changes. |
def onTCPConnectionChange(type):
print(type) ...
client.onConnectionChange(onTCPConnectionChange)
|
Real UDP |
Package = realudp |
||
Function |
Return Type | Description |
Example |
RealUDPSocket() |
RealUDPSocket | Creates an Real UDP Socket. |
udp = RealUDPSocket() |
begin(port) |
bool | Starts listening on port. |
udp.begin(2000) |
stop() |
N/A | Stops listening. |
udp.stop() |
| joinMulticastGroup(ip) | bool | Joins a multicast group. Must call begin() first. | udp.joinMulticastGroup("224.0.0.1") |
| leaveMulticastGroup(ip) | bool | Leaves a multicast group. | udp.leaveMulticastGroup("224.0.0.1") |
| localIP() | str | Returns the local IP. | udp.localIP() |
| localPort() | int | Returns the local port. | udp.localPort() |
send(ip, port, data) |
bool | Sends data. |
udp.send("1.1.1.1", 2000, "hello") |
onReceive(callback) |
N/A | Sets the callback for when data is received. |
def onUDPReceive(ip, port, data):
print(data)
...
udp.onReceive(onUDPReceive) |
| error() | int | Returns the last error code. | udp.error() |
| errorString() | str | Returns the last error in string. | udp.errorString() |
JSON |
Package = json |
||
Function |
Return Type | Description |
Example |
dumps(obj) |
str | Serializes a Python object into JSON string. |
jsonStr = json.dumps({"num":1, "s":"str"}) |
loads(jsonStr) |
python object | Converts a JSON string into a Python object. |
obj = json.loads(s) |
GUI (SBC and Thing , some End Devices) |
Package = gui |
||
Function |
Return Type | Description |
Example |
| GUI.setup() | N/A | Initializes the GUI and tells the GUI to display the html file configured in the manifest file. If the app is not installed, it throws an error. | GUI.setup() |
| GUI.update(type, args) | N/A | Asynchronously calls the html file's update() function passing in type and args. Type is a string and args can be any JSON valid object. | GUI.update("status", "playing") |
| guiEvent(type, args) | N/A | If defined, this function is called asynchronously when the html file calls guiEvent(type, args). Type is a string and args can be any JSON valid object. |
def guiEvent(type, args): |
CLI (SBC and Thing , some End Devices) |
Package = cli |
||
Function |
Return Type | Description |
Example |
| CLI.setup() | N/A | Initializes the CLI and will call the cliEvent() function if the app was started from a command in the Command Prompt. | CLI.setup() |
| CLI.exit() | N/A | Exits the CLI mode and returns back to the Command Prompt. | CLI.exit() |
| cliEvent(type, args) | N/A |
If defined, this function is called synchronously when different CLI events happen. Type is a string and args can be any JSON valid object. Type can be:
|
def cliEvent(type, args): |
Simulation |
Package = simulation |
||
Function |
Return Type | Description |
Example |
| Simulation.isInSimulationMode() | bool | Returns whether PT is currently in Simulation Mode. |
if Simulation.isInSimulationMode(): |
| Simulation.addCustomProtocolType(protocol) | bool | Adds a new protocol type to the current file/network. The protocol will show up in the Event List Filters. Returns true if successful, false otherwise. | Simulation.addCustomProtocolType("MyProtocol") |
| Simulation.hasCustomProtocolType(protocol) | bool | Returns whether the protocol type is already added to the current file/network. | if not Simulation.hasCustomProtocolType("MyProtocol"): Simulation.addCustomProtocolType("MyProtocol") |
| Simulation.addCustomPDU(protocol, pduType, definition) | bool |
Adds a new protocol type and PDU type to the current file/network. The protocol will show up in the Event List Filters, and the PDU with its definition will show up in PDU details. Returns true if successful, false if the definition is invalid. It will replace existing definitions if using the same protocol and PDU type names. The definition argument is an object with the following properties describing the layout and fields of the PDU:
|
Simulation.addCustomPDU("MyProtocol", "MyPDU", {
|
| Simulation.hasCustomPDU(protocol, pduType) | bool | Returns whether the protocol and PDU type is already added to the current file/network. |
if not Simulation.hasCustomPDU("MyProtocol", "MyPDU"): |
| PDUInfo(color) | PDUInfo | Creates a PDU Info object with the pdu color. A PDUInfo is required to show PDU with more details in Simulation Mode. | pduInfo = PDUInfo(0xffff00) |
| setOutFormat(protocol, pduType, fields) | N/A | Sets the outgoing PDU to be displayed in a custom PDU definition. The fields argument is an object with the variables defined in the PDU definition fields property. | pduInfo.setOutFormat("MyProtocol", "MyPDU", {"type": "REPLY", "data": data}) |
| addOutMessage(message) | N/A | Adds a message to the outgoing OSI layer 7. | pduInfo.addOutMessage("I am sending some data.") |
| addInMessage(message) | N/A | Adds a message to the incoming OSI layer 7. | pduInfo.addInMessage("I received some data.") |
| setAccepted() | N/A | Sets the PDU as accepted. | pduInfo.setAccepted() |
| setDropped() | N/A | Sets the PDU as dropped. | pduInfo.setDropped() |
Workspace |
Package = workspace |
||
Function |
Return Type | Description |
Example |
|
getPhysicalObject() |
PhysicalObject |
Returns the current device's physical object. |
po = getPhysicalObject() |
|
getName() |
str |
Returns the name of this physical object. |
print(po.getName()) |
|
getType() |
int |
Returns the type of this physical object. Valid values are: INTER_CITY = 0 |
print(po.getType()) |
|
getX() |
float |
Returns the x coordinate relative to its parent in meters. |
print(po.getX()) |
|
getY() |
float |
Returns the y coordinate relative to its parent in meters. |
print(po.getY()) |
|
getCenterX() |
float |
Returns the center x coordinate relative to its parent in meters. |
print(po.getCenterX()) |
|
getCenterY() |
float |
Returns the center y coordinate relative to its parent in meters. |
print(po.getCenterY()) |
|
getGlobalX() |
float |
Returns the global x coordinate of this physical object in meters. |
print(po.getGlobalX()) |
|
getGlobalY() |
float |
Returns the global y coordinate of this physical object in meters. |
print(po.getGlobalX()) |
|
getWidth() |
float |
Returns the width of this physical object in meters. |
print(po.getWidth()) |
|
getHeight() |
float |
Returns the height of this physical object in meters. |
print(po.getHeight()) |
| moveTo(x, y) | N/A | Moves this physical object's top left corner to the specified coordinates in meters relative to its parent. | po.moveTo(10, 20) |
| moveCenterTo(x, y) | N/A | Moves this physical object's center to the specified coordinates in meters relative to its parent. | po.moveCenterTo(10, 20) |
| moveBy(x, y) | N/A | Moves this physical object by the specified coordinates in meters. | po.moveBy(10, 20) |
| setVelocity(x, y) | N/A | Sets this physical object's velocity in meters. This physical object then moves automatically. | po.setVelocity(1, 2) |
|
getXVelocity() |
float |
Returns the x velocity of this physical object in meters. |
print(po.getXVelocity()) |
|
getYVelocity() |
float |
Returns the y velocity of this physical object in meters. |
print(po.getYVelocity()) |
| getParent() | PhysicalObject | Returns this physical object's parent. | parentPO = po.getParent() |
| moveOutOfParent() | bool | Moves this physical object out of its parent to the same level as the parent, and returns whether it was successful. | po.moveOutOfParent() |
| moveInto(name) | bool | Moves this physical object into a container with the specified name that is in the same level as this physical object, and returns whether it was successful. | po.moveInto("Corporate Office") |
| getChildCount() | int | Returns the number of children this physical object has. | print(po.getChildCount()) |
| getChildAt(index) | PhysicalObject | Returns the child physical object at the specified index. | childPO = po.getChildAt(0) |
| getChild(name) | PhysicalObject | Returns the child physical object with the specified name. | childPO = po.getChild("Wiring Closet") |
|
getLogicalObject() |
LogicalObject |
Returns the current device's logical object. |
lo = getLogicalObject() |
|
getName() |
str |
Returns the name of this logical object. |
print(lo.getName()) |
|
getType() |
int |
Returns the type of this logical object. Valid values are: ROOT = 1099 |
print(lo.getType()) |
|
getX() |
int |
Returns the x coordinate relative to its parent in pixels. |
print(lo.getX()) |
|
getY() |
int |
Returns the y coordinate relative to its parent in pixels. |
print(lo.getY()) |
|
getCenterX() |
int |
Returns the center x coordinate relative to its parent in pixels. |
print(lo.getCenterX()) |
|
getCenterY() |
int |
Returns the center y coordinate relative to its parent in pixels. |
print(lo.getCenterY()) |
|
getWidth() |
int |
Returns the width of this logical object in pixels. |
print(lo.getWidth()) |
|
getHeight() |
int |
Returns the height of this logical object in pixels. |
print(lo.getHeight()) |
| moveTo(x, y) | N/A | Moves this logical object's top left corner to the specified coordinates in pixels relative to its parent. | lo.moveTo(10, 20) |
| moveCenterTo(x, y) | N/A | Moves this logical object's center to the specified coordinates in pixels relative to its parent. | lo.moveCenterTo(10, 20) |
| moveBy(x, y) | N/A | Moves this logical object by the specified coordinates in pixels. | lo.moveBy(10, 20) |
| setVelocity(x, y) | N/A | Sets this logical object's velocity in pixels. This logical object then moves automatically. | lo.setVelocity(1, 2) |
|
getXVelocity() |
float |
Returns the x velocity of this logical object in pixels. |
print(lo.getXVelocity()) |
|
getYVelocity() |
float |
Returns the y velocity of this logical object in pixels. |
print(lo.getYVelocity()) |
| getParent() | LogicalObject | Returns this logical object's parent. | parentLO = lo.getParent() |
| moveOutOfParent() | bool | Moves this logical object out of its parent to the same level as the parent, and returns whether it was successful. | lo.moveOutOfParent() |
| moveInto(name) | bool | Moves this logical object into a container with the specified name that is in the same level as this logical object, and returns whether it was successful. | lo.moveInto("Cluster0") |
| getChildCount() | int | Returns the number of children this logical object has. | print(lo.getChildCount()) |
| getChildAt(index) | LogicalObject | Returns the child logical object at the specified index. | childlo = lo.getChildAt(0) |
| getChild(name) | LogicalObject | Returns the child logical object with the specified name. | childlo = lo.getChild("Cluster0") |