📄 4.zrg
字号:
define var
nBaud :n,10
MenuChoice:n,1
mMenu :c,16[6]
szSendString: C, 20
date1:c,8
time1:c,8
datetime:c,16
szReceiveString1: c,230
j: n,10
cKey: C, 1
b: n, 6
c:n,6
nData: n, 12
a: n,15
i:n,15
s:c,230
s1:c,2
yl:c,30
k:n,15
presult:n,15
flen:n,15
nresult:n,15
enddef
define database a
帧id :n,3 && n是类型,3是宽度
帧数据 :c,230
enddef
procedure UpData
clear
@0,0 say "===================="
@1,0 say " 上位机通讯"
@2,0 say "===================="
@9,0 say "===================="
@3,0 say "等待上位机通讯..."
@0,0 say "正在写文件..."
presult=0
flen=0
presult=fopen("\\k.dat","a") &&存的路径和文件名
&&@1,0 say "向1.dat文件写入内容"
flen=fread(szReceiveString1{1,218},presult) &&把你的缓冲区写入1.dat文件
sends szReceiveString1{1,218}
&&@3,0 say "字节数:"+str(flen,8)
&&sound 2,2
nresult=fclose(presult) &&关闭1.dat文件
return
endpro
procedure DataCollection
return
endpro
procedure SetBaud
return
endpro
***************************************************主程序***************************************************
procedure testcomm
clear
@2,0 say "按任意键开始测试..."
wait "" to cKey
Initsio 9600,"o",8 &&初始化串口
Set Com To 1
szSendString=space(10)
szSendString{1,10} = "\x54\x50\x53\x48\x00\x00\x00\x00\x50\x54"
sends szSendString{1,10}
date1=left(date(),2)+substr(date(),4,2)+substr(date(),7,2)
time1=left(time(),2)+substr(time(),4,2)+substr(time(),7,2)
datetime=date1+time1
@2,0 say datetime
APPEND BLANK
replace 帧数据 with trim(datetime)
@0,0 say "正在写文件..."
yl="\\k.dat"
presult=0
flen=0
presult=fopen(yl,"a") &&存的路径和文件名
&&@1,0 say "向1.dat文件写入内容"
flen=fwrite(datetime{1,12},presult) &&把你的缓冲区写入1.dat文件
&&@3,0 say "字节数:"+str(flen,8)
&&sound 2,2
nresult=fclose(presult) &&关闭1.dat文件
k=0
do while k<=511 &&1022 &&要拆分成511个230字节接收
&&szReceiveString1=space(230) &&使用前清空
j = Receives(szReceiveString1{1,218},8) &&获取当前接受字节数
if(j =218) &&如果接受到字节
clear
@0,0 say "正在写文件..."
yl="\\k.dat"
presult=0
flen=0
presult=fopen(yl,"a") &&存的路径和文件名
&&@1,0 say "向1.dat文件写入内容"
flen=fwrite(datetime{1,218},presult) &&把你的缓冲区写入1.dat文件
&&@3,0 say "字节数:"+str(flen,8)
&&sound 2,2
nresult=fclose(presult) &&关闭1.dat文件
@5,0 say k
k=k+1
j=0
else
@5,0 say "测试失败!"
exit
endif
enddo
@8,0 say "按任意键继续"
wait "" to cKey
return
endpro
start
nBaud = 9600 &&指定波特率
set com to 1 &&设置串口!
do while .t. &&无限循环
clear &&清屏
MenuChoice=1 &&菜单序号变量
&&mMenu[1]="[1] 数据采集"
&&mMenu[2]="[2] 系统设置"
mMenu[3]="[3] 历史采样"
mMenu[4]="[4] 上位机通讯"
@3,4 menu mMenu,4,4
READ MENU TO MenuChoice
do case
case MenuChoice=1
do DataCollection
case MenuChoice=2
do SetBaud
case MenuChoice=3
do testcomm
case MenuChoice=4
do UpData
otherwise
endcase
enddo
endstart
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -