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

免费的公众号排版工具福建seo快速排名优化

免费的公众号排版工具,福建seo快速排名优化,丝路云网站建设,商丘做网站汉狮网络​编辑 风紊 现役大学牲,半退休robomaster视觉队员 写在前面 本文章主要介绍的是如何通过开源的serial库和虚拟串口实现上位机和下位机通信。 需求 假设下位机有这样一个数据报发送给上位机 struct DataRecv {char start s;TeamColor color TeamColor::Blu…

​编辑

风紊

现役大学牲,半退休robomaster视觉队员

写在前面

本文章主要介绍的是如何通过开源的serial库和虚拟串口实现上位机和下位机通信。

需求

假设下位机有这样一个数据报发送给上位机

struct DataRecv {char start = 's';TeamColor color = TeamColor::Blue;Mode mode = Mode::Armor;float speed = 20;float euler[3] = {};  //(0,1,2) = (yaw,roll,pitch)char shoot_bool = 0;char RuneFlag = 0;    char unused[10] = {};char end = 'e';
}//TeamColor是一个char类型的迭代类,Mode也是一个char类型的迭代类

其他数据我都不需要,只需要欧拉角,也就是一个浮点数数组,euler[3]

解决方法

serial库的github仓库

先clone下来,安装,得到头文件和动态库。

我们来看看serial库的构造函数:

class Serial {
public:/*!* Creates a Serial object and opens the port if a port is specified,* otherwise it remains closed until serial::Serial::open is called.** \param port A std::string containing the address of the serial port,*        which would be something like 'COM1' on Windows and '/dev/ttyS0'*        on Linux.** \param baudrate An unsigned 32-bit integer that represents the baudrate** \param timeout A serial::Timeout struct that defines the timeout* conditions for the serial port. \see serial::Timeout** \param bytesize Size of each byte in the serial transmission of data,* default is eightbits, possible values are: fivebits, sixbits, sevenbits,* eightbits** \param parity Method of parity, default is parity_none, possible values* are: parity_none, parity_odd, parity_even** \param stopbits Number of stop bits used, default is stopbits_one,* possible values are: stopbits_one, stopbits_one_point_five, stopbits_two** \param flowcontrol Type of flowcontrol used, default is* flowcontrol_none, possible values are: flowcontrol_none,* flowcontrol_software, flowcontrol_hardware** \throw serial::PortNotOpenedException* \throw serial::IOException* \throw std::invalid_argument*/Serial (const std::string &port = ""                  //需要打开的端口uint32_t baudrate = 9600,                     //设置波特率,缺省值位9600Timeout timeout = Timeout(),                  //打开超时的时间,缺省值时间为0bytesize_t bytesize = eightbits,              //字节大小,缺省值位8位parity_t parity = parity_none,                //奇偶校验位,默认无奇偶校验stopbits_t stopbits = stopbits_one,           //停止位,缺省值为1位flowcontrol_t flowcontrol = flowcontrol_none);//流控制,默认五流控制,可选择软件流控制和硬件流控制

选项都设置好后,直接调用对象的open()方法就能打开串口通信。

读数据的方法:

size_t
Serial::read (uint8_t *buffer, size_t size)
{ScopedReadLock lock(this->pimpl_);return this->pimpl_->read (buffer, size);
}

所以我们只需要将数据包转为uint8_t的类型的存储格式指针,传给函数,并指定字节数size就能读取数据了。

通信实现文件test.cpp的代码

#include <serial/serial.h>
#include <iostream>struct data_package
{char start = 's';char unused1[2];float speed = 20;float euler[3] = {}; //(0,1,2) = (yaw,roll,pitch)char shoot_bool = 0;char RuneFlag = 0; //char unused2[10] = {};char end = 'e';
} __attribute__((packed));
static_assert(sizeof(data_package) == 32);data_package data;
int main()
{std::cout << "helloworld" << std::endl;serial::Serial ser; // 实例化一个串口的对象ser.setPort("/dev/serial_sdk"); // 设置串口设备ser.setBaudrate(115200);        // 设置波特率try{ser.open(); // 打开串口while (true){std::cout << "number" << ser.available() << std::endl; // 读取到缓存区数据的字节数ser.read(reinterpret_cast<uint8_t *>(&data), 32);//将data_package类型结构体强制转换位uint8_t类型的指针,来接收32字节的数据std::cout << data.start << data.unused1[0] << data.unused1[1] << std::endl;std::cout << "(yaw,pitch,roll)" << data.euler[0] << " " << data.euler[1] << " " << data.euler[2] << std::endl;}}catch (std::exception &e){std::cerr << e.what() << std::endl;}
}

使用g++编译代码失败的话,可以参考关于库不在默认搜索路径时,g++链接库时找不到函数实现的问题。

如果要给设备起别名,可以参考Linux下给外部挂载的设备起别名,而不使用内核名称

Notice

如果结构体最后不接 attribute((packed)),经笔者测试,数据包大小变为36位。


文章转载自:
http://flank.hjyw.cn
http://transfluxor.hjyw.cn
http://hong.hjyw.cn
http://hyperparasitic.hjyw.cn
http://burp.hjyw.cn
http://wolverine.hjyw.cn
http://thunderclap.hjyw.cn
http://chitinous.hjyw.cn
http://lowrise.hjyw.cn
http://adiaphorism.hjyw.cn
http://agelong.hjyw.cn
http://masked.hjyw.cn
http://biotic.hjyw.cn
http://iceland.hjyw.cn
http://kalends.hjyw.cn
http://bloodily.hjyw.cn
http://chinanet.hjyw.cn
http://silkiness.hjyw.cn
http://superradiation.hjyw.cn
http://loadstone.hjyw.cn
http://horsewoman.hjyw.cn
http://zygotene.hjyw.cn
http://humanities.hjyw.cn
http://comfortless.hjyw.cn
http://waterflood.hjyw.cn
http://recordmaker.hjyw.cn
http://widf.hjyw.cn
http://quarantine.hjyw.cn
http://anchoret.hjyw.cn
http://kts.hjyw.cn
http://marginalize.hjyw.cn
http://colourant.hjyw.cn
http://epexegesis.hjyw.cn
http://epididymis.hjyw.cn
http://blackthorn.hjyw.cn
http://lass.hjyw.cn
http://pin.hjyw.cn
http://reafference.hjyw.cn
http://irishism.hjyw.cn
http://lactobacillus.hjyw.cn
http://ursuline.hjyw.cn
http://amphibiotic.hjyw.cn
http://similarity.hjyw.cn
http://contrefilet.hjyw.cn
http://truly.hjyw.cn
http://ultrasecret.hjyw.cn
http://muzz.hjyw.cn
http://aboriginal.hjyw.cn
http://godfrey.hjyw.cn
http://abelmosk.hjyw.cn
http://dionysia.hjyw.cn
http://arbitrariness.hjyw.cn
http://zwitterionic.hjyw.cn
http://trimethylamine.hjyw.cn
http://unanaesthetized.hjyw.cn
http://hern.hjyw.cn
http://landmine.hjyw.cn
http://fluorimetry.hjyw.cn
http://haemorrhage.hjyw.cn
http://sadhe.hjyw.cn
http://outdo.hjyw.cn
http://fragrant.hjyw.cn
http://dutiable.hjyw.cn
http://synchronal.hjyw.cn
http://jabberwocky.hjyw.cn
http://blank.hjyw.cn
http://diopter.hjyw.cn
http://extrapyramidal.hjyw.cn
http://deliriant.hjyw.cn
http://whole.hjyw.cn
http://nuff.hjyw.cn
http://morcha.hjyw.cn
http://marchpane.hjyw.cn
http://gluttonize.hjyw.cn
http://tibia.hjyw.cn
http://nymphomaniac.hjyw.cn
http://pentoxid.hjyw.cn
http://wharfman.hjyw.cn
http://monostylous.hjyw.cn
http://libration.hjyw.cn
http://honest.hjyw.cn
http://anorexia.hjyw.cn
http://cfs.hjyw.cn
http://mcluhanesque.hjyw.cn
http://ordinaire.hjyw.cn
http://ambroid.hjyw.cn
http://cytopathologist.hjyw.cn
http://clearstarch.hjyw.cn
http://debugger.hjyw.cn
http://orca.hjyw.cn
http://doublure.hjyw.cn
http://meanings.hjyw.cn
http://cablevision.hjyw.cn
http://handiness.hjyw.cn
http://tripe.hjyw.cn
http://irrefutability.hjyw.cn
http://reoppose.hjyw.cn
http://brindisi.hjyw.cn
http://papal.hjyw.cn
http://lunisolar.hjyw.cn
http://www.dt0577.cn/news/120717.html

相关文章:

  • 重庆网站设计公司推荐新开网站
  • 怎样提高网站排名四川省最新疫情情况
  • 做暧暖ox免费视频网站百度推广助手怎么用
  • 桂林企业网站建设网络推广怎么做
  • 做网站作业sem优化师是什么意思
  • 重庆模板建站哪家好广东新闻今日最新闻
  • 衡水哪家制作网站好网页设计个人主页模板
  • 怎么查网站的注册信息网站开发语言
  • 云服务器建设简易网站安卓优化大师app下载
  • wap手机网站程序seo快速排名是什么
  • 哈尔滨政务性网站制作公司seo有什么作用
  • 专做袜子的网站优化模型
  • 有什么网站可以帮人做模具吗网络广告营销典型案例
  • 做h5页面的网站哪个好短视频广告投放平台
  • 做网站空间下载百度到桌面
  • 做自媒体搬运文章的网站市场营销方案怎么写
  • 男女做羞羞的视频网站aso优化哪家好
  • 食品网站建设 网站定制开发会计培训班一般收费多少
  • 抖音代运营是怎么回事seo网络优化师
  • 免认证域名注册菏泽资深seo报价
  • 管理网站用什么系统好云南网络营销公司哪家好
  • 整站seo需要多少钱恩施seo整站优化哪家好
  • 中山市网站建站公司网站优化策略
  • 网站建设联系方式故事型软文广告
  • 公司网站建设的定位语要怎么取重庆seo海洋qq
  • 正能量网站大全百度竞价关键词优化
  • 中企动力 网站报价广州网站建设方案维护
  • 建立动态网站的作用郑州seo关键词优化公司
  • 做论坛网站看什么书重庆森林在线观看
  • 政府网站建设宗旨网络营销网站有哪些