|
|
@@ -7,13 +7,13 @@
|
|
|
#### **rtthread** – 系统相关函数
|
|
|
`rtthread` 模块提供了与 rt-thread 操作系统相关的功能,如查看栈使用情况等。
|
|
|
|
|
|
-- rtthread.current_tid()
|
|
|
+- rtthread.current_tid()
|
|
|
返回当前线程的 id 。
|
|
|
|
|
|
-- rtthread.is_preempt_thread()
|
|
|
+- rtthread.is_preempt_thread()
|
|
|
返回是否是可抢占线程。
|
|
|
|
|
|
-- rtthread.stacks_analyze()
|
|
|
+- rtthread.stacks_analyze()
|
|
|
返回当前系统线程和栈使用信息。
|
|
|
|
|
|
`example`:
|
|
|
@@ -44,24 +44,24 @@ timer 4 suspend 0x00000080 0x00000200 25% 0x00000009 000
|
|
|
|
|
|
`函数`
|
|
|
|
|
|
-- utime.sleep(seconds)
|
|
|
+- utime.sleep(seconds)
|
|
|
休眠指定的时间(秒),Seconds 可以是浮点数。注意有些版本的 MicroPython不支持浮点数,为了兼容可以使用 sleep_ms() 和 ``sleep_us()``函数。
|
|
|
|
|
|
-- utime.sleep_ms(ms)
|
|
|
+- utime.sleep_ms(ms)
|
|
|
延时指定毫秒,参数不能小于0。
|
|
|
|
|
|
-- utime.sleep_us(us)
|
|
|
+- utime.sleep_us(us)
|
|
|
延时指定微秒,参数不能小于0。
|
|
|
|
|
|
-- utime.ticks_ms()
|
|
|
+- utime.ticks_ms()
|
|
|
返回不断递增的毫秒计数器,在某些值后会重新计数(未指定)。计数值本身无特定意义,只适合用在``ticks_diff()``。
|
|
|
|
|
|
注:执行标准数学运算(+,-)或关系运算符(<,>,>,> =)直接在这些值上会导致无效结果。执行数学运算然后传递结果作为论据来`ticks_diff()` 或 ` ticks_add() ` 也将导致后一个函数的无效结果。
|
|
|
|
|
|
-- utime.ticks_us()
|
|
|
+- utime.ticks_us()
|
|
|
和上面 ticks_ms() 类似,只是返回微秒。
|
|
|
|
|
|
-- utime.ticks_cpu()
|
|
|
+- utime.ticks_cpu()
|
|
|
与 ticks_ms() 和 ticks_us() 类似,具有更高精度 (使用 CPU 时钟)。
|
|
|
|
|
|
- 可用性:并非每个端口都实现此功能。
|
|
|
@@ -87,45 +87,45 @@ timer 4 suspend 0x00000080 0x00000200 25% 0x00000009 000
|
|
|
|
|
|
`函数`
|
|
|
|
|
|
-- sys.exit(retval=0)
|
|
|
+- sys.exit(retval=0)
|
|
|
终止当前程序给定的退出代码。 函数会抛出 SystemExit 异常。
|
|
|
|
|
|
-- sys.print_exception(exc, file=sys.stdout)
|
|
|
+- sys.print_exception(exc, file=sys.stdout)
|
|
|
打印异常与追踪到一个类似文件的对象 file (或者缺省 sys.stdout ).
|
|
|
|
|
|
`常数`
|
|
|
|
|
|
-- sys.argv
|
|
|
+- sys.argv
|
|
|
当前程序启动时参数的可变列表。
|
|
|
|
|
|
-- sys.byteorder
|
|
|
+- sys.byteorder
|
|
|
系统字节顺序 (“little” or “big”).
|
|
|
|
|
|
-- sys.implementation
|
|
|
+- sys.implementation
|
|
|
使用当前Python实现的。对于micropython,它具有以下属性:
|
|
|
|
|
|
-- sys.modules
|
|
|
+- sys.modules
|
|
|
加载模块字典。在一部分环境中它可能不包含内置模块。
|
|
|
|
|
|
-- sys.path
|
|
|
+- sys.path
|
|
|
搜索导入模块的可变目录列表。
|
|
|
|
|
|
-- sys.platform
|
|
|
+- sys.platform
|
|
|
返回当前操作系统信息。
|
|
|
|
|
|
-- sys.stderr
|
|
|
+- sys.stderr
|
|
|
标准错误流。
|
|
|
|
|
|
-- sys.stdin
|
|
|
+- sys.stdin
|
|
|
标准输入流。
|
|
|
|
|
|
-- sys.stdout
|
|
|
+- sys.stdout
|
|
|
标准输出流。
|
|
|
|
|
|
-- sys.version
|
|
|
+- sys.version
|
|
|
符合的Python语言版本,如字符串。
|
|
|
|
|
|
-- sys.version_info
|
|
|
+- sys.version_info
|
|
|
Python 语言版本,实现符合,作为一个元组的值。
|
|
|
|
|
|
`example`:
|
|
|
@@ -161,126 +161,126 @@ stat unlink mount umount
|
|
|
|
|
|
`函数`
|
|
|
|
|
|
-- math.acos(x)
|
|
|
+- math.acos(x)
|
|
|
返回 ``x`` 的反余弦。
|
|
|
|
|
|
-- math.acosh(x)
|
|
|
+- math.acosh(x)
|
|
|
返回 ``x`` 的逆双曲余弦。
|
|
|
|
|
|
-- math.asin(x)
|
|
|
+- math.asin(x)
|
|
|
返回 ``x`` 的反正弦。
|
|
|
|
|
|
-- math.asinh(x)
|
|
|
+- math.asinh(x)
|
|
|
返回``x`` 的逆双曲正弦。
|
|
|
|
|
|
-- math.atan(x)
|
|
|
+- math.atan(x)
|
|
|
返回 ``x`` 的逆切线。
|
|
|
|
|
|
-- math.atan2(y, x)
|
|
|
+- math.atan2(y, x)
|
|
|
Return the principal value of the inverse tangent of y/x.
|
|
|
|
|
|
-- math.atanh(x)
|
|
|
+- math.atanh(x)
|
|
|
Return the inverse hyperbolic tangent of x.
|
|
|
|
|
|
-- math.ceil(x)
|
|
|
+- math.ceil(x)
|
|
|
Return an integer, being x rounded towards positive infinity.
|
|
|
|
|
|
-- math.copysign(x, y)
|
|
|
+- math.copysign(x, y)
|
|
|
Return x with the sign of y.
|
|
|
|
|
|
-- math.cos(x)
|
|
|
+- math.cos(x)
|
|
|
Return the cosine of x.
|
|
|
|
|
|
-- math.cosh(x)
|
|
|
+- math.cosh(x)
|
|
|
Return the hyperbolic cosine of x.
|
|
|
|
|
|
-- math.degrees(x)
|
|
|
+- math.degrees(x)
|
|
|
Return radians x converted to degrees.
|
|
|
|
|
|
-- math.erf(x)
|
|
|
+- math.erf(x)
|
|
|
Return the error function of x.
|
|
|
|
|
|
-- math.erfc(x)
|
|
|
+- math.erfc(x)
|
|
|
Return the complementary error function of x.
|
|
|
|
|
|
-- math.exp(x)
|
|
|
+- math.exp(x)
|
|
|
Return the exponential of x.
|
|
|
|
|
|
-- math.expm1(x)
|
|
|
+- math.expm1(x)
|
|
|
Return exp(x) - 1.
|
|
|
|
|
|
-- math.fabs(x)
|
|
|
+- math.fabs(x)
|
|
|
Return the absolute value of x.
|
|
|
|
|
|
-- math.floor(x)
|
|
|
+- math.floor(x)
|
|
|
Return an integer, being x rounded towards negative infinity.
|
|
|
|
|
|
-- math.fmod(x, y)
|
|
|
+- math.fmod(x, y)
|
|
|
Return the remainder of x/y.
|
|
|
|
|
|
-- math.frexp(x)
|
|
|
+- math.frexp(x)
|
|
|
Decomposes a floating-point number into its mantissa and exponent. The returned value is the tuple (m, e) such that x == m * 2**e exactly. If x == 0 then the function returns (0.0, 0), otherwise the relation 0.5 <= abs(m) < 1 holds.
|
|
|
|
|
|
-- math.gamma(x)
|
|
|
+- math.gamma(x)
|
|
|
Return the gamma function of x.
|
|
|
|
|
|
-- math.isfinite(x)
|
|
|
+- math.isfinite(x)
|
|
|
Return True if x is finite.
|
|
|
|
|
|
-- math.isinf(x)
|
|
|
+- math.isinf(x)
|
|
|
Return True if x is infinite.
|
|
|
|
|
|
-- math.isnan(x)
|
|
|
+- math.isnan(x)
|
|
|
Return True if x is not-a-number
|
|
|
|
|
|
-- math.ldexp(x, exp)
|
|
|
+- math.ldexp(x, exp)
|
|
|
Return x * (2**exp).
|
|
|
|
|
|
-- math.lgamma(x)
|
|
|
+- math.lgamma(x)
|
|
|
Return the natural logarithm of the gamma function of x.
|
|
|
|
|
|
-- math.log(x)
|
|
|
+- math.log(x)
|
|
|
Return the natural logarithm of x.
|
|
|
|
|
|
-- math.log10(x)
|
|
|
+- math.log10(x)
|
|
|
Return the base-10 logarithm of x.
|
|
|
|
|
|
-- math.log2(x)
|
|
|
+- math.log2(x)
|
|
|
Return the base-2 logarithm of x.
|
|
|
|
|
|
-- math.modf(x)
|
|
|
+- math.modf(x)
|
|
|
Return a tuple of two floats, being the fractional and integral parts of x. Both return values have the same sign as x.
|
|
|
|
|
|
-- math.pow(x, y)
|
|
|
+- math.pow(x, y)
|
|
|
Returns x to the power of y.
|
|
|
|
|
|
-- math.radians(x)
|
|
|
+- math.radians(x)
|
|
|
Return degrees x converted to radians.
|
|
|
|
|
|
-- math.sin(x)
|
|
|
+- math.sin(x)
|
|
|
Return the sine of x.
|
|
|
|
|
|
-- math.sinh(x)
|
|
|
+- math.sinh(x)
|
|
|
Return the hyperbolic sine of x.
|
|
|
|
|
|
-- math.sqrt(x)
|
|
|
+- math.sqrt(x)
|
|
|
Return the square root of x.
|
|
|
|
|
|
-- math.tan(x)
|
|
|
+- math.tan(x)
|
|
|
Return the tangent of x.
|
|
|
|
|
|
-- math.tanh(x)
|
|
|
+- math.tanh(x)
|
|
|
Return the hyperbolic tangent of x.
|
|
|
|
|
|
-- math.trunc(x)
|
|
|
+- math.trunc(x)
|
|
|
返回一个整数, x 接近于0。
|
|
|
|
|
|
`常数`
|
|
|
|
|
|
-- math.e
|
|
|
+- math.e
|
|
|
自然对数的底
|
|
|
|
|
|
-- math.pi
|
|
|
+- math.pi
|
|
|
圆周率
|
|
|
|
|
|
----------
|
|
|
@@ -291,23 +291,23 @@ Return the hyperbolic tangent of x.
|
|
|
|
|
|
`函数`
|
|
|
|
|
|
-- uio.open(name, mode='r', **kwargs)
|
|
|
+- uio.open(name, mode='r', **kwargs)
|
|
|
打开一个文件,关联到内建函数``open()``。所有端口 (用于访问文件系统) 需要支持模式参数,但支持其他参数不同的端口。
|
|
|
|
|
|
`类`
|
|
|
|
|
|
-- class uio.FileIO(...)
|
|
|
+- class uio.FileIO(...)
|
|
|
这个文件类型用二进制方式打开文件,等于使用``open(name, “rb”)``。 不应直接使用这个实例。
|
|
|
|
|
|
-- class uio.TextIOWrapper(...)
|
|
|
+- class uio.TextIOWrapper(...)
|
|
|
这个类型以文本方式打开文件,等同于使用``open(name, “rt”)``不应直接使用这个实例。
|
|
|
|
|
|
-- class uio.StringIO([string])
|
|
|
+- class uio.StringIO([string])
|
|
|
|
|
|
-- class uio.BytesIO([string])
|
|
|
+- class uio.BytesIO([string])
|
|
|
内存文件对象。StringIO 用于文本模式 I/O (用 “t” 打开文件),BytesIO 用于二进制方式 (用 “b” 方式)。文件对象的初始内容可以用字符串参数指定(stringio用普通字符串,bytesio用byets对象)。所有的文件方法,如 read(), write(), seek(), flush(), close() 都可以用在这些对象上,包括下面方法:
|
|
|
|
|
|
-- getvalue()
|
|
|
+- getvalue()
|
|
|
获取缓存区内容。
|
|
|
|
|
|
----------
|
|
|
@@ -319,7 +319,7 @@ Return the hyperbolic tangent of x.
|
|
|
|
|
|
`类`
|
|
|
|
|
|
-- ucollections.namedtuple(name, fields)
|
|
|
+- ucollections.namedtuple(name, fields)
|
|
|
这是工厂函数创建一个新的 namedtuple 型与一个特定的字段名称和集合。namedtuple 是元组允许子类要访问它的字段不仅是数字索引,而且还具有属性使用符号字段名访问语法。 字段是字符串序列指定字段名称。为了兼容的实现也可以用空间分隔的字符串命名的字段(但效率较低) 使用示例:
|
|
|
|
|
|
```python
|
|
|
@@ -369,19 +369,19 @@ b 3
|
|
|
|
|
|
`函数`
|
|
|
|
|
|
-- ustruct.calcsize(fmt)
|
|
|
+- ustruct.calcsize(fmt)
|
|
|
返回需要的字节数`fmt`。
|
|
|
|
|
|
-- ustruct.pack(fmt, v1, v2, ...)
|
|
|
+- ustruct.pack(fmt, v1, v2, ...)
|
|
|
按照字符串格式`fmt` 压缩参数 v1, v2, ... 。 返回值是参数编码后的字节对象。
|
|
|
|
|
|
-- ustruct.pack_into(fmt, buffer, offset, v1, v2, ...)
|
|
|
+- ustruct.pack_into(fmt, buffer, offset, v1, v2, ...)
|
|
|
按照字符串格式`fmt` 压缩参数 v1, v2, ... 到缓冲区`buffer`,开始位置是`offset`。`offset`可以是负数,从缓冲区末尾开始计数。
|
|
|
|
|
|
-- ustruct.unpack(fmt, data)
|
|
|
+- ustruct.unpack(fmt, data)
|
|
|
按照字符串格式`fmt`解压数据`data`。 返回值是解压后参数的元组。
|
|
|
|
|
|
-- ustruct.unpack_from(fmt, data, offset=0)
|
|
|
+- ustruct.unpack_from(fmt, data, offset=0)
|
|
|
从 fmt 的 offset 开始解压数据,如果 offset 是负数就是从缓冲区末尾开始计算。 返回值是解压后参数元组。
|
|
|
|
|
|
----------
|
|
|
@@ -394,13 +394,13 @@ b 3
|
|
|
|
|
|
`类`
|
|
|
|
|
|
-- class array.array(typecode[, iterable])
|
|
|
+- class array.array(typecode[, iterable])
|
|
|
指定类型创建数组元素。用可选项[]做为数组的初始值,可选项[]未指定的,则创建空数组。
|
|
|
|
|
|
-- append(val)
|
|
|
+- append(val)
|
|
|
将新元素添加到数组的结尾,并将其扩展。
|
|
|
|
|
|
-- extend(iterable)
|
|
|
+- extend(iterable)
|
|
|
使用迭代方式将新元素添加到数组的结尾,并将其扩展。
|
|
|
|
|
|
----------
|
|
|
@@ -411,19 +411,19 @@ b 3
|
|
|
|
|
|
`函数`
|
|
|
|
|
|
-- gc.enable()
|
|
|
+- gc.enable()
|
|
|
启动自动垃圾回收。
|
|
|
|
|
|
-- gc.disable()
|
|
|
+- gc.disable()
|
|
|
禁用自动垃圾回收。 堆内存仍然可以分配,垃圾回收仍然可以手动启动使用 gc.collect().
|
|
|
|
|
|
-- gc.collect()
|
|
|
+- gc.collect()
|
|
|
运行垃圾回收。
|
|
|
|
|
|
-- gc.mem_alloc()
|
|
|
+- gc.mem_alloc()
|
|
|
返回分配的堆RAM的字节数。
|
|
|
|
|
|
-- gc.mem_free()
|
|
|
+- gc.mem_free()
|
|
|
返回可用堆内存的字节数。
|
|
|
|
|
|
----------
|