簡體   English   中英

如何從串口RS232的輸出中獲取脈沖?

[英]How to get pulses from the output of serial port RS232?

我正在使用linux,我需要用C語言編寫一個程序,以通過串行端口的o / p創建脈沖,示波器可以查看該脈沖。 怎么做? 另外如何通過C配置串行端口?

終於找到了完成它的方法

#include<time.h>
#include<unistd.h>
#include<stdio.h>
#include<errno.h>
#include<termios.h>
#include<fcntl.h>
#include<sys/ioctl.h>
int main()
{
    struct t`enter code here`imespec ts;
    ts.tv_nsec =999999999; 
    ts.tv_sec=0;
    int fd,ctr,j1,j2,j3,j4;
    fd =open("/dev/ttyS0", O_RDWR | O_NOCTTY);
    j1=ioctl(fd, TIOCMGET, &ctr);
    if(j1<0)
        perror("\nfailed1 not able to get status\n");
    else
    {
        ctr=ctr|TIOCM_DTR;
        j2=ioctl(fd,TIOCMSET,&ctr);
        if(j2<0)
            perror("\nfailed2 not able to set \n");

        else
            nanosleep(&ts,0);   

    j3=ioctl(fd,TIOCMGET,&ctr);
    if(j3<0)
        perror("failed 3 not able to get status2\n");

    else
    {
        ctr&=~TIOCM_DTR;
        j4=ioctl(fd,TIOCMSET,&ctr);
        if(j4<0)
            perror("faliure 4 not able to set 2");
        else
            nanosleep(&ts,0);
    }

    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM