快速入门指南R&S FSL - Rohde & Schwarz

快速入门指南R&S FSL - Rohde & Schwarz 快速入门指南R&S FSL - Rohde & Schwarz

rohde.schwarz.cz
from rohde.schwarz.cz More from this publisher
12.07.2015 Views

远 程 控 制 编 程 的 基 本 步 骤R&S FSLPublic Sub InstrRead(ByVal vi As Long, Response As String, ByVal count As Long,retCount As Long)Dim status As Long'Initialize response stringResponse = Space(count)'...and readstatus = viRead(vi, Response, count, retCount)'Check for errors – this will raise an error if status is not VI_SUCCESSCALL CheckError(vi, status)'adjust string lengthResponse = Left(Response, retCount)End Sub下 面 的 函 数 说 明 了 如 何 进 行 状 态 / 错 误 检 测 。 在 出 现 一 个 VISA 错 误 时 , 该 程 序 就 会 产 生 一 个异 常 :Public Sub CheckError(ByVal vi As Long, status As Long)Dim ErrorMessage As String * 1024'Initialize error message stringErrorMessage = ""If (status < 0) Then'Query the error message from VISAIf (viStatusDesc(vi, status, ErrorMessage) = VI_SUCCESS) ThenErr.Description = ErrorMessageEnd IfErr.Raise (status)End IfEnd Sub初 始 化 和 默 认 状 态在 每 个 程 序 的 开 始 部 分 , 必 须 创 建 所 有 子 程 序 使 用 的 全 局 变 量 。 接 着 , 远 程 控 制 和 仪 器 设 置将 被 更 改 为 定 义 的 默 认 状 态 。 为 此 , 使 用 了 两 个 子 例 程 “ InitController ” 和“InitDevice”。创 建 全 局 变 量在 Visual Basic 中 , 全 局 变 量 存 储 在 模 块 中 ( 文 件 扩 展 名 .BAS)。 这 样 , 至 少 应 该 创 建 一 个模 块 ( 如 GLOBALS.BAS), 该 模 块 包 含 所 有 子 程 序 使 用 的 变 量 , 比 如 远 程 控 制 驱 动 程 序 所使 用 的 仪 器 地 址 变 量 。在 下 面 给 出 的 所 有 例 子 中 , 文 件 都 必 须 包 含 下 面 的 指 令 :Global analyzer As LongGlobal defaultRM As Long11300.2519.69 6.4 ZH-4

R&S FSL远 程 控 制 编 程 的 基 本 步 骤初 始 化 远 程 控 制 会 话REM –––––––––––– 初 始 化 远 程 控 制 会 话 –––––––––––––––––-----------------------––Public SUB Initialize()Dim status As Long'CALL viOpenDefaultRM to get the resource manager handle'Store this handle in defaultRM. The function viStatusDesc'returns a text description of the status code returned by viOpenDefaultRMstatus = viOpenDefaultRM(defaultRM)status = viStatusDesc(defaultRM, status, Response)'Open the connection to the device and store the handle'Note: The timeout value in viOpen() applies only for opening the interface'For setting the communication timeout, set the VI_ATTR_TMO_VALUE attribute'timeout values are in milliseconds'This example assumes the instrument IP address 10.0.0.10'If the network provides a name resolution mechanism, the hostname of'the instrument can be used instead of the numeric IP address'the resource string for GPIB would be "GPIB::20::INSTR''status = viOpen(defaultRM, "TCPIP::10.0.0.10::INSTR'', 0, 1000, analyzer)'status = viOpen(defaultRM, "TCPIP::::INSTR'', 0, 1000, analyzer)'status = viOpen(defaultRM, "GPIB::20::INSTR'', 0, 1000, analyzer)'Set timeout value – here 5sstatus = viSetAttribute(vi, VI_ATTR_TMO_VALUE, 5000)END SUBREM ***********************************************************************初 始 化 仪 器设 定 远 程 控 制 状 态 寄 存 器 和 仪 器 设 置 为 默 认 状 态 。REM –––––––––––– 初 始 化 仪 器 ––––––––––––––––––––––––------------------–––––––Public SUB InitDevice()CALL InstrWrite(analyzer, "*CLS")CALL InstrWrite(analyzer, "*RST")'Reset status register'Reset instrumentEND SUBREM************************************************************************1300.2519.69 6.5 ZH-4

R&S <strong>FSL</strong>远 程 控 制 编 程 的 基 本 步 骤初 始 化 远 程 控 制 会 话REM –––––––––––– 初 始 化 远 程 控 制 会 话 –––––––––––––––––-----------------------––Public SUB Initialize()Dim status As Long'CALL viOpenDefaultRM to get the resource manager handle'Store this handle in defaultRM. The function viStatusDesc'returns a text description of the status code returned by viOpenDefaultRMstatus = viOpenDefaultRM(defaultRM)status = viStatusDesc(defaultRM, status, Response)'Open the connection to the device and store the handle'Note: The timeout value in viOpen() applies only for opening the interface'For setting the communication timeout, set the VI_ATTR_TMO_VALUE attribute'timeout values are in milliseconds'This example assumes the instrument IP address 10.0.0.10'If the network provides a name resolution mechanism, the hostname of'the instrument can be used instead of the numeric IP address'the resource string for GPIB would be "GPIB::20::INSTR''status = viOpen(defaultRM, "TCPIP::10.0.0.10::INSTR'', 0, 1000, analyzer)'status = viOpen(defaultRM, "TCPIP::::INSTR'', 0, 1000, analyzer)'status = viOpen(defaultRM, "GPIB::20::INSTR'', 0, 1000, analyzer)'Set timeout value – here 5sstatus = viSetAttribute(vi, VI_ATTR_TMO_VALUE, 5000)END SUBREM ***********************************************************************初 始 化 仪 器设 定 远 程 控 制 状 态 寄 存 器 和 仪 器 设 置 为 默 认 状 态 。REM –––––––––––– 初 始 化 仪 器 ––––––––––––––––––––––––------------------–––––––Public SUB InitDevice()CALL InstrWrite(analyzer, "*CLS")CALL InstrWrite(analyzer, "*RST")'Reset status register'Reset instrumentEND SUBREM************************************************************************1300.2519.69 6.5 ZH-4

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!