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

📄 test01.c

📁 这是实际项目中的一个串口通信程序. Makefile通过开关, 可使此程序适用于 Linux 和嵌入式 ARM Linux. 代码注释较多. 是学习UART或Serail Port 通信的一个好例子.
💻 C
字号:
#include "SerialBase.h"

int main(void)
{
	//Step 1: Initilize the DLL
	int retVal = DllInit("/dev/ttyS0");
	if(!retVal)
	{
		printf("DllInit is sucessful! \n");
	}
	else
	{
		return 1;
	}
	
	
//Step 2: download UID
	typedef struct  
	{
		unsigned char   uniqueNodeId[6];
	}UID;

	UID aUid;
	int i ;
	for(i=0; i<6; i++)
	{
		aUid.uniqueNodeId[i] = 0x10 +i;
	}

	if(DownloadUID((unsigned char*)&aUid, 1) == 0)   //Be careful this is a struct not an array.
	{
		printf("DownloadUID Successful!\n"); //failure to Init dll
	}
	else
	{
		printf("DownloadUID Failed!\n"); //failure to Init dll
	}	

	if(DownloadUID((unsigned char*)&aUid, 1) == 0)   //Be careful this is a struct not an array.
	{
		printf("DownloadUID Successful!\n"); //failure to Init dll
	}
	else
	{
		printf("DownloadUID Failed!\n"); //failure to Init dll
	}	

//Run Net build
	if(RunNetBuild() == 0)   //Be careful this is a struct not an array.
	{
		printf("RunNetBuild Successful!\n"); //failure to Init dll
	}
	else
	{
		printf("RunNetBuild Failed!\n"); //failure to Init dll
	}	


//SendUnAckDataToTN  

	char szSndbuf[100] ="A";
	unsigned int  iSndbufLen = strlen(szSndbuf);

	int bRet = SendUnAckDataToTN((unsigned char*)&aUid,(unsigned char*)szSndbuf,iSndbufLen);//, iSndbufLen,szRcvbuf,&iRevbufLen);

	
	if(bRet != 0)
	{
		printf("an Error in SendUnAckDataToTN!\n");
	}
	else
	{

		printf("SendUnAckDataToTN is successful!\n");
	}

//	SendAckDataToTN		
	unsigned char  szRcvbuf[100] ;
	unsigned char  iRevbufLen = 0;

	bRet = SendAckDataToTN((unsigned char*)&aUid,(unsigned char*)szSndbuf, iSndbufLen,szRcvbuf,&iRevbufLen);

	if(bRet != 0)
	{
		printf("an Error in SendAckDataToTN!\n");
	}
	else
	{
		printf("SendAckDataToTN is successful!\n");
	}


//Th last step: close the Dll	
	DllCleanUp();
	
	
printf("exit from main function!\n");	
	//end 
	
}







/***************************************************************************
 *   Copyright (C) 2008 by root   *
 *   root@debian   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

/*
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include <stdlib.h>

int main01(int argc, char *argv[])
{
  printf("Hello, world!\n");

int a =100;
int b =200;

int c = a + b +20;

printf("%d\n",c);

  return EXIT_SUCCESS;
}

*/

/*
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <semaphore.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <time.h>
*/
/*
int main002() 
{
	sem_t mysemp;
	struct timespec ts;
	int sts, val;

    if ( sem_init (&mysemp, 0, 0) == -1 ) 
    {
         perror("sem_init is err");
         return -1;
    }

    perror("wait for 100s \n");
    //printf("wait for 100s\n ");
	ts.tv_sec=time(NULL)+ 10;   // �ص�
    ts.tv_nsec=0;

	/* Try to lock Semaphore */
/*	sts = sem_timedwait(&mysemp, &ts);

 	sem_destroy(&mysemp);
 	
 	perror("wait for 100s \n");
 	//printf("End of waiting  for 100s\n ");
 	
 	return 0;
}

*/

⌨️ 快捷键说明

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