单总线协议转换器在分布式测控系统中的应用
javascript:window.open(this.src);" style="cursor:pointer;"/>
下面是用VB6.0开发工具调用TMEX的API函数,驱动DS2480B进行单总线通信的程序。
......
Dim dmmy,search, result as integer
Dim Myhandle as long
State-buffer(15360) as byte
Private declare function TMExtendedStartSession lib "IBFS32.DLL"(Byval portnum as integer Byval portType as integer, Byval reserved as any) as long
Private declare function TMsetup lib "IBFS32.DLL"(Byval session_handle as long ,state_buffer as byte) as integer
Private declare function TMfirst lib "IBFS32.DLL" (Byval session_handle as long, state_buffer as byte) as integer
Private declare function TMrom lib "IBFS32.DLL" (Byval session_handle as long, state_buffer as byte, rom as integer) as integer
Private declare function TMendsession lib "IBFS32.DLL"(Byval session_handle as long) as integer
......
Myhandle= TMExtendedStartSession(1,5,vbNullstring)
'检查DS2480B是否准备就绪,准备建立会话注意,针
'对DS2480B,该函数第2个参数必须为5
If (Myhandle>0) then '成功建立会话
Dmmy=TMSetup(Myhandle) '初始化
Search=TMFirst(Myhandle,state_buffer(0)) '查找设备,找
'到第1个设备返回"1"
If (search=1) then
ROM[0] = 0; '表示读数据
result = TMRom(session_handle, state_buffer(0), ROM(0));
if (result = 1) then
'此时ROM中数据表示该设备的64位ROM序列号,其中
' ROM[0]为器件类型代码,如ROM(0)=20H 表示找到
' DS2450, ROM[7] 存放的是 8 bit CRC
...... '对找到的设备进行相应操作
......
end if
dmmy= TMendsession(Myhandle) '结束会话,释放单总线
......
结束语
基于DS2480B的单总线分布式测控系统,具有节省I/O口线资源、结构简单、开发快捷、成本低廉、便于总线扩展和维护等优点,因此有广阔的应用空间,具有较大的推广价值。