--- title: "How To Use The Generic Serial Driver on I/O Gateway" slug: "how-to-use-the-generic-serial-driver-on-io-gateway" updated: 2025-04-23T20:55:09Z published: 2025-04-23T20:55:09Z canonical: "support.tulip.co/how-to-use-the-generic-serial-driver-on-io-gateway" --- > ## Documentation Index > Fetch the complete documentation index at: https://support.tulip.co/llms.txt > Use this file to discover all available pages before exploring further. # 如何在 I/O Gateway 上使用通用串行驱动程序 ## 如何在 I/O Gateway 上使用通用串行驱动程序 *了解如何让 I/O Gateway 与任何串行设备通信。* {{snippet.IO Gateway 停止使用注意事项}{{snippet.IO Gateway 停止使用注意事项}. [Edge IO 串口指南](https://support.tulip.co/docs/how-to-use-serial-with-edge-io) [Edge MC](https://support.tulip.co/docs/how-to-use-serial-on-edge-mc) [串行](https://support.tulip.co/docs/how-to-use-serial-with-edge-io) [设置指南](https://support.tulip.co/docs/how-to-use-serial-on-edge-mc) 本文将介绍如何使用 I/O Gateway 上的通用串行驱动程序与大多数串行设备通信。本文适用于其他 Tulip Edge 设备,如[Edge MC](https://support.tulip.co/docs/how-to-use-serial-on-edge-mc)和[Edge IO](https://support.tulip.co/docs/how-to-use-serial-with-edge-io)。 本文假定您已完成[I/O 网关设置](/r230/docs/setting-up-a-tulip-io-gateway)。 请注意,该驱动程序不同于[串行驱动程序(仅播放器)](https://support.tulip.co/docs/using-the-serial-driver),后者目前仅适用于 Windows Tulip Player。 ## 什么是通用串行驱动程序? 通用串行驱动允许 I/O 网关使用通用串行协议与其他设备通信。这些设备包括 - Arduino - 树莓派 - 其他郁金香边缘设备 - 微型控制器 - 许多其他设备 由于该驱动程序用途广泛,因此配置复杂。该配置需要与其他设备的配置完全匹配。 该驱动程序可同时支持与多个设备通信。 注意:Tulip 不会为连接到通用串行驱动程序的设备编写自定义代码。 ## 打开通用串行驱动程序 登录 I/O Gateway 创建的本地网络,将计算机连接到 I/O Gateway。 打开设备门户。在仪表盘页面,单击页面左侧的 "配置驱动程序 "按钮。 ![](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/How%20To%20Use%20The%20Generic%20Serial%20Driver%20on%20I_O%20Gateway_104960645.png) 在驱动程序配置页面,单击 "通用串行 "选项。 ![](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/How%20To%20Use%20The%20Generic%20Serial%20Driver%20on%20I_O%20Gateway_104960899.png) 默认情况下,"Generic Serial(通用串行)"选项应为绿色(已启用),并配置了一些常用设置。 ![](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/How%20To%20Use%20The%20Generic%20Serial%20Driver%20on%20I_O%20Gateway_104961340.png) Windows 倾向于使用 \r 进行回车。 通用串行驱动程序需要进行一些配置,才能继续打开驱动程序。 以下是每个字段的选项: #### 写后缀 - 预期输入:任何字符串 - 这将附加到 I/O Gateway 发送到设备的任何信息中,通常是换行 (\n) 或回车 (\n\r) - 必须输入:否 **路径匹配器** - 预期输入:设备的系统路径 - 可以用 * 与任何未使用的串行设备匹配(这对使用 usb 转串行适配器很有用)。 - 必填:是 #### 名称 - 预期输入内容:该设备的名称(将用于在应用程序中引用该设备) - 必填:是 #### 分隔符 - 预期输入内容:任何字符串(用于将来自设备的信息分割成小块发送到您的 Tulip 账户) - 必填:是 #### 波特 - 预期输入:设备用于通信的波特率 - 要求: 是 #### 本地 DB9 端口 如果计划使用 I/O Gateway 上的本地 DB9 端口,则需要在**路径匹配器中**使用`/dev/ttyO4`路径。*这是大写的 O,而不是 0。* ## 构建与串行驱动程序配合使用的应用程序 下面介绍如何构建一个应用程序来测试驱动程序。 首先,创建一个新的应用程序并添加一个按钮。 为该按钮添加一个触发器,用配置驱动程序时使用的名称调出通用串行设备。 ![](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/How%20To%20Use%20The%20Generic%20Serial%20Driver%20on%20I_O%20Gateway_104963228.png) 以下是 "然后 "语句中需要的字段: - "运行设备函数 - "通用串行设备 - "将字符串发送到串行设备 - 在 "此站 "处 - 要发送到的设备:"文本" "RS232" - 要发送的信息"文本""测试通用串行" 在该程序中添加一个触发器,以便在通用串行驱动程序发出数据时将数据记录到变量中。使用 "If "语句,只有当正确的设备输出数据时才存储数据。 ![](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/How%20To%20Use%20The%20Generic%20Serial%20Driver%20on%20I_O%20Gateway_104964088.png) #### 当 - "设备""通用串行设备 "在 "此站 "输出数据 #### 如果 - "设备输出 - "名称" - "=" - "文本" "RS232" #### 那么 - "数据操作 - "存储" - "设备输出" "数据 - 位置:"通用序列"(这是一个变量的名称) 将该变量添加到应用程序中。它将是一个具有 "名称 "和 "数据 "属性的对象。 ![](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/How%20To%20Use%20The%20Generic%20Serial%20Driver%20on%20I_O%20Gateway_104965028.png) ## 测试应用程序 使用[null 调制解调器](https://www.amazon.com/USB-Serial-Adapter-Modem-9-pin/dp/B008634VJY)和 USB 转 RS232 转换器测试应用程序。 将 USB 连接到计算机。然后将零调制解调器适配器连接到 RS232 适配器和 I/O Gateway 的 DB9 端口。 开始: ![](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/How%20To%20Use%20The%20Generic%20Serial%20Driver%20on%20I_O%20Gateway_104965111.png) 如果您使用的是 Windows 系统,请使用[Putty](https://www.putty.org/)测试连接。使用设备管理器获取端口号。 ![](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/How%20To%20Use%20The%20Generic%20Serial%20Driver%20on%20I_O%20Gateway_104965202.png) 在 "速度 "框中输入 COM 端口号,并选择 "连接类型 "为 "串行"。 ![](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/How%20To%20Use%20The%20Generic%20Serial%20Driver%20on%20I_O%20Gateway_104965318.png) 只有在运行的应用程序中点击按钮时,Putty 终端才会向 I/O 网关打印信息。 ![](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/How%20To%20Use%20The%20Generic%20Serial%20Driver%20on%20I_O%20Gateway_104965362.png) 输入信息 "Tulip "并按回车键,通过 Putty 发送信息。 ![](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/How%20To%20Use%20The%20Generic%20Serial%20Driver%20on%20I_O%20Gateway_104965408.png) ## 如何在 Linux 或 Mac 上使用 Node.js 测试通用串行驱动程序 这需要 node.js 和 npm。然后,通过 npm 安装`serialport`软件包。 ``const SerialPort = require('serialport') const Readline = require('@serialport/parser-readline') const port = new SerialPort('/dev/ttyUSB0', { baudRate: 19200 }) const parser = new Readline() port.pip(parser) parser.on('data', line => { console.log(> ${line}) }); 让 test = false; setInterval(()=>{ if (test){ port.write('output\n'); test = false } else { port.write('other output\n'); test = true } },1000)```