当前位置:文档之家› lis通讯,串口通讯协议

lis通讯,串口通讯协议

竭诚为您提供优质文档/双击可除lis通讯,串口通讯协议篇一:lis系统通讯程序原理与实现篇二:利用powerbuilder实现lis系统中的串口通讯利用powerbuilder实现lis系统中的串口通讯南晓北,书恒(赤峰学院,内蒙古赤峰024000)摘要:介绍了如何使用powerbuilder中的mscomm控件来实现检验仪器与计算机之间的串口通讯。

关键词:lis、mscomm控件、串口通讯随着医院信息系统技术日趋成熟,如今医院信息系统在医院得到广泛应用。

检验信息系统(lis:laboratoryinformationsystem)是医院信息系统中一个较大组成部分。

利用计算机对检验仪器进行数据的自动采集是医院检验科室信息化建设中的重要内容。

串口因其速度快所以是目前检验仪器大量采用的一种数据传输端口。

pb (powerbuilder)工具软件是sybase公司开发的分布式数据库应用程序的前端开发工具,它以功能强大、使用灵活的数据窗口,面向对象的、具有可视图形界面的开发能力等优势,因此深受广大数据库开发人员的青睐。

目前使用pb作为大型医院信息系统前端开发工具占据了很大比例,使用pb 进行lis系统串口通讯程序的开发也是被广泛应用的一种方式。

一、mscomm控件常用的属性及通讯方法在使用pb开发lis系统串口通讯程序应首先来了解一下微软的microsoftcommunicationscontrol(简称mscomm)控件,mscomm属于windows下串行通讯编程的activex控件,它为应用程序提供了通过串行端口传输和接收数据,为应用程序提供串行通讯功能。

1、mscomm控件的常用属性commport:设置用户所选用的通讯端口号。

settings:以字符串的形式设置并返回波特率、奇偶校验、数据位、停止位。

portopen:设置通讯端口的状态,可以打开(值为true)或关闭端口(值为False)。

input:从接收缓冲区返回和删除字符。

output:向传输缓冲区写一个字符串。

inbuffersize:设置或返回接收缓冲区的大小,缺省为1024字节。

inbuffercount:返回接收缓冲区内的等代读取的字节个数,设属性为0清除接收缓冲区。

outbuffersize:设置或返回发送缓冲区,缺省为512字节。

outbuffercounter:返回发送缓冲区内等待发送的字符数,可用0来清空缓冲区。

Rthreshold:该属性确定当接收缓冲区内字节个数达或超过该值后就产生代码为comeventReceive的oncomm事件,设置位0,则不产生oncomm 事件。

commevent:有通讯错误或事件发生时产生oncomm事件,commevent事件的值可以用来确定引发oncomm事件的具体的错误或事件常用的有以下几种comeventbreak:接受到中断信号。

comeventRxover:接收缓冲区溢出。

comeventtxFull:发送缓冲区溢出。

comeventReceive:接受到规定的字符数。

inputlen:设置或返回接收缓冲区内用input读入的个数。

若取0,则读取整个缓冲区的内容。

2、mscomm控件的通讯方法mscomm控件在处理串口通讯上有两种方法:一是事件驱动法;二是查询法。

这两种方法各自的特点如下:(1)事件驱动法是利用mscomm控件的oncomm事件捕获并处理通讯错误或事件,是处理串行端口交互作用的一种非常有效的方法。

当串口接收到或发送完指定数量的数据时,或当状态发生改变时,mscomm控件都将触发oncomm事件,该事件也可以捕获通讯中的错误。

当应用程序捕获到这些事件后,可通过检查mscomm控件的commevent属性的值来获知所发生的事件或错误,从而执行相应的处理。

这种方法具有相应及时,可靠性高等优点。

(2)查询法是在每个重要的程序之后查询mscomm控件的某些属性(比如commevent属性和inbuffercount属性)的值来检测事件和通讯错误。

二、程序实例描述在前面我们对mscomm控件有所了解之后,我们就可以将mscomm控件引入到程序中。

整个lis系统的数据流程包括his开出检验申请信息,lis主程序读取数据,仪器检验结果数据通过通讯程序写入lis结果数据表等。

本文所要研究的就是仪器检验结果通过通讯程序写入lis结果数据表这一程序实例。

第一步:选择适合的数据库设计相关数据表(这个主要是根据使用需要和编程人员的使用习惯)就我看来使用中型数据库如:sqlserver就可以。

第二步:设计应用程序界面。

