libserialport: cross-platform library for accessing serial ports

简介: /*********************************************************************************** * libserialport: cross-platform library for accessing serial ports * 说明: * 很多时候,我们经常需要写一下串口方面的调试工具,象征一下我们的知识产权, * 但是对于很多人来说,也许仅仅关心上层的软件,并不关心驱动上的事,所以使用串 * 口库就变成了一种很不错的选择。
/***********************************************************************************
 *       libserialport: cross-platform library for accessing serial ports
 * 说明:
 *     很多时候,我们经常需要写一下串口方面的调试工具,象征一下我们的知识产权,
 * 但是对于很多人来说,也许仅仅关心上层的软件,并不关心驱动上的事,所以使用串
 * 口库就变成了一种很不错的选择。
 * 
 *                                             2015-12-22 深圳 南山平山村 曾剑锋
 **********************************************************************************/

一、参考文档:
    1. C: cross-platform RS232 serial library? [closed]
        http://stackoverflow.com/questions/2973402/c-cross-platform-rs232-serial-library
    2. request basic example code please #11
        https://github.com/martinling/libserialport/issues/11

二、README 翻译:
    -------------------------------------------------------------------------------
    libserialport: cross-platform library for accessing serial ports
    libserialport: 跨平台的串口库
    -------------------------------------------------------------------------------

    libserialport is a minimal library written in C that is intended to take care
    of the OS-specific details when writing software that uses serial ports.
    libserialport采用C语言编写,当我们写软件的时候可以规避一些操作系统 特有的内容。

    By writing your serial code to use libserialport, you enable it to work
    transparently on any platform supported by the library.
    通过使用libserialport,你的软件可以在任何平台上运行。

    The operations that are supported are:
    支持以下操作:

    - Port enumeration (obtaining a list of serial ports on the system).
    枚举串口
    - Opening and closing ports.
    打开关闭串口
    - Setting port parameters (baud rate, parity, etc).
    设置串口参数
    - Reading, writing and flushing data.
    读、写、刷新数据
    - Obtaining error information.
    获取错误

    libserialport is an open source project released under the LGPL3+ license.
    libserialport是一个开源项目,在LGPL3+协议下发行的

    Status
    现状
    ======

    The library should build and work on any Windows or Unix-based system. If it
    does not, please submit a bug.
    该库能够在任何Windows或者Unix-based系统下工作。当然,如果不能工作,请提交bug

    Enumeration is currently only implemented on Windows, Mac OS X and Linux. On
    other systems enumeration is not supported, but ports can still be opened by
    name and then used.
    枚举目前只在Windows、Mac OS X和Linux上实现了,在其他的系统上目前还不支持,
    但是串口还是可以通过名字打开并使用。

    If you know how to enumerate available ports on another OS, please submit a bug
    with this information, or better still a patch implementing it.
    如果你知道怎么枚举串口在其他的OS上,请提交对应的bug,将会实现这个功能。

    Future
    将来
    ======

    Future versions will add additional API calls for obtaining metadata about a
    port, e.g. for USB devices the USB VID and PID of the underlying device.
    将来的版本将添加用于获取串口元数据的API,例如,获取USB底层设备的VID、PID。

    Dependencies
    ============

    On Linux, libudev is required. On other systems no other libraries are required.
    在Linux系统上,libudev是依赖的库,在其他的系统上不依赖任何其他的库。

    The libudev dependency could be eliminated in favour of direct sysfs queries at
    the cost of some brevity. This is not currently a priority but if you feel like
    doing this feel free to submit a patch.

    Building
    编译
    ========

    The package uses a GNU style build system and requires a Unix style shell.
    On Windows it can be built with the MinGW toolchain and MSYS environment.
    这个包使用GNU编译系统,需要一个Unix形式的shell,在Windows上,可以通过MinGW
    工具、MSYS环境进行编译。

    Run "./autogen.sh" to generate the build system, "./configure" to setup, then
    "make" to build the library and "make install" to install it.
    运行"./autogen.sh" 来生成编译系统,"./configure"来配置,同时"make"来生成库,
    "make install"来进行安装

    API
    ===

    Doxygen API documentation is included.

三、Simple Demo:
    #include <stdio.h>
    #include "libserialport.h"

    int main ( void ) 
    {
        int i = 0;
        struct sp_port **ports;

        sp_list_ports(&ports);

        for (i = 0; i > 0 && ports[i]; i++)
            printf("Found port: '%s'.\n", sp_get_port_name(ports[i]));

        sp_free_port_list(ports);
    }
    

 

目录
相关文章
|
Web App开发 域名解析 缓存
如何在 Ubuntu 20.04 上安装 Node.js 和 npm
本文我们主要为大家介绍在 Ubuntu 20.04 上安装 Node.js 和 npm 的三种不同的方式。
162259 7
如何在 Ubuntu 20.04 上安装 Node.js 和 npm
|
Web App开发 分布式计算 小程序
什么是云计算,云计算在未来有什么作用?
简要介绍云计算及云计算作用
8064 0
|
存储 芯片 C++
STM32启动详细流程分析(一)
STM32启动详细流程分析(一)
620 0
|
存储 监控 安全
探究Linux操作系统的进程管理机制及其优化策略
本文旨在深入探讨Linux操作系统中的进程管理机制,包括进程调度、内存管理以及I/O管理等核心内容。通过对这些关键组件的分析,我们将揭示它们如何共同工作以提供稳定、高效的计算环境,并讨论可能的优化策略。
234 20
|
存储 Kubernetes 监控
Kubernetes集群管理的最佳实践
【7月更文挑战第25天】遵循上述最佳实践可以显著提升Kubernetes集群的管理效率、安全性和性能。然而,每个集群的环境和需求都是独特的,因此在实际操作中还需根据具体情况进行调整和优化。希望本文能为你管理Kubernetes集群提供一些有益的参考。
|
缓存 监控 Ubuntu
Linux命令slabtop详解
`slabtop`是Linux内存监控工具,展示内核slab缓存的实时状态。它读取`/proc/slabinfo`,显示缓存名、对象数、大小和使用详情。特点包括实时显示、可排序和多选项定制。常用参数有`-d`设置更新间隔,`-s`按特定标准排序。适用于多种Linux发行版,用于识别性能瓶颈和优化内存使用。结合其他工具使用,提升系统性能。
|
机器学习/深度学习
Softmax 和 ReLU 函数的效用
【8月更文挑战第23天】
718 0
|
自然语言处理 前端开发 Swift
Llama3 中文通用Agent微调模型来啦!(附手把手微调实战教程)
Llama3模型在4月18日公布后,国内开发者对Llama3模型进行了很多训练和适配,除了中文纯文本模型外,多模态版本也陆续在发布中。
|
搜索推荐 开发工具 Android开发
安卓即时应用(Instant Apps)开发指南
【4月更文挑战第14天】Android Instant Apps让用户体验部分应用功能而无需完整下载。开发者需将应用拆分成模块,基于已上线的基础应用构建。使用Android Studio的Instant Apps Feature Library定义模块特性,优化代码与资源以减小模块大小,同步管理即时应用和基础应用的版本。经过测试,可发布至Google Play Console,提升用户便利性,创造新获客机会。
594 1
FAT-fs (mmcblk0p1): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.
/******************************************************************************** * FAT-fs (mmcblk0p1): Volume was not properly unmounted. Some data may be corrupt. Please run fsck. * 说明: * 系统更新的时候遇到这个错误,记录一下处理步骤,其原因是我自己把其umount了 * 导致的问题。
6705 0

热门文章

最新文章