为了创建一对串行端口,我跟踪了。效果很好。
现在,我正在开发一个Qt应用程序(使用)通过串口发送数据,我真正想要的是这样一个虚拟串口链接。但是QSerialPortInfo::availablePorts()似乎找不到/dev/ it /.港口。
为了在linux上建立这样的串口链接,我应该尝试哪种方法?
我的工作是机器人,它必须控制使用无线串行通信。机器人在微控制器上运行(通过燃烧一个.hex文件)。我想用我的Linux () PC来控制它。我是新来的串口编程。我能够发送数据,但我不能读取数据。
在微控制器上运行的几段代码:
函数发送数据:
void TxData(unsigned char tx_data)
{
SBUF = tx_data; // Transmit data that is passed to this function
while(TI == 0) // Wait while data is being transmitted
;
}
这是我的C程序(在Linux中)的相关部分:
while (input != ' '){
write(serial_port, msg, sizeof(msg));
//1. here I would like to wait at least 100 us with the Tx line high
//2. followed by at least 8us with the Tx line low
//3. and then repeat the message
input = mygetch();
}
如您所见,每次通过串口发送msg后,我希望将Tx行设置为10
我可以使用串口调试工具和Modbus协议接收数据。
以下参数相同。但是,我在DataReceived方法中设置了一个断点,但从未遇到过它。下面是我的程序:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading;
using System.Thread
过去,我曾在Linux和Windows环境中使用c++和python与串口通信。在Linux中,我还使用picocom、minicom和cutecom等程序进行串行通信,但现在我想使用简单的Linux命令读写串口,这不需要安装外部程序。我会在raspberry pi中使用这种方法与我的Arduino板进行通信。在下面的示例中,我使用stty设置串口选项,并使用echo和cat命令从串口发送和读取数据,但在最后,我没有看到任何输出,我在这个站点上阅读了与此相关的其他文章,但似乎没有什么对我有用。我可以使用cutecom与Arduino进行通信,但是使用下面的命令,我看不到任何响应。
Linux
所以我正在写一个从串口获取输入的程序。如下所示:
String p = "COM3";
SerialPort in = SerialPort.getCommPort(p);
in.openPort();
InputStream d = in.getInputStream();
为了从port.stream中读取数据,我使用了以下代码
do
{
System.out.print((char)d.read());
counter++;