关于串口发送数据,我做了如下程序,请师傅们指点下:
thisform.LockScreen=.t.
nhandle=Sqlstringconnect("Driver={Microsoft Access Driver (*.mdb)}; Dbq=\\Jls4\ENRAF\DATA\tankdatart;Pwd=")
IF
nhandle<=0
MESSAGEBOX("数据库连接失败!!!",16,
'错误信息')
RETURN
ELSE
&&取数据成功
Ac=SQLEXEC(nhandle,"Select tankname,localtime,displacerlevel,temperature From tankdata ","T_cs")
IF
Ac<0
MESSAGEBOX("读取数据错误!",16,
'错误信息')
RETURN
ELSE
SELECT
ALLTRIM(tankname) tankname,TTOC(localtime) localtime ,ALLTRIM(STR(displacerlevel)) displacerlevel,ALLTRIM(STR(ROUND(temperature,1))) temperature
FROM t_cs INTO CURSOR t_cs1
SELECT t_cs1
cmsg=""
SCAN
&&从第一条记录到最后一条记录
FOR ii=1 TO 4
&&从第一个字段到最后一个字段
x=Evaluate(FIELD(ii)) &&要发送的数据
z=""
FOR i=1 TO LENc(x)
y=ALLTRIM(STR(ASC(SUBSTRc(x,i,1))))
z=z+CHR(13)+CHR(10)+y
eNDFOR
cmsg=cmsg+z
ENDFOR
&&最后一个字段
ENDSCAN
&&循环到最后一条记录结束
ENDIF
= SQLDISCONNECT(nhandle)
&&关闭连接
Set Library To e:\应急数据\myFll
hCom1=ComOpen(4,"2400,S,8,1")&&这里是串口的参数,比如9600等
If hCom1== ""
MessageBox("无法打开串口com1!")
Return
EndIf
ComWrite(hCom1,cMsg) &&向串口输出
ComClose(hCom1)&&关闭串口
Set Library To
ENDIF
thisform.refresh
thisform.LockScreen=.f.