Documentation

← back to Oculus Prime Contents

Oculus Prime - Python Module

The Oculus Prime Python module, that you can import into your own python scripts, handles connection and conversation with the Oculus Prime Server Application. It connects to the server via the Telnet API, and supplies a handful of convenience conversing functions.

The module is the file oculusprimesocket.py. You can find the current version in the Oculus Prime ROS repository: oculusprime_ros/src/oculusprimesocket.py

The module uses the standard Python socket interface to connect with the server. Once connected, it creates a file object using socket.makefile, to simplify conversing using newline-terminated blocks of text back and forth.

Useage

At the top of any python script, import the module by adding the line

import oculusprimesocket

NOTE: a copy of the module file needs to be in the same folder as your script.

If not connecting to the oculus prime server at localhost, specify a different address by adding the line:

oculusprimesocket.host = "192.168.0.99"

Substituting your preferred IP address or hostname.

Next, before you can converse with the server, your script has to call:

oculusprimesocket.connect()

Now your script should be connected, and able to use the module’s conversation functions.


Variables

host
Server host address (default is "127.0.0.1")

port
Server host port (default is 4444)

connected
(Boolean) server connection status

reconnect
(Boolean) persistent server connection, keep trying if server unavailable

Available Functions

clearIncoming()
Clear socket buffer of all incoming server messages

connect()
Make socket connection to server, blocking
Returns: True on successful connect, False otherwise

replyBufferSearch(pattern)
Search through unread output from server, compare to pattern, return match
pattern — regular expression pattern to be searched
Returns: first line containing match, or empty string if search fails
non blocking function

sendString(str)
Send single line command to server
str — command to be sent

waitForReplySearch(pattern)
Read all incoming messages from server, do not return until search match
pattern — regular expression pattern to be searched
Returns: first line containing match, or empty string if server connection drops
blocking function

Example

The following Python script imports the oculusprimesocket module. Then it connects to the Oculus Prime Server running on the same machine, turns on the camera using the publish command, then requests the ambient light level using the getlightlevel command.

It uses the module’s waitForReplySearch() function to wait for the server to write the result to the lightlevel state variable, then turns on the light if it’s too dark using the spotlight command.

It then disconnects and exits.


NEXT: More Script Examples

← back to Oculus Prime Contents


CART 0 items | US$
    Check Order Status
Follow →
instagram twitter facebook youtube
© 2024 Xaxxon
Products Documentation Downloads Source Code
Warranty & Returns About Us Contact/Support News
instagram twitter facebook youtube