Skip to content
Snippets Groups Projects
Commit 0b32909d authored by Neil Gershenfeld's avatar Neil Gershenfeld
Browse files

C 10kHz

parent bbc3c934
No related branches found
No related tags found
No related merge requests found
serialtimetest/C.SDS00002.png

17.6 KiB

serialtimetest/C.SDS00003.png

18.3 KiB

File added
//
// serialtimetest.c
// serial speed time test
//
// Neil Gershenfeld 4/11/21
// This work may be reproduced, modified, distributed,
// performed, and displayed for any purpose, but must
// acknowledge this project. Copyright is retained and
// must be preserved. The work is provided as is; no
// warranty is provided, and users accept all liability.
//
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>
#include <stdlib.h>
//
int speed,port;
unsigned char msg0 = 0;
unsigned char msg1 = 255;
//
void timer_handler (int signum) {
static int flag = 0;
if (flag == 0) {
flag = 1;
write(port,&msg0,1);
}
else {
flag = 0;
write(port,&msg1,1);
}
}
//
int main(int argc,char *argv[]) {
if (argc != 3) {
printf("command line: serialtimetest port speed\n");
return -1;
}
//
speed = atoi(argv[2]);
port = open(argv[1],O_RDWR|O_NOCTTY|O_NDELAY);
fcntl(port,F_SETFL,0);
struct termios term;
tcgetattr(port,&term);
term.c_cflag &= ~(PARENB|CSTOPB|CSIZE|CRTSCTS);
term.c_cflag |= (CS8|CREAD|CLOCAL);
term.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHONL|ISIG);
term.c_iflag &= ~(IXON|IXOFF|IXANY|IGNBRK|BRKINT
|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL);
term.c_oflag &= ~(OPOST|ONLCR);
term.c_cc[VTIME] = 0;
term.c_cc[VMIN] = 1;
cfsetispeed(&term,speed);
cfsetospeed(&term,speed);
tcsetattr(port,TCSANOW,&term);
//
struct sigaction sa;
struct itimerval timer;
memset (&sa, 0, sizeof (sa));
sa.sa_handler = &timer_handler;
sigaction (SIGALRM, &sa, NULL);
timer.it_value.tv_sec = 0;
timer.it_value.tv_usec = 100;
timer.it_interval.tv_sec = 0;
timer.it_interval.tv_usec = 100;
setitimer (ITIMER_REAL,&timer,NULL);
//
while (1);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment