使用文件系统和支持包的软件管理
UTILS_API*是一组用于处理用户计算机上的文件和目录的辅助方法,不适用于目录。 *AnyMath .
使用*UTILS_API*您可以:
*上传文件到您的计算机; *从您的计算机下载文件; *使用指定的路径在文件系统中创建和删除目录。
#
Main.EngeeDeviceManager.UTILS_API.createFile — Function
UTILS_API.createFile(utils::Any, filename::String, filepath::String, contents::Union{Vector{UInt8}, String, Nothing}=nothing, mode::String="wb", buffering::Int64=-1, encoding::Union{String, Nothing}=nothing, errors::Union{String, Nothing}=nothing, newline::Union{String, Nothing}=nothing, closefd::Bool=true)::Nothing
该函数用于在用户客户端程序的指定目录 filepath 中创建名为 filename 的文件。
参数
-
utils:UTILS.Utils类型的对象。 -
engee_filepath:AnyMath文件浏览器中文件的路径。 -
host_dirpath:用户客户端程序中用于接收从AnyMath下载的指定文件的目录路径。-
mode:文件打开模式。可能的取值: -
"r":读取; -
"w":写入(覆盖); -
"a":追加写入; -
"wb":二进制写入; -
"rb":二进制读取。
-
-
buffering:文件操作的系统缓冲区参数。可能的值:-
-1:默认系统缓冲区; -
0:禁用缓冲; -
1:逐行缓冲(仅限文本模式); -
>1:缓冲区大小(单位:字节)。
-
-
encoding:文件编码。可能的值:"utf-8"、"cp1251"、"ascii"、"latin-1"、nothing----系统默认值。 -
errors:错误处理策略:-
"strict":遇到无法编码的字符时报错; -
"ignore":忽略不可编码字符; -
"replace":替换为�(replacement marker); -
"backslashreplace":替换为转义序列。
-
-
newline:行转换控制:-
nothing或""---- 通用模式; -
"\n"、"\r"、"\r\n"— 特定的换行符处理方式。不同系统中的换行符各不相同:
-
-
Unix/Linux:
\n;-
Windows:
\r\n; -
旧版 MacOS:
\r。
-
-
closefd: 自动关闭文件描述符(true----关闭,false----保持打开)。 -
filename: 要创建的文件名; -
filepath: 创建文件的目录路径; -
contents: 文件内容(字符串、字节或nothing)。
#
Main.EngeeDeviceManager.UTILS_API.createFolder — Function
UTILS_API.createFolder(utils::Any, folder_path::String, folder_name::String, mode::Int64=511, dir_fd::Union{Int64, Nothing}=nothing)::Nothing
该函数用于在用户客户端程序中,于指定的 folder_path 目录下创建名为 folder_name 的目录。
参数
-
utils:UTILS.Utils类型的对象。 -
folder_path:用户客户端程序中将创建新文件夹的目录路径。 -folder_name:要创建的目录名称。 -mode:目录的访问权限。访问权限示例:权限
八进制表示
十进制表示
说明
-----------
--------------
------------
----------------------------------------------------
rwxrwxrwx
0o777
511
所有用户均享有完全访问权限
rwxr-xr-x
0o755
493
目录的标准权限
rwxr-x---
0o750
488
所有者:完全访问权限,组:读取+执行权限
rwx------
0o700
448
仅所有者
rw-rw-rw-
0o666
438
所有者可读写
rw-r—r--
0o644
420
文件的标准权限
rw-r-----
0o640
416
所有者:读写,组:读取
rw-------
0o600
384
仅所有者(读+写)
-
dir_fd: 文件描述符。nothing— 绝对路径,数字 — 通过描述符指定的相对路径。
#
Main.EngeeDeviceManager.UTILS_API.deleteFile — Function
UTILS_API.deleteFile(utils::Any, filename::String, filepath::String, ignore_if_missing::Bool=false, verbose::Bool=false)::Nothing
该函数用于在用户客户端程序的指定目录 filepath 中删除名为 filename 的文件。
参数
-
utils: 类型为UTILS.Utils的对象。 -
filename: 要删除的文件名。 -
filepath:要删除文件的目录路径。 -
ignore_if_missing:false— 若未找到文件则报错;true— 忽略文件不存在的情况。 -
verbose:是否输出操作详情(true)或不输出(false)。
#
Main.EngeeDeviceManager.UTILS_API.deleteFolder — Function
UTILS_API.deleteFolder(utils::Any, folder_path::String, folder_name::String, even_if_not_empty::Bool=false, dir_fd::Union{Int64, Nothing}=nothing)
该函数用于在用户客户端程序中,从指定的 folder_path 目录中删除名为 folder_name 的目录。
参数
-
utils: 类型为UTILS.Utils的对象。 -
folder_path: 用户客户端程序中目录的路径。 -
folder_name:要删除的目录名称。 -
even_if_not_empty:即使目录不为空也删除(true— 是,false:仅删除空目录)。 -
dir_fd:文件描述符:nothing— 绝对路径,数字 — 使用相对路径。
#
Main.EngeeDeviceManager.UTILS_API.downloadFile — Function
UTILS_API.downloadFile(utils::Any, engee_dirpath::String, host_filepath::String, mode::String="rb", buffering::Int64=-1, encoding::Union{String, Nothing}=nothing, errors::Union{String, Nothing}=nothing, newline::Union{String, Nothing}=nothing, closefd::Bool=true)::Nothing
该函数用于将用户客户端程序中的指定文件下载到AnyMath文件浏览器的指定目录中。
参数
-
utils:UTILS.Utils类型的对象。 -
engee_filepath:AnyMath 文件浏览器中文件的路径。 -
host_dirpath:用户客户端程序中用于接收从 AnyMath 上传指定文件的目录路径。 -mode:文件打开模式。 可能的取值: -"r":读取; -"w":写入(覆盖); -"a":追加写入; -"wb":二进制写入; -"rb":二进制读取。 -
buffering:文件操作系统缓冲区的参数。 可能的取值: --1:默认系统缓冲区; -0:禁用缓冲; -1:按行缓冲(仅限文本模式); ->1:缓冲区大小(以字节为单位)。 -
encoding:文件的编码。可选值:"utf-8"、"cp1251"、"ascii"、"latin-1"、nothing----默认使用系统编码。 -
errors:错误处理策略: -"strict":遇到不可编码字符时报错; -"ignore":忽略不可编码字符; -"replace":替换为�(替换标记); -"backslashreplace":替换为转义序列。 -
newline:换行符处理控制:-
nothing或""— 通用模式; -
"\n"、"\r"、"\r\n"— 特定的换行符处理方式。 不同系统中的换行符各不相同:
-
-
Unix/Linux:
\n;-
Windows:
\r\n; -
旧版 MacOS:
\r。
-
-
closefd:自动关闭文件描述符(true----关闭,false----保持打开)。
#
Main.EngeeDeviceManager.UTILS_API.getCanDevicesList — Method
UTILS_API.getCanDevicesList()::Nothing
以表格形式输出可用 CAN 设备的列表。
该表格包含以下列:
-
@— 行号; -
Interface— 厂商或所用 CAN 驱动程序的名称; -
Channel— 可用的(已找到的)CAN 适配器通道。
参数
该函数不接受任何参数。返回nothing 。
示例
using Main.EngeeDeviceManager.UTILS_API
UTILS_API.getCanDevicesList()
#
Main.EngeeDeviceManager.UTILS_API.uploadFile — Function
UTILS_API.uploadFile(utils::Any, engee_filepath::String, host_dirpath::String, mode::String="wb", buffering::Int64=-1, encoding::Union{String, Nothing}=nothing, errors::Union{String, Nothing}=nothing, newline::Union{String, Nothing}=nothing, closefd::Bool=true)::Nothing
该函数用于将指定的文件从AnyMath文件浏览器下载到用户客户端程序的指定目录中。
参数
-
utils: 类型为UTILS.Utils的对象。 -
engee_filepath:AnyMath文件浏览器中文件的路径。 -
host_dirpath:用户客户端程序中用于接收从AnyMath下载指定文件的目录路径。 -mode:文件打开模式。 可能的取值: -"r":读取; -"w":写入(覆盖); -"a":追加写入; -"wb":二进制写入; -"rb":二进制读取。 -
buffering:文件操作系统缓冲区的参数。 可能的取值: --1:默认系统缓冲区; -0:禁用缓冲; -1:逐行缓冲(仅限文本模式); ->1:缓冲区大小(单位:字节)。 -
encoding:文件的编码。可用值:"utf-8"、"cp1251"、"ascii"、"latin-1"、nothing----默认使用系统编码。-errors:错误处理策略: -"strict":遇到不可编码字符时报错; -"ignore":忽略不可编码字符; -"replace":替换为�(替换标记); -"backslashreplace":替换为转义序列。 -
newline:换行符处理控制:-
nothing或""— 通用模式; -
"\n"、"\r"、"\r\n"— 具体的换行符处理方案。 不同系统中的换行符各不相同:
-
-
Unix/Linux:
\n;-
Windows:
\r\n; -
旧版 MacOS:
\r。
-
-
closefd:自动关闭文件描述符(true— 关闭,false— 保持打开)。