QT c++生成周期2ms,采样时间为2ms的锯齿波
时间: 2024-05-22 07:12:27 浏览: 10
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <errno.h>
#include <string.h>
#include <ctype.h>
#define BAUDRATE B115200
#define MODEMDEVICE "/dev/ttyS0"
#define FALSE -1
#define TRUE 0
int fd;
struct termios oldtio,newtio;
void set_serial(void)
{
fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY);
if (fd < 0) {
perror(MODEMDEVICE);
exit(-1);
}
tcgetattr(fd, &oldtio);
bzero(&newtio, sizeof(newtio));
newtio.c_cflag = BAUDRATE | CS8 | CLOCAL | CREAD;
newtio.c_iflag = IGNPAR;
newtio.c_oflag = 0;
tcflush(fd, TCIFLUSH);
tcsetattr(fd, TCSANOW, &newtio);
}
void send_serial(char *s)
{
int len = strlen(s);
int n = write(fd, s, len);
if (n < 0) {
perror("write");
}
}
void close_serial(void)
{
tcsetattr(fd, TCSANOW, &oldtio);
close(fd);
}
int main(int argc, char *argv[])
{
set_serial();
int i = 0;
while (1) {
char buf[1024];
sprintf(buf, "%d\n", i % 1024);
send_serial(buf);
usleep(2000);
i++;
}
close_serial();
return 0;
}
相关推荐
![tar](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)