VxWorks实现串口数据收发

作者:佚名 上传时间:2023-03-23 运行软件:Wind River Systems 软件版本:VxWorks6.9 版权申诉

本示例代码演示了如何在VxWorks系统中通过串口进行数据收发。通过调用系统提供的函数库进行串口的配置和收发,快速实现串口通讯。代码中包括了串口数据的读取和写入,以及常见的错误处理。

/* include files */
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h> 
#include <ioLib.h>
#include <tyLib.h>

/* define variables */
int fd;     // serial port file descriptor
char buffer[256];   // buffer for writing and reading data

/* open serial port, configure and set parameters */
fd = open ("/tyCo/1", O_RDWR, 0);
if (fd == ERROR)
{
    printf("Failed to open serial port.");
}
else
{
    if (ioctl(fd, FIOOPTIONS, OPT_RAW) == ERROR)
    {
        printf("Failed to set serial port options.");
    }
    else
    {
        if (ioctl(fd, FIOBAUDRATE, 9600) == ERROR)
        {
            printf("Failed to set serial port Baudrate.");
        }
        else
        {
            printf("Serial port configured successfuly.");
        }
    }
}

/* send data over serial port */
sprintf(buffer,"Hello VxWorks");
if (write(fd, buffer, strlen(buffer)) == ERROR)
{
    printf("Failed to write data to serial port.");
}

/* receive data from serial port */
if (read(fd, buffer, sizeof(buffer)) == ERROR)
{
    printf("Failed to read data from serial port.");
}
else
{
    printf("Received data: %s", buffer);
}

/* close serial port */
ioctl(fd, FIOFLUSH, 0);
close(fd);

免责申明:文章和图片全部来源于公开网络,如有侵权,请通知删除 server@dude6.com

用户评论
相关推荐
VxWorks实现串口数据收发
本示例代码演示了如何在VxWorks系统中通过串口进行数据收发。通过调用系统提供的函数库进行串口的配置和收发,快速实现串口通讯。代码中包括了串口数据的读取和写入,以及常见的错误处理。/* inclu
VxWorks6.9
Wind River Systems
2023-03-23 04:12
串口封装实现串口数据收发
封装串口通信过程,添加到工程中,生命命名空间,创建对象,调用方法打开就可以了
RAR
0B
2019-05-16 08:03
串口通信串口收发数据
串口通信:串口收发数据,将接收到的数据写入数据库
RAR
0B
2019-01-01 22:22
LinuxC语言实现串口收发数据
基于Linux使用C语言实现的一个串口通讯Demo,实测可用。
ZIP
0B
2019-05-13 08:38
串口程序实现收发
程序中实现了串口的自发自收,测试串口通信
C
0B
2018-12-08 16:49
串口数据收发VC
主要实现串口的自行发送和接受,要先有个串口,并将接受端和发送端直连,测试用的,适合于初学者
RAR
0B
2019-01-17 10:25
android串口收发数据
android串口收发数据,GPS调试工具,符合MB100麦哲伦主板
APK
0B
2019-07-11 20:09
串口数据收发.rar
串口数据收发C++源程序,接收串口发送固定格式的数据包,并进行解析显示在界面上。调用了mscomm32.ocx控件,需自己提前加载控件到VS中
RAR
0B
2020-05-22 21:23
vc串口收发数据
简单的串口收发数据,相当于虚拟串口的作用,可以看到你自己写的串口程序对错
RAR
24KB
2020-08-17 14:28
串口收发数据工具
串口收发数据工具,可以模拟串口收发数据情况,向该工具应用程序发送指令,它能够返回相应数据
RAR
979KB
2020-08-31 15:37