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�ķ�ʽC��E

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-57600��intger -����ֵ��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)