在这里主要说一下如何插入mscomm控件,在设计窗口插入mscomm控件的步骤:选中createolecontrol在insertobject会话框中选中insertcontrol页卡中的microsoftcommunicationscontrol 项,这便完成了添加mscomm控件。

如下图第三步:这一步是编写程序的重点与难点,在完成上面的界面设计之后我们就要为界面里的控件编写代码。

在界面设计时除mscomm控件外还有两项是必需要设计的。

一个是通讯端口选择,因为一台计算机有多个串口(com1,com2,……)如果一台计算机连接两台或更多的仪器时就要凭借通讯端口来区分数据和接收数据。

另一个是通讯参数配置,检验仪器进行数据传输时会根据仪器自身的参数来进行通讯,这些参数包括:波特率,数据位,停止位,校验位。

接下来我们来重点看一下对mscomm控件相关事件及相关函数的编写。

1、为mscomm控件编写oncomm事件注:代码中ole_comm_one为mscomm控件的名称stringls_receipt_datacharlc_char_dataintegerli_len,ils_receipt_data=ole_comm_one.object.inputifgs_status=pthenreturnli_len=len(ls_receipt_data)fori=1toli_lenlc_char_data=mid(ls_receipt_data,i,1)f_comm_char_monitor(lc_char_data)next2、f_comm_char_monitor函数:它的功能是当有字符触发则进行接受,代码如下:integerli_asc_valueli_asc_value=asc(lc_data)choosecaseli_asc_valuecasestxgs_current_result=lc_datacaseetxgs_current_result+=string(lc_data)f_analyse_data(gs_current_result)//对接收的数据进行分析gs_current_result=""caseelsegs_current_result+=string(lc_data)endchoosereturn03、f_analyse_data函数它的功能是分析结果数据,分离出工作单号及结果(在下面代码中有被注释的定义参数,把它写进来是来讲述如何使用mscomm控件相关参数)。

integerblockseqoffset=2integerblockseqlength=1integerFuoffset=3integerFulength=2integersamplenooffset=5//integersamplenolength=5//integerdisknooffset=10//integerdisknolength=1//integerpositionnooffset=11//integerpositionnolength=3//integeridnooffset=14//integeridnolength=13//integerageoffset=27//integeragelength=4//integersexoffset=31//integersexlength=1//integerbldcoltimeoffset=32//integerbldcoltimelength=10integerchannelcountoffset=42integerchannelcountlength=3integerResultdataoffset=45integerli_channel_count,istringls_block_seq,ls_fu,ls_channel_blockstringls_result_datastringls_property_charstringls_working_idstringls_instru_item_code,ls_instru_item_hard_code stringls_item_resultstringls_indicatorstringls_unitls_result_data=ls_datals_fu=mid(ls_result_data,Fuoffset,Fulength)ifnot(ls_fu=n1orls_fu=n2orls_fu=n1orls_fu=n2)thenw_ main.tab_show.tabpage_current_result.mle_current_re sult.text=ls_datareturn1endifls_block_seq=mid(ls_result_data,blockseqoffset,bloc kseqlength)li_channel_count=integer(trim(mid(ls_result_data,ch annelcountoffset,channelcountlength)))ifls_block_seq=1then//消息开始记录g_struc_result.count=0endiffori=0toli_channel_count-1ls_instru_item_hard_code=trim(mid(ls_result_data,Re sultdataoffset+i*10+1,3))ls_instru_item_code=profilestring(gs_ini_file,itemc odealia,ls_instru_item_hard_code,ls_instru_item_hard_code)ls_unit=profilestring(gs_ini_file,itemunits,ls_inst ru_item_hard_code,)ls_item_result=trim(mid(ls_result_data,Resultdataof fset+i*10+4,6))ls_indicator=trim(mid(ls_result_data,Resultdataoffs et+i*10+10,1))g_struc_result.count++g_struc_result.item_no[g_struc_result.count]=g_stru c_result.countg_struc_result.result[g_struc_result. count]=ls_item_resultg_struc_result.instrument_item_code[g_struc_result. count]=ls_instru_item_codeg_struc_result.normal_indicator[g_struc_result.coun t]=ls_indicatorg_struc_result.units[g_struc_result. count]=ls_unitnextifls_block_seq=:then//消息结束记录g_struc_result.result_datetime=datetime(today(),now ())ls_working_id=string(integer(mid(ls_result_data,sam plenooffset+(5-gi_samplenolen),gi_samplenolen)),Fil l(0,gi_samplenolen))。

相关主题