Device Script Guide: Device Control

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 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): ...

ຯ…

opbt.device.SetOutputMode()

Overview

ýűʾ豸ʱҪķʽprint

Syntax

opbt.device.SetOutputMode(mode)

Parameters

  • mode : 0-3ֵʾűϢ豸
    • 0 : ԶѡĬϵ豸
    • 1 :
    • 2 : ͷ
    • 3 : Ļʾ

Return

صǰõֵ(0-3)

Sample

LCDĻʾ Hello World!

>>> opbt.device.SetOutputMode(3)
>>> print("Hello World!")

opbt.device.GetOutputMode()

Overview

õǰʾ豸

Syntax

opbt.device.GetOutputMode()

Parameters

Return

  • صǰõֵ(0-3)
    • 0 : ԶѡĬϵ豸
    • 1 :
    • 2 : ͷ
    • 3 : Ļʾ

Sample

>>> a=opbt.device.GetOutputMode()
>>> print("OutputDevice=",a)
OutputDevice= 0

opbt.device.TransparentModeOn()

Overview

OPBT豸͸䷽ʽ

Syntax

opbt.device.TransparentModeOn()

Parameters

Return

Sample

>>> opbt.device.TransparentModeOn()

opbt.device.TransparentModeOff()

Overview

OPBT豸˳͸䷽ʽ

Syntax

opbt.device.TransparentModeOff()

Parameters

Return

Sample

>>> opbt.device.TransparentModeOff()

opbt.device.IecAutoOn()

Overview

OPBT豸IecԶлģʽ֧IEC65026ķʽCE

Syntax

opbt.device.IecAutoOn()

Parameters

Return

Sample

>>> opbt.device.IecAutoOn()

opbt.device.IecAutoOff()

Overview

OPBT豸˳IecԶлģʽ

Syntax

opbt.device.IecAutoOff()

Parameters

Return

Sample

>>> opbt.device.IecAutoOff()

opbt.device.UartConfig()

Overview

ùͷ˵ĴͨѶ

Syntax

UartConfig(baudrate,parity,databit,stopbit)

Parameters

  • baudrate ֵ300-57600intger -ֵ300,600,1200,2400,4800,9600,19200,38400,57600
  • parity Уֵ, string
    • “N” : None Уλ
    • “E” : Even żУλ
    • “O” : Odd λ
    • ĬΪУλ
  • databit λ(5-8),ֵ
    • 5 : λΪ5λ
    • 6 : λΪ6λ
    • 7 : λΪ7λ
    • 8 : λΪ8λ
    • ĬλΪ8λ
  • stopbit ֹͣλ(1-2),ֵ
    • 1 : ֹͣλΪ1
    • 2 : ֹͣλΪ2
    • ĬֹͣλΪ1

Return

޷ֵ

Sample

ôڲΪ9600bpsУλλΪ8ֹͣλΪ1

>>> opbt.device.UartConfig(9600,"N",8,1)

opbt.device.UartSendByte()

Overview

úõĴڲһֽݳȥ

Syntax

opbt.device.UartSendByte(ch)

Parameters

  • ch : intger ͵ݵֽڴ

Return

Sample

"123"

>>> opbt.device.UartConfig(9600,"N",8,1)
>>> opbt.device.UartSendByte(49)
>>> opbt.device.UartSendByte(50)
>>> opbt.device.UartSendByte(51)

opbt.device.UartGetByte()

Overview

Ӵȡһֽ

Syntax

opbt.device.UartGetByte()

Parameters

Return

  • ֵ
    • -1 : ûнյ
    • ֵ : ֽڴ

Sample

>>> opbt.device.UartConfig(9600,"N",8,1)
>>> ch=opbt.device.UartGetByte()
>>> print(ch)
-1

opbt.device.UartSendString()

Overview

úõĴڲָȵַȥȴһݷɲŷ

Syntax

opbt.device.UartSendString(string,length)

Parameters

  • string : ַ,͵ַ
  • length : ֵ,ݵij

Return

Sample

"123"

>>> opbt.device.UartConfig(9600,"N",8,1)
>>> opbt.device.UartSendString("123",3)

opbt.device.UartSendStringNoWait()

Overview

úõĴڲָȵַȥݷϷأʱĴڲпƻ֮ǰڻδ͵

Syntax

opbt.device.UartSendStringNoWait(string,length)

Parameters

  • string : ַ,͵ַ
  • length : ֵ,ݵij

Return

Sample

"123"

