BrightScript Quick Reference#
Quick lookup for BrightScript objects, methods, and functions.
Core Objects#
System Objects#
| Object | Purpose | Key Methods |
|---|
roDeviceInfo | Device information | GetModel(), GetDeviceUniqueId(), GetVersion() |
roSystemTime | System clock | SetTimeZone(), GetLocalDateTime() |
roDateTime | Date/time operations | ToIsoString(), AsSeconds(), GetYear() |
roMessagePort | Event queue | Used with wait() |
roTimer | Timed events | SetElapsed(), Start(), Stop(), GetIdentity() |
| Object | Purpose | Key Methods |
|---|
roVideoPlayer | Video playback | PlayFile(), Pause(), Resume(), Stop(), Seek() |
roAudioPlayer | Audio playback | PlayFile(), Stop(), SetVolume() |
roImagePlayer | Image display | DisplayFile(), SetTransition() |
roVideoMode | Display settings | SetMode(), GetResX(), GetResY() |
Network Objects#
| Object | Purpose | Key Methods |
|---|
roUrlTransfer | HTTP client | SetUrl(), GetToString(), PostFromString() |
roNetworkConfiguration | Network config | SetDHCP(), SetIP4Address(), Apply() |
roHttpServer | HTTP server | AddGetFromEvent(), SetPort() |
roDatagramSocket | UDP socket | Send(), SetAddress() |
roStreamSocket | TCP socket | Connect(), Send(), Receive() |
Storage Objects#
| Object | Purpose | Key Methods |
|---|
roReadFile | Read files | ReadLine(), AtEof() |
roCreateFile | Create files | SendLine(), Flush() |
roAppendFile | Append files | SendLine(), Flush() |
roByteArray | Binary data | ReadFile(), WriteFile(), ToBase64String() |
roStorageInfo | Storage info | GetDriveTotalSize(), GetDriveFreeSpace() |
roRegistrySection | Registry access | Read(), Write(), Flush(), Exists() |
Hardware Objects#
| Object | Purpose | Key Methods |
|---|
roGpioControlPort | GPIO control | SetOutputState(), SetWholeState() |
roSerialPort | Serial comm | SendLine(), GetLine() |
HTML Objects#
| Object | Purpose | Key Methods |
|---|
roHtmlWidget | HTML display | SetPort(), PostJSMessage(), SetUrl() |
Global Functions#
File Operations#
content$ = ReadAsciiFile(filename$)
WriteAsciiFile(filename$, content$)
files = ListDir(directory$)
files = MatchFiles(directory$, pattern$)
CreateDirectory(path$)
DeleteFile(path$)
MoveFile(source$, dest$)
CopyFile(source$, dest$)
String Functions#
length = Len(string$)
upper$ = UCase(string$)
lower$ = LCase(string$)
left$ = Left(string$, count)
right$ = Right(string$, count)
mid$ = Mid(string$, start, length)
Type Conversion#
str$ = Str(number) ' Number to string (with space)
str$ = number.ToStr() ' Number to string (no space)
num = Val(string$) ' String to number
json$ = FormatJson(object) ' Object to JSON
object = ParseJson(json$) ' JSON to object
Utility#
type$ = type(variable) ' Get type name
sleep(milliseconds) ' Pause execution
RebootSystem() ' Reboot player
Event Types#
| Event Type | Source | Key Methods |
|---|
roTimerEvent | roTimer | GetSourceIdentity() |
roVideoEvent | roVideoPlayer | GetInt() (event code) |
roAudioEvent | roAudioPlayer | GetInt() |
roUrlEvent | roUrlTransfer | GetResponseCode(), GetString() |
roHttpEvent | roHttpServer | GetMethod(), GetUrl() |
roGpioButton | roGpioControlPort | GetInt() (button ID) |
roHtmlWidgetEvent | roHtmlWidget | QueryData() |
Video Event Codes#
| Code | Event |
|---|
| 1 | Start of stream |
| 3 | Playing |
| 4 | Paused |
| 5 | Resumed |
| 8 | Media ended |
| 19 | Failed |
| 30 | Time hit |
HTTP Response Codes#
| Code | Meaning |
|---|
| 200 | OK |
| 201 | Created |
| 204 | No Content |
| 301/302 | Redirect |
| 400 | Bad Request |
| 401 | Unauthorized |
| 403 | Forbidden |
| 404 | Not Found |
| 500 | Server Error |
| < 0 | BrightSign error |
Common Patterns#
Event Loop#
msgPort = CreateObject("roMessagePort")
while true
msg = wait(0, msgPort)
if type(msg) = "roVideoEvent" then
HandleVideoEvent(msg)
end if
end while
Factory Function#
Function newPlayer() As Object
return {
video: CreateObject("roVideoPlayer"),
play: Function(file$) As Void
m.video.PlayFile(file$)
End Function
}
End Function
Configuration Load#
json$ = ReadAsciiFile("SD:/config.json")
config = ParseJson(json$)
if config = invalid then config = {}