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

📄 test485.zrg

📁 掌机使用Zzbase语言的各种的关于各种电力规约如645
💻 ZRG
字号:
**************485通讯测试程序*****************

***定义变量区***
define var
	szBaud: C, 20[5]={"1. 1200bps",
					  "2. 2400bps",
					  "3. 9600bps",
					  "4. 38400bps",
					  "5. 115200bps"}
	szOperate: C, 20[3]={"1. 按键发送",
						 "2. 连续发送",
						 "3. 接收"}
	nMenuChoice: N, 3
	nBaud: N, 6
	nSend: N, 1
	cKey: C, 1
	i: N, 3
enddef


***发送子程序***
procedure SendComm
	initsio nBaud, "N", 8
	set com to 1 /485
	clear 2
	@2,0 say "正在发送..."
	@3,0
	do while .t.
		wait "" to cKey
		if asc(cKey)<>24
			if nSend=1
				send asc(cKey)
				@row(),col() say cKey
			else
				do while .t.
					send asc(cKey)
					@row(),col() say cKey
					if testkb()
						wait "" to cKey
						if asc(cKey)=24
							return
						endif
					endif
					if row()=0 .and. col()=0
						@3,0
					endif
					i=0
					do while i<6
						i=i+1
					enddo
				enddo
			endif
		else
			exit
		endif
		if row()=0 .and. col()=0
			@3,0
		endif
	enddo
	return
endpro


***接收子程序***
procedure RecvComm
	initsio nBaud, "N", 8
	set com to 1 /485
	clear 2
	@2,0 say "正在接收..."
	@3,0
	do while .t.
		cKey=chr(receive())
		@row(),col() say cKey
		if row()=0 .and. col()=0
			@3,0
		endif
		if lastkey()=24
			if testkb()
				wait ""
			endif
			exit
		endif
	enddo
	return
endpro


***主程序***
start
	do while .t.
		clear
		@0,0 say "  --485通讯测试--  "
		@2,0 say "请选择波特率:"
		@3,4 menu szBaud, 5, 5
		read menu to nMenuChoice
		do case
			case nMenuChoice=1
				nBaud=1200
			case nMenuChoice=2
				nBaud=2400
			case nMenuChoice=3
				nBaud=9600
			case nMenuChoice=4
				nBaud=38400
			case nMenuChoice=5
				nBaud=115200
			otherwise
				exit
		endcase

		nMenuChoice=1
		do while .t.
			clear 2
			@2,0 say "请选择操作:"
			@3,6 menu szOperate, 3, 3
			read menu to nMenuChoice
			do case
				case nMenuChoice=1 .or. nMenuChoice=2
					nSend=nMenuChoice
					do SendComm
				case nMenuChoice=3
					do RecvComm
				otherwise
					exit
			endcase
		enddo
	enddo
endstart

⌨️ 快捷键说明

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