>>> opbt.device.UartConfig(9600,"N",8,1)
>>> opbt.device.UartSendStringNoWait("123",3)

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 : Ļߵɫָʾ
    • 0x02 : Ļߵĺɫָʾ
    • 0x04 : Ļߵɫָʾ
    • 0x08 : Ļұߵɫָʾ
    • 0x10 : Ļұߵĺɫָʾ
    • 0x20 : Ļұߵɫָʾ
    • 0x40 : ֵͲ
  • mode : ֵ,TOGGLE, ON, OFF
    • 0 : Off
    • 1 : On
    • 2 : blink ЧledBlink(leds,1,5,1000)
    • 4 : flash ЧledBlink(leds,50,5,1000)
    • 8 : toggle

Return

Sample

ߵĺɫұߵɫָʾ

>>> opbt.device.LedSet(0xff,0)  # �ȹر�����ָʾ��
>>> opbt.device.LedSet(0x02|0x20,1)

Overview

Blink the leds, ҪTmosSystemProcess֧

Syntax

opbt.device.LedBlink(leds,cnt,duty,time)

Parameters

  • leds : ֵ,bit mask value of leds to be turned ON/OFF/TOGGLE
    • 0x01 : Ļߵɫָʾ
    • 0x02 : Ļߵĺɫָʾ
    • 0x04 : Ļߵɫָʾ
    • 0x08 : Ļұߵɫָʾ
    • 0x10 : Ļұߵĺɫָʾ
    • 0x20 : Ļұߵɫָʾ
    • 0x40 : ֵͲ
  • cnt : ֵ, number of blinks
  • duty : ֵ, the percentage in each period where the led will be on
  • time : ֵ, length of each cycle in milliseconds

Return

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.GetKeyStatus()

Overview

Read the current value of a key

Syntax

opbt.device.GetKeyStatus()

Parameters

Return

  • current keys status
    • bit 1 : =1 Ҽ
    • bit 2 : =1

Sample

>>> k=opbt.device.GetKeyStatus()
>>> print(k)
0

opbt.device.SystemProcess()

Overview

opbtϵͳ,Ҫ

Syntax

opbt.device.SystemProcess()

Parameters

Return

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

LCDĻ

Syntax

opbt.device.LcdClear()

Parameters

Return

Sample

opbt.device.LcdClear()

opbt.device.LcdTextColor()

Overview

LCDĻʾɫ

Syntax

opbt.device.LcdTextColor(fc,bc)

Parameters

  • fc : ֵ,ǰɫ
  • bc : ֵ,ɫ
  • ɫֵ
    • 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 : DRAKBLUE
    • 0x7D7C : LIGHTBLUE
    • 0x5458 : GRAYBLUE
    • 0x841F : LIGHTGREEN
    • 0xC618 : LGRAY
    • 0xA651 : LGRAYBLUE
    • 0x2B12 : LBBLUE

Return

Sample

ĻɫΪɫֱΪɫ

opbt.device.LcdClear()
opbt.device.LcdTextColor(0xf800,0x0000)
opbt.device.LcdPrint("Hello World!")

opbt.device.LcdTextXY()

Overview

LCDĻʾ

Syntax

opbt.device.LcdTextXY(x,y)

Parameters

  • x : ֵ,Χ0-19
  • y : ֵ,Χ0-4

Return

Sample

opbt.device.LcdClear()
opbt.device.LcdTextColor(0xf800,0x0000)
opbt.device.LcdTextXY(5,2)
opbt.device.LcdPrint("Hello World!")

opbt.device.LcdPrint()

Overview

LCDĻʾַ

Syntax

opbt.device.LcdPrint(strp)

Parameters

  • strp : ַ, ʾַ

Return

Sample

opbt.device.LcdClear()
opbt.device.LcdTextColor(0xf800,0x0000)
opbt.device.LcdTextXY(5,2)
opbt.device.LcdPrint("Hello World!")

opbt.device.LcdFill()

Overview

ھοָɫ

Syntax

opbt.device.LcdFill(xsta,ysta,xend,yend,color)

Parameters

  • xsta : ֵ,Ͻx꣬Χ0-159
  • ysta : ֵ,Ͻy꣬Χ0-79
  • xend : ֵ,Ͻx꣬Χ0-159
  • yend : ֵ,Ͻy꣬Χ0-79
  • color : ֵɫֵοLcdTextColor()

Return

Sample

opbt.device.LcdClear()
opbt.device.LcdFill(10,20,50,60,0xffff)