VirtualBox虚拟机串口调试方法

阅读: 评论:0

VirtualBox虚拟机串口调试方法

VirtualBox虚拟机串口调试方法

1.windows下调试virtualbox的虚拟机串口

2.Cannot open /dev/ttyS0: Permission denied解决
出现了Cannot open /dev/ttyS0: Permission denied提示字样
解决方法如下:
1.由于tty属于“dialout”组别,比如用户名是admin123,
先命令查看下用户隶属的组别
groups admin123
2.如果没有隶属“dialout”,那么把用户加入进去
sudo gpasswd --add admin123 dialout
3.logout 再登录系统激活功能

3.linux在shell下的串口的一些操作

echo aaa > /dev/ttyS0向com1写数据
cat /dev/ttyS0向com1读数据
cat /proc/tty/drivers/serial查看串口信息
stty -F设置串口参数

stty linux 命令在线中文手册
Linux深入探索01-stty与键盘信号

Linux C 配置串口

#include <termios.h>
#include <unistd.h>// 最核心的配置结构体
typedef unsigned int tcflag_t;
struct termios {tcflag_t    c_cflag;                    /* 控制标志 */tcflag_t    c_iflag;                     /* 输入标志 */tcflag_t    c_oflag;                    /* 输出标志 */tcflag_t    c_lflag;                     /* 本地标志 */tcflag_t    c_cc[NCCS];           /* 控制字符 */
};fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY);
struct termios opt;
tcgetattr(fd, &opt);  // 获取上述配置结构体// 设置波特率相关接口
speed_t cfgetispeed(const struct termios *termios_p);
speed_t cfgetospeed(const struct termios *termios_p);int cfsetispeed(struct termios *termios_p, speed_t speed);
int cfsetospeed(struct termios *termios_p, speed_t speed);
int cfsetspeed(struct termios *termios_p, speed_t speed);// 设置奇偶校验位
opt.c_cflag &= ~PARENB;
// 设置数据位
opt.c_cflag &= ~CSIZE;  // 先用 CSIZE 来做屏蔽字段
opt.c_cflag |= CS8;
// 设置停止位
opt.c_cflag &= ~CSTOPB;
// 设置硬件控制流
opt.c_cflag |= CRTSCTS;
// 抛弃存储在 fd 里的未接收的数据
tcflush(fd, TCIFLUSH);
// 将配置信息写入文件描述符 fd
tcsetattr(fd, TCSANOW, &opt);

本文发布于:2024-01-30 15:46:12,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170660077421090.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:串口   虚拟机   方法   VirtualBox
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23