yekingger 发表于 2006-7-6 22:47:17

串口通讯如何保证总是从第一字节开始读(附图)

我用串口读函数从一台彩色分析仪读数据,该分析仪处于不断数据输出状态,输出格式:P1(空格)***;***;****(空格) 共16个字节。我现要求程序总是从第一个程序“P”开始读,然后正确显示:P1(空格)***;***;****(空格)(如附件正确界面图片)。但实际上程序有时非从第一个字节开始读,造成错误显示,例如: ;****(空格)P1(空格)***;***(如附件错误界面图片)。有什么办法可使程序总是从第一个字节“P”开始数据?附件有程序。
请看图片
<img src="attachments/dvbbs/2006-7/20067614463098288.jpg" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt=\'Click here to open new window\nCTRL+Mouse wheel to zoom in/out\';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor=\'hand\'; this.alt=\'Click here to open new window\nCTRL+Mouse wheel to zoom in/out\';}" onclick="if(!this.resized) {return true;} else {window.open(\'attachments/dvbbs/2006-7/20067614463098288.jpg\');}" onmousewheel="return imgzoom(this);" alt="" />
<img src="attachments/dvbbs/2006-7/20067614465545460.jpg" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt=\'Click here to open new window\nCTRL+Mouse wheel to zoom in/out\';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor=\'hand\'; this.alt=\'Click here to open new window\nCTRL+Mouse wheel to zoom in/out\';}" onclick="if(!this.resized) {return true;} else {window.open(\'attachments/dvbbs/2006-7/20067614465545460.jpg\');}" onmousewheel="return imgzoom(this);" alt="" />

Kingger 发表于 2006-7-7 22:31:08

<P>TO:cpubbs</P>
<P>能详细点吗?怎么设?</P>

cpubbs 发表于 2006-7-8 05:59:43

在VISA里面有这个节点VISA Set I/O Buffer Size,兄弟你查找一下试试看行不行!

sunshuai03 发表于 2006-7-10 02:14:16

显示的时候处理也可以啊,先把缓冲区的数都读出来,显示的时候从P开始显示就可以了。

lgh269 发表于 2006-7-11 05:19:58

<P>还有一个法,就是在VISA Read -byte count端口接VISA bytes at serial port</P>
<P>这样可以按你仪器的输出来显示</P>
<P>如果仪器显示方式不是按规定方式,可以用循环(移位寄存器)加字符处理match pattern</P>
<P>具体的你可以再看是否须要其它的,</P>
<P>应该可以实现大多显示的要求</P>

yekingger 发表于 2006-7-6 22:48:22

这是程序图

pp<img src="attachments/dvbbs/2006-7/20067614481985161.jpg" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt=\'Click here to open new window\nCTRL+Mouse wheel to zoom in/out\';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor=\'hand\'; this.alt=\'Click here to open new window\nCTRL+Mouse wheel to zoom in/out\';}" onclick="if(!this.resized) {return true;} else {window.open(\'attachments/dvbbs/2006-7/20067614481985161.jpg\');}" onmousewheel="return imgzoom(this);" alt="" />

cpubbs 发表于 2006-7-6 23:46:59

设定一个缓冲区试试!
页: [1]
查看完整版本: 串口通讯如何保证总是从第一字节开始读(附图)