⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 port.c

📁 QNX 系统下的串口通讯控制程序,可以根据自己的想法进行修改
💻 C
字号:
#include <termios.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <public.h>
#include <string.h>
#include <errno.h>  
#include <sys/time.h>
#include <hw/inout.h>
#include <sys/mman.h>
#include   "ser.h"

/***********************************************************************/
//
//OCU line-up test instrument examination tool V1.0
//author:liuwei
//date:090205
/***********************************************************************/

int main(int argc, char **argv)
{
//####################(set com1)###########################################
    int fd,i,rxdd,txdd,fxdd;
    //int nread;
    char buff[128];
    char *dev = "/dev/com1";
	char buf_f[]="startupok!";
	char buf_gsmr[]="gsm";
	char buf_file[]="fil";

	
    fd = OpenDev(dev);
    if (fd > 0)
    {
        set_speed(fd, 9600);
    }
    else
    {
        printf("Can't Open Serial Port!\n");
        return (0);
    }

    if (set_Parity(fd, 8, 1, 'N') < 0)
    {
        printf("Set Parity Error\n");
        return (1);
    }
    
//####################(Data potency )###########################################
    write(fd,buf_f,10);
    while (1)
    {
    	  read(fd, buff, 128);
    	  
          for (i=0;i<=2;i++)
          {
          	rxdd=buff[i];
          	txdd=buf_gsmr[i];
          	fxdd=buf_file[i];
          }
//####################(GSM-R Test )###########################################
          if(rxdd==txdd)
          {
			int  rc,ret;
			char *dev1 ="/dev/ser1";   
			char rbuf[15];
			char buf[]="at\r\n";
  			rc=openport(dev1); 
 			if(rc>0)
 			 {
 				ret=setport(rc,9600,8,1,'n'); 
 			 }
 			write(rc,buf,4);
  			readport1(rc,rbuf,15,50);   
 			printf("%s\n",rbuf);

			}
//####################(SDRAM Test )###########################################
			if (rxdd==fxdd)
			{
			
			    FILE* tf1;
				tf1 = fopen( "/flash/ceshi.txt", "w" );
				fputs( "temp file 1", tf1 );
				fclose( tf1 );
				remove( "/flash/ceshi.txt");
				printf("SDRAM");
			}
//####################################################################
     }     
    close(fd);
   return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -