pyboard

package module
v0.0.0-...-dc55161 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

README

pyboard

Go语言实现的MicroPython工程中的pyboard类,用于连接开发板设备。

使用方法:

import "gitee.com/sanshentech/pyboard"

// 扫描端口号
portList, err := pyboard.PortList()
if err != nil {
    log.Fatalln(err)
}
if len(portList) == 0 {
    log.Fatalln("port not found")
}
port := portList[0]

// 连接开发板
cli, err := pyboard.New(portList[0])
if err != nil {
    log.Fatalln(err)
}

// 发送指令,注意一定要处理函数内部panic的错误,否则应用会崩溃
defer func() {
    if err, ok := recover().(error); ok {
        log.Fatalln(err)
    }
}()
cli.EnterRawRepl()
rsp, errMsg := cli.Exec(code)
log.Println(rsp, errMsg)
cli.ExitRawRepl()

mpy-cross跨平台编译方法:

  • 安装:pip install -U mpy-cross
  • 使用:mpy-cross -march=[ARCH] [FILE].py
  • 生成:同名的.mpy二进制文件
  • 注意:main.py不需要编译,因为开发板启动时会自动查找该文件名

参考内容:

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PortList

func PortList() (ports []string, err error)

获取端口号列表

Types

type Pyboard

type Pyboard struct {
	// contains filtered or unexported fields
}

对应Pyboard类

func New

func New(device string) (*Pyboard, error)

新建一个串口连接,对应__init__初始化

func NewWithParams

func NewWithParams(
	device string,
	baudrate int,
) (cli *Pyboard, err error)

新建一个串口连接,对应__init__初始化

func (*Pyboard) Close

func (pyb *Pyboard) Close()

关闭连接

func (*Pyboard) EnterRawRepl

func (pyb *Pyboard) EnterRawRepl()

进入RawRepl模式,对应enter_raw_repl函数

func (*Pyboard) Exec

func (pyb *Pyboard) Exec(command string) (ret string, err string)

执行程序,对应exec_/exec函数

func (*Pyboard) ExitRawRepl

func (pyb *Pyboard) ExitRawRepl()

退出RawRepl模式

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL