opbt Device
Module structure
class device:
def SetOutputMode(self,mode: int) -> int: ...
def GetOutputMode(self) -> int: ...
def UartConfig(self, baudrate: int, parity: str, DataBit: int, StopBit: int): ...
def TransparentModeOn(self): ...
def TransparentModeOff(self): ...
def IecAutoOn(self): ...
def IecAutoOff(self): ...
def UartSendByte(self, ch: int): ...
def UartGetByte(self) -> int: ...
def UartSendString(self, buf: str, len: int): ...
def UartSendStringNoWait(self, buf: str, len: int): ...
def BtUartSendByte(self, ch: int): ...
def BtUartGetByte(self) -> int: ...
def BtUartSendString(self, buf: str, len: int): ...
def BtUartSendStringNoWait(self, buf: str, len: int): ...
def BtUartSendBytes(self, buf: bytes, len: int): ...
def CheckUnlock(self) -> int: ...
def IsUnlocked(self) -> int: ...
def LedSet(self, leds: int, mode: int): ...
def LedBlink(self, leds: int, cnt: int, duty: int, time:int): ...
def GetKeyStatus(self) -> int: ...
def TmosSystemProcess(self): ...
def LcdClear(self): ...
def LcdTextColor(self,fc: int,bc: int): ...
def LcdTextXY(self, x: int,y:int): ...
def LcdPrint(self,str_p: str): ...
def LcdFill(self, xsta: int,ysta: int,xend: int,yend: int,color: int): ...
More functions are being updated continuously…
opbt.device.SetOutputMode()
Overview
Sets the output device for script display. The output method must be set before running the program, similar to how the print function outputs.
Syntax
opbt.device.SetOutputMode(mode)
Parameters
- mode : Integer, between 0 and 3 that indicates the output device for information in the script.
- 0 : Automatically select the default output device
- 1 : Bluetooth device
- 2 : Optical head device
- 3 : Lcd Screen
Return
Returns the current set value (0-3).
Sample
Display “Hello World!” on the LCD screen.
>>> opbt.device.SetOutputMode(3)
>>> print("Hello World!")
opbt.device.GetOutputMode()
Overview
Gets the current output device for display.
Syntax
opbt.device.GetOutputMode()
Parameters
None
Return
- Return integer, between 0 and 3 that indicates the output device for information in the script.
- 0 : Automatically select the default output device
- 1 : Bluetooth device
- 2 : Optical head device
- 3 : Lcd Screen
Sample
>>> a=opbt.device.GetOutputMode()
>>> print("OutputDevice=",a)
OutputDevice= 0
opbt.device.TransparentModeOn()
Overview
Sets the OPBT device to enter transparent transmission mode.
Syntax
opbt.device.TransparentModeOn()
Parameters
None
Return
No return value.
Sample
>>> opbt.device.TransparentModeOn()
opbt.device.TransparentModeOff()
Overview
Set the OPBT device to exit transparent transmission mode.
Syntax
opbt.device.TransparentModeOff()
Parameters
None
Return
No return value.
Sample
>>> opbt.device.TransparentModeOff()
opbt.device.IecAutoOn()
Overview
Set the OPBT device to enter the IEC automatic baud rate switching mode, supporting modes C and E of IEC65026-21.
Syntax
opbt.device.IecAutoOn()
Parameters
None
Return
No return value.
Sample
>>> opbt.device.IecAutoOn()
opbt.device.IecAutoOff()
Overview
Set the OPBT device to exit the IEC automatic baud rate switching mode.
Syntax
opbt.device.IecAutoOff()
Parameters
None
Return
No return value.
Sample
>>> opbt.device.IecAutoOff()
opbt.device.UartConfig()
Overview
Set the serial communication parameters for the optical head.
Syntax
UartConfig(baudrate,parity,databit,stopbit)
Parameters
- baudrate : intger, Baud rate value from 300 to 57600. -Typical values??300,600,1200,2400,4800,9600,19200,38400,57600 etc.
- parity : string, Parity value.
- “N” : None (no parity)
- “E” : Even (even parity)
- “O” : Odd (odd parity)
- Defaults to no parity.
- databit : intger, Data bit length (5-8).
- 5 : 5 data bits
- 6 : 6 data bits
- 7 : 7 data bits
- 8 : 8 data bits
- Defaults to 8 data bits.
- stopbit : intger,Stop bits (1-2).
- 1 : 1 stop bit
- 2 : 2 stop bits
- Defaults to 1 stop bit.
Return
No return value.
Sample
Set the serial port baud rate to 9600 bps, no parity, data bit length to 8, and stop bit to 1.
>>> opbt.device.UartConfig(9600,"N",8,1)
opbt.device.UartSendByte()
Overview
Sends a single byte of data using the configured serial parameters.
Syntax
opbt.device.UartSendByte(ch)
Parameters
- ch : intger?? the byte code of the data to be sent.
Return
No return value.
Sample
Send the data “123” .
>>> opbt.device.UartConfig(9600,"N",8,1)
>>> opbt.device.UartSendByte(49)
>>> opbt.device.UartSendByte(50)
>>> opbt.device.UartSendByte(51)
opbt.device.UartGetByte()
Overview
Retrieves a single byte of data from the serial port.
Syntax
opbt.device.UartGetByte()
Parameters
None
Return
- Returns an integer value:
- -1 : No data received
- Other values: Byte code
Sample
>>> opbt.device.UartConfig(9600,"N",8,1)
>>> ch=opbt.device.UartGetByte()
>>> print(ch)
-1
opbt.device.UartSendString()
Overview
Sends a specified length of string data using the configured serial parameters and waits until the last data is sent before returning.
Syntax
opbt.device.UartSendString(string,length)
Parameters
- string : String, the data to be sent.
- length : Integer, the length of the data to be sent.
Return
No return value.
Sample
Send the data “123”:
>>> opbt.device.UartConfig(9600,"N",8,1)
>>> opbt.device.UartSendString("123",3)
opbt.device.UartSendStringNoWait()
Overview
Sends a specified length of string data using the configured serial parameters, returning immediately after the data is sent. If the serial parameters are changed at this time, it may corrupt the previously buffered data that has not yet been sent.
Syntax
opbt.device.UartSendStringNoWait(string,length)
Parameters
- string : String, the data to be sent.
- length : Integer, the length of the data to be sent.
Return
No return value.
Sample
Send the data “123”:
>>> opbt.device.UartConfig(9600,"N",8,1)
>>> opbt.device.UartSendStringNoWait("123",3)
opbt.device.BtUartSendByte()
Overview
Sends a single byte of data through the Bluetooth serial port.
Syntax
opbt.device.BtUartSendByte(ch)
Parameters
- ch : Integer, the byte code of the data to be sent.
Return
No return value.
Sample
Send the data “123” through Bluetooth serial port:
#!pika
opbt.device.SetOutputMode(1) # Set output to Bluetooth
opbt.device.BtUartSendByte(49) # Send character '1'
opbt.device.BtUartSendByte(50) # Send character '2'
opbt.device.BtUartSendByte(51) # Send character '3'
#!pika
opbt.device.BtUartGetByte()
Overview
Reads a single byte of data from the Bluetooth serial port.
Syntax
opbt.device.BtUartGetByte()
Parameters
None
Return
- Returns an integer value:
- -1 : No data received
- Other values: Byte code
Sample
Read data from Bluetooth serial port:
#!pika
opbt.device.SetOutputMode(1) # Set output to Bluetooth
ch = opbt.device.BtUartGetByte()
if ch != -1:
print("Received:", ch)
else:
print("No data received")
#!pika
opbt.device.BtUartSendString()
Overview
Sends a specified length of string data through the Bluetooth serial port and waits until the last data is sent before returning (blocking mode).
Syntax
opbt.device.BtUartSendString(string,length)
Parameters
- string : String, the data to be sent.
- length : Integer, the length of the data to be sent.
Return
No return value.
Sample
Send the data “Hello” through Bluetooth serial port:
#!pika
opbt.device.SetOutputMode(1) # Set output to Bluetooth
opbt.device.BtUartSendString("Hello", 5)
#!pika
opbt.device.BtUartSendStringNoWait()
Overview
Sends a specified length of string data through the Bluetooth serial port, returning immediately after the data is sent (non-blocking mode).
Syntax
opbt.device.BtUartSendStringNoWait(string,length)
Parameters
- string : String, the data to be sent.
- length : Integer, the length of the data to be sent.
Return
No return value.
Sample
Send the data “Hello” through Bluetooth serial port in non-blocking mode:
#!pika
opbt.device.SetOutputMode(1) # Set output to Bluetooth
opbt.device.BtUartSendStringNoWait("Hello", 5)
# Returns immediately without waiting for transmission to complete
#!pika
opbt.device.BtUartSendBytes()
Overview
Sends byte data through the Bluetooth serial port, skipping the protocol header and sending raw byte data directly.
Syntax
opbt.device.BtUartSendBytes(buf,length)
Parameters
- buf : bytes type, the byte data to be sent.
- length : Integer, the length of the data to be sent.
Return
No return value.
Sample
Send byte data through Bluetooth serial port:
#!pika
opbt.device.SetOutputMode(1) # Set output to Bluetooth
data = b'\x01\x02\x03\x04\x05'
opbt.device.BtUartSendBytes(data, len(data))
#!pika
opbt.device.CheckUnlock()
Overview
Checks device unlock status. If security is enabled (SecurityEnable) and the device is not unlocked, the LCD password input screen is shown for user verification; if security is disabled or already unlocked, returns success immediately. Requires firmware 4.84 or later.
Syntax
opbt.device.CheckUnlock()
Parameters
None
Return
- 1 : Unlocked or security disabled, can proceed
- 0 : User canceled or verification failed
Sample
Verify unlock before sensitive operations:
>>> if opbt.device.CheckUnlock() != 1:
... print("Unlock canceled")
... else:
... print("Proceed")
opbt.device.IsUnlocked()
Overview
Queries whether the device is currently unlocked only; does not show the password screen. Requires firmware 4.84 or later.
Syntax
opbt.device.IsUnlocked()
Parameters
None
Return
- 1 : Unlocked
- 0 : Locked
Sample
>>> r = opbt.device.IsUnlocked()
>>> print(r)
1
opbt.device.LedSet()
Overview
Turn ON/OFF/TOGGLE given LEDs
Syntax
opbt.device.LedSet(leds,mode)
Parameters
- leds : intger, bit mask value of leds to be turned ON/OFF/TOGGLE
- 0x01 : Green indicator light on the left side of the screen
- 0x02 : Red indicator light on the left side of the screen
- 0x04 : Blue indicator light on the left side of the screen
- 0x08 : Green indicator light on the right side of the screen
- 0x10 : Red indicator light on the right side of the screen
- 0x20 : Blue indicator light on the right side of the screen
- 0x40 : Flashlight
- mode : integer ,TOGGLE, ON, OFF
- 0 : Off
- 1 : On
- 2 : blink equivalent to ledBlink(leds,1,5,1000)
- 4 : flash equivalent to ledBlink(leds,50,5,1000)
- 8 : toggle
Return
No return value.
Sample
Turn on the red indicator light on the left and the blue indicator light on the right.
>>> opbt.device.LedSet(0xff,0) # First, turn off all indicator lights
>>> opbt.device.LedSet(0x02|0x20,1)
opbt.device.LedBlink()
Overview
Blinks the LEDs, requires support from SystemProcess().
Syntax
opbt.device.LedBlink(leds,cnt,duty,time)
Parameters
- leds : intger, bit mask value of leds to be turned ON/OFF/TOGGLE
- 0x01 : Green indicator light on the left side of the screen
- 0x02 : Red indicator light on the left side of the screen
- 0x04 : Blue indicator light on the left side of the screen
- 0x08 : Green indicator light on the right side of the screen
- 0x10 : Red indicator light on the right side of the screen
- 0x20 : Blue indicator light on the right side of the screen
- 0x40 : Flashlight
- cnt : Integer, number of blinks
- duty : Integer, the percentage in each period where the led will be on
- time : Integer, length of each cycle in milliseconds
Return
No return value.
Sample
Make the red light on the left blink.
opbt.device.LedSet(0xff,0)
opbt.device.LedBlink(0x02,10,50,300)
for i in range(500):
opbt.device.SystemProcess()
opbt.device.LedSet(0xff,0)
opbt.device.GetKeyStatus()
Overview
Read the current value of a key
Syntax
opbt.device.GetKeyStatus()
Parameters
??
Return
- current keys status
- bit 1 : =1 if the right key is pressed.
- bit 2 : =1 if the left key is pressed.
Sample
>>> k=opbt.device.GetKeyStatus()
>>> print(k)
0
opbt.device.SystemProcess()
Overview
OPBT system processing function that needs to be continuously run in the main function.
Syntax
opbt.device.SystemProcess()
Parameters
None
Return
No return value.
Sample
opbt.device.LedSet(0xff,0)
opbt.device.LedBlink(0x02,10,50,300)
for i in range(500):
opbt.device.SystemProcess()
opbt.device.LedSet(0xff,0)
opbt.device.LcdClear()
Overview
Clears the LCD screen.
Syntax
opbt.device.LcdClear()
Parameters
None
Return
No return value.
Sample
opbt.device.LcdClear()
opbt.device.LcdTextColor()
Overview
Sets the text display color on the LCD screen.
Syntax
opbt.device.LcdTextColor(fc,bc)
Parameters
- fc : Integer, foreground color.
- bc : Integer, background color.
- Color values
- 0xFFFF : White
- 0x0000 : Black
- 0x001F : Blue
- 0xF800 : Red
- 0x07E0 : Green
- 0xFFE0 : Yellow
- 0xFD20 : Orange
- 0xBC40 : Brown
- 0x8430 : Gray
- 0xF81F : BRED
- 0xFFE0 : GRED
- 0x07FF : GBLUE
- 0xF81F : MAGENTA
- 0x7FFF : CYAN
- 0xFC07 : BRRED
- 0x01CF : Dark Blue
- 0x7D7C : Light Blue
- 0x5458 : Gray Blue
- 0x841F : Light Green
- 0xC618 : Light Gray
- 0xA651 : Light Gray Blue
- 0x2B12 : Light Blue
Return
No return value.
Sample
Set the text color to red and the background to black.
opbt.device.LcdClear()
opbt.device.LcdTextColor(0xf800,0x0000)
opbt.device.LcdPrint("Hello World!")
opbt.device.LcdTextXY()
Overview
Sets the coordinates for displaying text on the LCD screen.
Syntax
opbt.device.LcdTextXY(x,y)
Parameters
- x : Integer, range is 0-19.
- y : Integer, range is 0-4.
Return
No return value.
Sample
opbt.device.LcdClear()
opbt.device.LcdTextColor(0xf800,0x0000)
opbt.device.LcdTextXY(5,2)
opbt.device.LcdPrint("Hello World!")
opbt.device.LcdPrint()
Overview
Displays a string on the LCD screen.
Syntax
opbt.device.LcdPrint(strp)
Parameters
- strp : String, the string to be displayed.
Return
No return value.
Sample
opbt.device.LcdClear()
opbt.device.LcdTextColor(0xf800,0x0000)
opbt.device.LcdTextXY(5,2)
opbt.device.LcdPrint("Hello World!")
opbt.device.LcdFill()
Overview
Fills a specified color within a rectangular area.
Syntax
opbt.device.LcdFill(xsta,ysta,xend,yend,color)
Parameters
- xsta : Integer, the x-coordinate of the top-left corner, range is 0-159.
- ysta : Integer, the y-coordinate of the top-left corner, range is 0-79.
- xend : Integer, the x-coordinate of the bottom-right corner, range is 0-159.
- yend : Integer, the y-coordinate of the bottom-right corner, range is 0-79.
- color : Integer, color value (refer to LcdTextColor() for options).
Return
No return value.
Sample
opbt.device.LcdClear()
opbt.device.LcdFill(10,20,50,60,0xffff)