当前位置: 首页 > news >正文

绵阳微信网站/如何做网站

绵阳微信网站,如何做网站,怎么卸载安装好的wordpress,做网站用php还是python我有下面的程序,试图从一个arduino读取数据使用串行端口,事情是它大多不读任何东西,除了有时它读我发送的一部分。arduino代码只是在一个循环中写一个字母。#include #include #include #include #include #include int main() {int serialfd…

我有下面的程序,试图从一个arduino读取数据使用串行端口,事情是它大多不读任何东西,除了有时它读我发送的一部分。arduino代码只是在一个循环中写一个字母。#include

#include

#include

#include

#include

#include

int main() {

int serialfd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NDELAY);

if (serialfd == -1)

perror("Error opening the serial port");

else

fcntl(serialfd, F_SETFL, 0);

fprintf(stdout, "Device is open, attempting read \n");

fcntl(serialfd, F_SETFL, 0);

char buf[11] = {0};

read(serialfd, buf, 10);

fprintf(stdout, "Buffer: %s", buf);

close(serialfd);

return 0;

}

例如,输出如下

Device is open, attempting read

Buffer: AAAAAAAAAAA⏎

如果我尝试再次运行它(几次),我只得到0'd缓冲区

Device is open, attempting read

Buffer: ⏎

最佳答案:

听起来像是配置问题,很可能波特率设置不正确。此外,正如问题注释中提到的,您可能会得到一个完整的缓冲区,结尾没有'\0'字符,因此fprintf的行为不正常。

在这里,我将解释如何设置波特率,但你可以使用wikibooks链接,我已经把答案放在下面,设置其他设置,也要确保检查缓冲区。

简而言之,我喜欢用115200作为我的波特率。There are a few more that are usually supported在其他设备上,但是这个值很好,所以我将用它作为示例。

在arduino上,这很可能是您唯一需要配置的东西(如果事实上,这是我在想使用串行端口与计算机通信时设置的唯一东西)。Serial.begin(115200);

然后根据this wikibook可以通过termios结构中的设置来设置波特率,如wikibook示例中我将其称为attribs。

struct termios attribs;

/* get the current settings */

tcgetattr(serialfd, &attribs);

/* set the baudrate */

cfsetospeed(&attribs, B115200); /* outut baudrate */

cfsetispeed(&attribs, B115200); /* input baudrate */

/* if there is need for it, set other settings here */

/* eventually apply everything for your serialfd descriptor */

tcsetattr(serialfd, TCSANOW, &attribs);

所以从技术上讲,你可以有不同的输入速度,而不是输出速度,但是arduino的UART只有一个这样的设置,而且does not support different speeds for input/ouput,所以你需要在计算机上为这两个设置设置相同的值。

http://www.jmfq.cn/news/5012839.html

相关文章:

  • 网站推广规范/友情链接图片
  • 济南外贸网站制作/北京最新疫情情况
  • 电商创业怎么做/汕头网站优化
  • flash 网站 源码/优化设计七年级下册语文答案
  • 59网站一起做网店/推广平台排行榜有哪些
  • 电商网站新闻怎么做/推广平台有哪些渠道
  • 跨国多语言交友网站建设/seo舆情优化
  • 宜春企业网站的建设/企业培训内容
  • 做二手房比较好的网站/如何在百度上发布自己的广告
  • 原创文学网站建设/福州seo公司排名
  • 做视频网站代码/抚顺网站建设
  • 中山好的网站建设公司哪家好/友情链接翻译
  • 网站制作报价多少/seo交流博客
  • 网页小游戏网站建设/上海十大营销策划公司排名
  • 台州制作网站软件/个人网站制作模板
  • 做网站可以赚钱吗/福州seo排名优化
  • 山东临沂网站开发/亚马逊排名seo
  • 做微信请帖网站/企业网站大全
  • 杭州做企业网站的公司/seo教学培训
  • php网站建设与维护/上海网站推广系统
  • 网站非法篡改/seo搜索引擎优化业务
  • 广州网站制作功能/永久免费google搜索引擎
  • 网站开发费用明细/网络营销广告
  • 昌乐网站制作/北京seo优化排名
  • 战鼓的h5网站如何做/阿拉善盟seo
  • 网站备案后怎么做/青柠影院免费观看电视剧高清
  • 做网站手机电脑通用要加些什么/东莞网站建设推广公司
  • 媒体资源/上海站群优化公司
  • 使用dw做门户网站/武汉java培训机构排名榜
  • 网站建设的可用性/建设网站流程