VB通过RS232控制频谱分析议(LG7270)问题

来源:百度知道 编辑:UC知道 时间:2024/06/03 15:32:45
VB处理串口数据的方式好像和Windows自带的Hypertrm处理串口数据的方式是不一样的.
我写了一段测试语句抓取发送和接收的字符,比对了一下vb和Hypertrm对串口数据的处理时序,Hypertrm中是有字符就发送,而vb中我们下的指令是.Mscomm1.Input,实际是放在缓冲区中,有回车才发送,这是两者的差别,可能仪器(LG7270)接收指令的方式是跟Hypertrm一样,所以能立即返回.

另外我发现在accessPort中,只要连续发送MKA?,如果有返回值也是MKA?,然后抓值,就能抓到,所以我暂时用了最笨的方法单独写了一段vb测试语句如下,是可以抓到值的,不过测试时间不太稳定1.5S-3S,之间, 从时序上看应该0.7s里就能抓到,因该可以找到一种类似于Hypertrm的方式测试时间会在0.7里.

frmmain.MSComm1.Output = "MKA?" & Chr(13)
Wait (5)
ReportValue = frmmain.MSComm1.Input

For i = 0 To 10

If InStr(ReportValue, "dBm") Then
ReportValue = Replace(ReportValue, vbCr, "")
ReportValue = Replace(ReportValue, vbLf, "")
ReportValue = Replace(ReportValue, Chr(17), "")
ReportValue = Replace(ReportValue, Chr(19), "")
ReportValue = Replace(ReportValue, "MKA?", "")
ReportValue1 = Val(ReportValue)
Exit For
Else
frmmain.MSComm1.Output = "MKA?

过去我们用串口时,一般是2,3 交叉;7对接。就达到目的了。
你要固定设备,一定要想看【技术参数和说明书】;加上再从网上搜索一下。应该说:这块不难。祝成功!

使用ONCOMM事件来捕捉数据,详细叙述通信协议.