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

📄 test.c

📁 moxa串口服务器串口cts_rts_dsr_dtr应用程序源码
💻 C
字号:
#include <stdio.h>
#include "sio.h"

int main(int argc, char **argv[])
{
	int nSelect, bStop=0;
	int fd0,fd1;
	char buf0[12]="1234567890";
	char buf1[12];
	int nResult = 0;
	int lctrl_mode = 0;

	
	while(!bStop)
	{
		printf("***********************************\n");
		printf("1.serial read/write test\n");
		printf("2.CTS/RTS test \n");
		printf("3.DSR/DTR test \n");
		printf("0.Quit\n");
		printf("Please input your selection>");
		scanf("%d",&nSelect);
		
		switch(nSelect)
		{
			case 0:
				bStop=1;
				break;
			case 1:
				fd0=sio_open(0);
				fd1=sio_open(1);
				
				printf("buf0:%s\n",buf0);
				sio_write(fd0, buf0, 10);
				usleep(1000000);
				sio_read(fd1, buf1, 10);
				buf1[10]='\0';
				printf("buf1:%s\n",buf1);
				
				close(fd0);
				close(fd1);
				break;
			case 2:
				fd0=sio_open(0);
				fd1=sio_open(1);
				
				printf("port0:RTS turn on\n");
				sio_RTS(fd0, 1);			/* RTS on */
				nResult=sio_lstatus(fd1);			/* read the RTS status */
				if( nResult & S_CTS )	/* CTS */
					printf("port1:CTS turn on detected\n");
				else
					printf("port1:CTS turn off detected\n");
				
				printf("port0:RTS turn off\n");
				sio_RTS(fd0, 0);			/* RTS off */
				nResult=sio_lstatus(fd1);			/* read the RTS status */
				if( nResult & S_CTS )	/* CTS */
					printf("port1:CTS turn on detected\n");
				else
					printf("port1:CTS turn off detected\n");

				printf("port0:RTS turn on\n");
				sio_RTS(fd0, 1);			/* RTS on */
				nResult=sio_lstatus(fd1);			/* read the RTS status */
				if( nResult & S_CTS )	/* CTS */
					printf("port1:CTS turn on detected\n");
				else
					printf("port1:CTS turn off detected\n");

				close(fd0);
				close(fd1);
				break;
			case 3:
				fd0=sio_open(0);
				fd1=sio_open(1);
				
				printf("port0:DTR turn on\n");
				lctrl_mode |= C_DTR;
				sio_lctrl(fd0, lctrl_mode);			/* DTR on */
				nResult=sio_lstatus(fd1);			/* read the RTS status */
				if( nResult & S_DSR )	/* DSR */
					printf("port1:DSR turn on detected\n");
				else
					printf("port1:DSR turn off detected\n");

				printf("port0:DTR turn off\n");
				lctrl_mode &= ~C_DTR;
				sio_lctrl(fd0, lctrl_mode);			/* DTR off */
				nResult=sio_lstatus(fd1);			/* read the DSR status */
				if( nResult & S_DSR )	/* DSR */
					printf("port1:DSR turn on detected\n");
				else
					printf("port1:DSR turn off detected\n");

				printf("port0:DTR turn on\n");
				lctrl_mode |= C_DTR;
				sio_lctrl(fd0, lctrl_mode);			/* DTR on */
				nResult=sio_lstatus(fd1);			/* read the RTS status */
				if( nResult & S_DSR )	/* DSR */
					printf("port1:DSR turn on detected\n");
				else
					printf("port1:DSR turn off detected\n");
					
				close(fd0);
				close(fd1);
				break;
			default:
				printf("Please input your choice again!\n");
				break;
		}
	}	
	
	return 0;
}

⌨️ 快捷键说明

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