PageRenderTime 120ms CodeModel.GetById 29ms RepoModel.GetById 2ms app.codeStats 1ms

/Library/PRIMITIVES/Controller.vb

https://bitbucket.org/davidhary/isr.scpi.vb.6.x
Visual Basic | 2878 lines | 1225 code | 235 blank | 1418 comment | 0 complexity | a8048109558df8a2a00a43f7973bb8fa MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. ''' <summary>
  2. ''' The SCPI Controller for controlling, reading from and writing to the decies..
  3. ''' The SCPI controller uses the <see cref="IPort">Port I/O</see> to control the instrument and
  4. ''' read or write SCPI structures to the instrument.
  5. ''' The <see cref="IPort">Port I/O</see> could VISA device such as SERIAL, ETHRENET or GPIB.
  6. ''' </summary>
  7. ''' <license>
  8. ''' (c) 2011 Integrated Scientific Resources, Inc.
  9. ''' Licensed under the Apache License Version 2.0.
  10. ''' Unless required by applicable law or agreed to in writing, this software is provided
  11. ''' "AS IS", WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. ''' </license>
  13. ''' <history date="01/15/05" by="David Hary" revision="1.0.1841.x">
  14. ''' Created
  15. ''' </history>
  16. ''' <history date="02/12/11" by="David Hary" revision="6.0.4060.x">
  17. ''' Based on the subsystem class of the previous version.
  18. ''' </history>
  19. Public Class Controller
  20. Implements IController
  21. #Region " CONSTRUCTORS and DESTRUCTORS "
  22. ''' <summary>
  23. ''' Initializes a new instance of the <see cref="port" /> class.
  24. ''' </summary>
  25. ''' <param name="io">The element implementing the interface to the instrument.</param>
  26. Public Sub New(ByVal io As Scpi.IPort)
  27. MyBase.New()
  28. Me._port = io
  29. End Sub
  30. ''' <summary>Calls <see cref="M:Dispose(Boolean Disposing)"/> to cleanup.</summary>
  31. ''' <remarks>Do not make this method overridable (virtual) because a derived
  32. ''' class should not be able to override this method.</remarks>
  33. Public Sub Dispose() Implements IDisposable.Dispose
  34. ' Do not change this code. Put cleanup code in Dispose(Boolean) below.
  35. ' this disposes all child classes.
  36. Dispose(True)
  37. ' Take this object off the finalization(Queue) and prevent finalization code
  38. ' from executing a second time.
  39. GC.SuppressFinalize(Me)
  40. End Sub
  41. ''' <summary>
  42. ''' Gets or sets the dispose status sentinel of the base class. This applies to the derived class
  43. ''' provided proper implementation.
  44. ''' </summary>
  45. Public Property IsDisposed() As Boolean
  46. ''' <summary>Cleans up unmanaged or managed and unmanaged resources.</summary>
  47. ''' <param name="disposing">True if this method releases both managed and unmanaged
  48. ''' resources; False if this method releases only unmanaged resources.</param>
  49. ''' <remarks>Executes in two distinct scenarios as determined by
  50. ''' its disposing parameter. If True, the method has been called directly or
  51. ''' indirectly by a user's code--managed and unmanaged resources can be disposed.
  52. ''' If disposing equals False, the method has been called by the
  53. ''' runtime from inside the finalizer and you should not reference
  54. ''' other objects--only unmanaged resources can be disposed.</remarks>
  55. Protected Overridable Sub Dispose(ByVal disposing As Boolean)
  56. If Not Me.IsDisposed Then
  57. Try
  58. If disposing Then
  59. ' Free managed resources when explicitly called
  60. Me._port = Nothing
  61. End If
  62. ' Free shared unmanaged resources
  63. Finally
  64. ' set the sentinel indicating that the class was disposed.
  65. Me.IsDisposed = True
  66. End Try
  67. End If
  68. End Sub
  69. ''' <summary>This destructor will run only if the Dispose method
  70. ''' does not get called. It gives the base class the opportunity to
  71. ''' finalize. Do not provide destructors in types derived from this class.</summary>
  72. Protected Overrides Sub Finalize()
  73. Try
  74. ' Do not re-create Dispose clean-up code here.
  75. ' Calling Dispose(false) is optimal for readability and maintainability.
  76. Dispose(False)
  77. Finally
  78. ' The compiler automatically adds a call to the base class finalizer
  79. ' that satisfies the rule: FinalizersShouldCallBaseClassFinalizer.
  80. MyBase.Finalize()
  81. End Try
  82. End Sub
  83. #End Region
  84. #Region " I IO "
  85. Private _port As IPort
  86. ''' <summary>
  87. ''' Gets reference to the Port I/O system that implements the <see cref="Scpi.IPort">SCPI Port IO</see> interface
  88. ''' for accessing the instrument.
  89. ''' </summary>
  90. ''' <value></value>
  91. ''' <returns></returns>
  92. ''' <remarks></remarks>
  93. Public ReadOnly Property Port() As IPort Implements IController.Port
  94. Get
  95. Return Me._port
  96. End Get
  97. End Property
  98. #End Region
  99. #Region " SUBSYSTEM HEADER "
  100. Private _syntaxHeader As String
  101. ''' <summary>
  102. ''' Gets or sets the subsystem syntax header.
  103. ''' </summary>
  104. ''' <value></value>
  105. ''' <returns></returns>
  106. ''' <remarks></remarks>
  107. Public Property SyntaxHeader() As String Implements IController.SyntaxHeader
  108. Get
  109. Return Me._syntaxHeader
  110. End Get
  111. Set(ByVal value As String)
  112. Me._syntaxHeader = value
  113. End Set
  114. End Property
  115. #End Region
  116. #Region " EXECUTE "
  117. ''' <summary>
  118. ''' Executes a command based on the <paramref name="command">SCPI command</paramref> syntax.
  119. ''' </summary>
  120. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}' where
  121. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see> and
  122. ''' the second item is a <paramref name="command">command</paramref>.
  123. ''' </param>
  124. ''' <remarks></remarks>
  125. Public Sub Execute(ByVal subHeader As String) Implements IController.Execute
  126. Me.Port.WriteLine(Syntax.BuildExecute(Me.SyntaxHeader, subHeader))
  127. End Sub
  128. ''' <summary>
  129. ''' Executes a command based on the <paramref name="command">SCPI command</paramref> syntax.
  130. ''' </summary>
  131. ''' <param name="modalityName">Specifies the modality name.</param>
  132. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2}' where
  133. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  134. ''' the second item is the <paramref name="modalityName">modality name</paramref> and
  135. ''' the second item is a <paramref name="command">command</paramref>.
  136. ''' </param>
  137. ''' <remarks></remarks>
  138. Public Sub Execute(ByVal modalityName As String, ByVal subHeader As String) Implements IController.Execute
  139. Me.Port.WriteLine(Syntax.BuildExecute(Me.SyntaxHeader, modalityName, subHeader))
  140. End Sub
  141. ''' <summary>
  142. ''' Executes a command constructered from the specified subsystem elements.
  143. ''' </summary>
  144. ''' <param name="modalityName">Name of the modality.</param>
  145. ''' <param name="subHeader">The sub header.</param>
  146. ''' <param name="isVerifyOperationComplete">if set to <c>true</c> [is verify operation complete].</param>
  147. ''' <param name="isRaiseDeviceErrors">if set to <c>true</c> [is raise device errors].</param>
  148. Public Sub Execute(ByVal modalityName As String, ByVal subHeader As String,
  149. ByVal isVerifyOperationComplete As Boolean, ByVal isRaiseDeviceErrors As Boolean) Implements IController.Execute
  150. Me.Port.WriteLine(Syntax.BuildExecute(Me.SyntaxHeader, modalityName, subHeader), isVerifyOperationComplete, isRaiseDeviceErrors)
  151. End Sub
  152. #End Region
  153. #Region " STRING "
  154. #Region " QUERRIES "
  155. ''' <summary>
  156. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  157. ''' </summary>
  158. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}?' where
  159. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see> and
  160. ''' the second item is a <paramref name="command">command</paramref>.
  161. ''' </param>
  162. ''' <returns></returns>
  163. ''' <remarks></remarks>
  164. Public Function QueryTrimEnd(ByVal subHeader As String) As String Implements IController.QueryTrimEnd
  165. Return Me.Port.QueryTrimEnd(Syntax.BuildQuery(Me.SyntaxHeader, subHeader))
  166. End Function
  167. ''' <summary>
  168. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  169. ''' </summary>
  170. ''' <param name="modalityName">Specifies the modality name.</param>
  171. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2}?' where
  172. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  173. ''' the second item is the <paramref name="modalityName">modality name</paramref> and
  174. ''' the thrid item is a <paramref name="command">command</paramref>.
  175. ''' </param>
  176. ''' <returns></returns>
  177. ''' <remarks></remarks>
  178. Public Function QueryTrimEnd(ByVal modalityName As String, ByVal subHeader As String) As String Implements IController.QueryTrimEnd
  179. Return Me.Port.QueryTrimEnd(Syntax.BuildQuery(Me.SyntaxHeader, modalityName, subHeader))
  180. End Function
  181. #End Region
  182. #Region " GETTERS w/ ACCESS "
  183. ''' <summary>
  184. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  185. ''' </summary>
  186. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}?' where
  187. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see> and
  188. ''' the second item is a <paramref name="command">command</paramref>
  189. ''' </param>
  190. ''' <param name="existingValue">The existing value to use for forcing instrument access if null or empty.</param>
  191. ''' <param name="access">The access <see cref="isr.Scpi.ResourceAccessLevels">level</see> to the instrument.</param>
  192. ''' <returns></returns>
  193. ''' <remarks></remarks>
  194. Public Function Getter(ByVal subHeader As String,
  195. ByVal existingValue As String,
  196. ByVal access As ResourceAccessLevels) As String Implements IController.Getter
  197. If access.IsDeviceAccess OrElse String.IsNullOrEmpty(existingValue) Then
  198. existingValue = Me.QueryTrimEnd(subHeader)
  199. End If
  200. Return existingValue
  201. End Function
  202. ''' <summary>
  203. ''' Gets a value from the instrument <see cref="SyntaxHeader">SCPI subsystem</see> <paramref name="modalityName">modality</paramref> and <paramref name="subHeader">element</paramref>.
  204. ''' </summary>
  205. ''' <param name="modalityName">Specifies the modality name.</param>
  206. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2}?' where
  207. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  208. ''' the second item is the <paramref name="modalityName">modality name</paramref> and
  209. ''' the third item is a <paramref name="command">command</paramref>
  210. ''' </param>
  211. ''' <param name="existingValue">The existing value to use for forcing instrument access if null or empty.</param>
  212. ''' <returns></returns>
  213. ''' <remarks></remarks>
  214. Public Function Getter(ByVal modalityName As String, ByVal subHeader As String,
  215. ByVal existingValue As String,
  216. ByVal access As ResourceAccessLevels) As String Implements IController.Getter
  217. If access.IsDeviceAccess OrElse String.IsNullOrEmpty(existingValue) Then
  218. existingValue = Me.QueryTrimEnd(modalityName, subHeader)
  219. End If
  220. Return existingValue
  221. End Function
  222. #End Region
  223. #Region " GETTERS w/ ACCESS w/ ELEMENT "
  224. ''' <summary>
  225. ''' Gets a value from the instrument <see cref="SyntaxHeader">SCPI subsystem</see> <paramref name="subHeader">element</paramref>.
  226. ''' Uses or updates the nullable value getter command.
  227. ''' </summary>
  228. ''' <param name="element">Specifies the <see cref="IScpiValueBase">existing element</see> where the getter command is stored.</param>
  229. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}?' where
  230. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see> and
  231. ''' the second item is a <paramref name="command">command</paramref>
  232. ''' </param>
  233. ''' <param name="existingValue">The existing value to use for forcing instrument access if null or empty.</param>
  234. ''' <param name="access">Specifies the desired access level to the instrument.</param>
  235. ''' <returns></returns>
  236. ''' <remarks></remarks>
  237. Public Function GetterString(ByVal element As IScpiValueBase,
  238. ByVal subHeader As String,
  239. ByVal existingValue As String,
  240. ByVal access As ResourceAccessLevels) As String Implements IController.GetterString
  241. If access.IsDeviceAccess OrElse String.IsNullOrEmpty(existingValue) Then
  242. If String.IsNullOrEmpty(element.GetterCommand) Then
  243. element.GetterCommand = Syntax.BuildQuery(Me.SyntaxHeader, subHeader)
  244. End If
  245. existingValue = Me.Port.QueryTrimEnd(element.GetterCommand)
  246. ' value = Me.QueryTrimEnd(subHeader)
  247. End If
  248. Return existingValue
  249. End Function
  250. ''' <summary>
  251. ''' Gets a value from the instrument <see cref="SyntaxHeader">SCPI subsystem</see> <paramref name="modalityName">modality</paramref> and <paramref name="subHeader">element</paramref>.
  252. ''' </summary>
  253. ''' <param name="element">Specifies the <see cref="IScpiValueBase">existing element</see> where the getter command is stored.</param>
  254. ''' <param name="modalityName">Specifies the modality name.</param>
  255. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2}?' where
  256. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  257. ''' the second item is the <paramref name="modalityName">modality name</paramref> and
  258. ''' the third item is a <paramref name="command">command</paramref>
  259. ''' </param>
  260. ''' <param name="existingValue">The existing value to use for forcing instrument access if null or empty.</param>
  261. ''' <returns></returns>
  262. ''' <remarks></remarks>
  263. Public Function GetterString(ByVal element As IScpiValueBase,
  264. ByVal modalityName As String, ByVal subHeader As String,
  265. ByVal existingValue As String,
  266. ByVal access As ResourceAccessLevels) As String Implements IController.GetterString
  267. If access.IsDeviceAccess OrElse String.IsNullOrEmpty(existingValue) Then
  268. If String.IsNullOrEmpty(element.GetterCommand) Then
  269. element.GetterCommand = Syntax.BuildQuery(Me.SyntaxHeader, modalityName, subHeader)
  270. End If
  271. ' value = Me.QueryTrimEnd(modalityName, subHeader)
  272. existingValue = Me.Port.QueryTrimEnd(element.GetterCommand)
  273. End If
  274. Return existingValue
  275. End Function
  276. #End Region
  277. #Region " GETTERS w/ ACCESS w/ SCPI VALUE "
  278. ''' <summary>
  279. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  280. ''' Uses or updates the nullable value getter command.
  281. ''' </summary>
  282. ''' <param name="element">Specifies the <see cref="IScpiValueBase">existing element</see> where the getter command is stored.</param>
  283. ''' <param name="access">The desired <see cref="ResourceAccessLevels">access level</see> to the instrument.</param>
  284. ''' <returns></returns>
  285. ''' <remarks></remarks>
  286. Public Function Getter(ByVal element As IScpiString, ByVal access As ResourceAccessLevels) As IScpiString Implements IController.Getter
  287. If access.IsDeviceAccess OrElse String.IsNullOrEmpty(element.Value) Then
  288. element.Value = Me.Port.QueryTrimEnd(element.GetterCommand)
  289. element.ActualValue = element.Value
  290. End If
  291. Return element
  292. End Function
  293. ''' <summary>
  294. ''' Gets the instrument <see cref="SyntaxHeader">SCPI subsystem</see> <paramref name="subHeader">element</paramref> value.
  295. ''' Applies readings to the <paramref name="element">existing element</paramref>
  296. ''' </summary>
  297. ''' <param name="element">Specifies the existing element where the instrument readings are applied.</param>
  298. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}?' where
  299. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see> and
  300. ''' the second item is a <paramref name="command">command</paramref>
  301. ''' </param>
  302. ''' <param name="access">The desired <see cref="ResourceAccessLevels">access level</see> to the instrument.</param>
  303. ''' <returns></returns>
  304. ''' <remarks></remarks>
  305. Public Function Getter(ByVal element As IScpiString, ByVal subHeader As String, ByVal access As ResourceAccessLevels) As IScpiString Implements IController.Getter
  306. element.Value = Me.GetterString(CType(element, IScpiValueBase), subHeader, element.Value, access)
  307. element.ActualValue = element.Value
  308. Return element
  309. End Function
  310. ''' <summary>
  311. ''' Gets the instrument <see cref="SyntaxHeader">SCPI subsystem</see> <paramref name="modalityName">modality</paramref> <paramref name="subHeader">element</paramref> value.
  312. ''' Applies readings to the <paramref name="element">existing element</paramref>
  313. ''' </summary>
  314. ''' <param name="element">Specifies the existing element where the instrument readings are applied.</param>
  315. ''' <param name="modalityName">Specifies the modality name.</param>
  316. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2}?' where
  317. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  318. ''' the second item is the <paramref name="modalityName">modality name</paramref> and
  319. ''' the third item is a <paramref name="command">command</paramref>
  320. ''' </param>
  321. ''' <param name="access">The desired <see cref="ResourceAccessLevels">access level</see> to the instrument.</param>
  322. ''' <returns></returns>
  323. ''' <remarks></remarks>
  324. Public Function Getter(ByVal element As IScpiString, ByVal modalityName As String, ByVal subHeader As String,
  325. ByVal access As ResourceAccessLevels) As IScpiString Implements IController.Getter
  326. element.Value = Me.GetterString(element, modalityName, subHeader, element.Value, access)
  327. element.ActualValue = element.Value
  328. Return element
  329. End Function
  330. #End Region
  331. #Region " SETTERS "
  332. ''' <summary>
  333. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  334. ''' </summary>
  335. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1} {2}' where
  336. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  337. ''' the second item is a <paramref name="command">command</paramref>
  338. ''' the third item represents a <paramref name="value">numeric value</paramref>.
  339. ''' </param>
  340. ''' <param name="value">The value to set in the instrument.</param>
  341. ''' <returns></returns>
  342. ''' <remarks></remarks>
  343. Public Function Setter(ByVal subHeader As String, ByVal value As String, ByVal verify As Boolean) As Boolean Implements IController.Setter
  344. Dim scpiMessage As String = Syntax.BuildCommand(Me.SyntaxHeader, subHeader, value)
  345. Me.Port.WriteLine(scpiMessage)
  346. If verify Then
  347. Dim actual As String = Me.QueryTrimEnd(subHeader)
  348. Return Not String.IsNullOrEmpty(actual) AndAlso (value = actual)
  349. Else
  350. Return True
  351. End If
  352. End Function
  353. ''' <summary>
  354. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  355. ''' </summary>
  356. ''' <param name="modalityName">Specifies the modality name.</param>
  357. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2} {3}' where
  358. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  359. ''' the second item is the <paramref name="modalityName">modality name</paramref>,
  360. ''' the third item is a <paramref name="command">command</paramref>
  361. ''' the fourth item represents a <paramref name="value">numeric value</paramref>.
  362. ''' </param>
  363. ''' <param name="value">The value to set in the instrument.</param>
  364. ''' <returns></returns>
  365. ''' <remarks></remarks>
  366. Public Function Setter(ByVal modalityName As String, ByVal subHeader As String, ByVal value As String, ByVal verify As Boolean) As Boolean Implements IController.Setter
  367. Dim scpiMessage As String = Syntax.BuildCommand(Me.SyntaxHeader, modalityName, subHeader, value)
  368. Me.Port.WriteLine(scpiMessage)
  369. If verify Then
  370. Dim actual As String = Me.QueryTrimEnd(modalityName, subHeader)
  371. Return Not String.IsNullOrEmpty(actual) AndAlso (value = actual)
  372. Else
  373. Return True
  374. End If
  375. End Function
  376. #End Region
  377. #Region " SETTERS w/ ACCESS "
  378. ''' <summary>
  379. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  380. ''' </summary>
  381. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1} {2}' where
  382. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>
  383. ''' the second item is a <paramref name="command">command</paramref> and
  384. ''' the third item is the <paramref name="value">value</paramref>.
  385. ''' </param>
  386. ''' <param name="existingValue">Specifies the existing element value where the instrument.</param>
  387. ''' <param name="access">The desired <see cref="ResourceAccessLevels">access level</see> to the instrument.</param>
  388. ''' <returns></returns>
  389. ''' <remarks></remarks>
  390. Public Function Setter(ByVal subHeader As String,
  391. ByVal existingValue As String, ByVal value As String,
  392. ByVal access As ResourceAccessLevels) As String Implements IController.Setter
  393. If access.IsVerifyAccess Then
  394. Throw New ArgumentException("Verification not supported by this method", "access")
  395. End If
  396. If access.IsDeviceAccess OrElse Not String.Equals(value, existingValue, StringComparison.OrdinalIgnoreCase) Then
  397. Me.Port.WriteLine(Syntax.BuildCommand(Me.SyntaxHeader, subHeader, value))
  398. End If
  399. Return value
  400. End Function
  401. ''' <summary>
  402. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  403. ''' </summary>
  404. ''' <param name="modalityName">Specifies the modality name.</param>
  405. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2} {3}' where
  406. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  407. ''' the second item is the <paramref name="modalityName">modality name</paramref>,
  408. ''' the second item is a <paramref name="command">command</paramref> and
  409. ''' the fourth item represents a <paramref name="value">numeric value</paramref>.
  410. ''' </param>
  411. ''' <param name="existingValue">Specifies the existing element value where the instrument.</param>
  412. ''' <param name="access">The desired <see cref="ResourceAccessLevels">access level</see> to the instrument.</param>
  413. ''' <returns></returns>
  414. ''' <remarks></remarks>
  415. Public Function Setter(ByVal modalityName As String, ByVal subHeader As String,
  416. ByVal existingValue As String, ByVal value As String,
  417. ByVal access As ResourceAccessLevels) As String Implements IController.Setter
  418. If access.IsVerifyAccess Then
  419. Throw New ArgumentException("Verification not supported by this method", "access")
  420. End If
  421. If access.IsDeviceAccess OrElse Not String.Equals(value, existingValue, StringComparison.OrdinalIgnoreCase) Then
  422. Me.Port.WriteLine(Syntax.BuildCommand(Me.SyntaxHeader, modalityName, subHeader, value))
  423. End If
  424. Return value
  425. End Function
  426. #End Region
  427. #Region " SETTERS w/ ACCESS w/ ELEMENT "
  428. ''' <summary>
  429. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  430. ''' </summary>
  431. ''' <param name="element">Specifies the <see cref="IScpiValueBase">existing element</see> where the getter command is stored.</param>
  432. ''' <param name="existingValue">Specifies the existing element value where the instrument.</param>
  433. ''' <param name="value">Specifies the value to be set using the element <see cref="IScpiValueBase.SetterCommandFormat">command</see>.</param>
  434. ''' <param name="access">The desired <see cref="ResourceAccessLevels">access level</see> to the instrument.</param>
  435. ''' <returns></returns>
  436. ''' <remarks></remarks>
  437. Public Function Setter(ByVal element As IScpiValueBase,
  438. ByVal existingValue As String, ByVal value As String,
  439. ByVal access As ResourceAccessLevels) As String Implements IController.Setter
  440. If access.IsVerifyAccess Then
  441. Throw New ArgumentException("Verification not supported by this method", "access")
  442. End If
  443. If access.IsDeviceAccess OrElse Not String.Equals(value, existingValue, StringComparison.OrdinalIgnoreCase) Then
  444. If Not String.IsNullOrEmpty(element.SetterCommandFormat) Then
  445. element.SetterCommand = String.Format(Globalization.CultureInfo.InvariantCulture, element.SetterCommandFormat, value)
  446. ElseIf String.IsNullOrEmpty(element.SetterCommand) Then
  447. Throw New ArgumentException("Element setter command is empty", "element")
  448. End If
  449. Me.Port.WriteLine(element.SetterCommand)
  450. End If
  451. Return value
  452. End Function
  453. ''' <summary>
  454. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  455. ''' </summary>
  456. ''' <param name="element">Specifies the <see cref="IScpiValueBase">existing element</see> where the getter command is stored.</param>
  457. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1} {2}' where
  458. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>
  459. ''' the second item is a <paramref name="command">command</paramref> and
  460. ''' the third item is the <paramref name="value">value</paramref>.
  461. ''' </param>
  462. ''' <param name="existingValue">Specifies the existing element value where the instrument.</param>
  463. ''' <param name="access">The desired <see cref="ResourceAccessLevels">access level</see> to the instrument.</param>
  464. ''' <returns></returns>
  465. ''' <remarks></remarks>
  466. Public Function Setter(ByVal element As IScpiValueBase,
  467. ByVal subHeader As String,
  468. ByVal existingValue As String, ByVal value As String,
  469. ByVal access As ResourceAccessLevels) As String Implements IController.Setter
  470. If access.IsVerifyAccess Then
  471. Throw New ArgumentException("Verification not supported by this method", "access")
  472. End If
  473. If access.IsDeviceAccess OrElse Not String.Equals(value, existingValue, StringComparison.OrdinalIgnoreCase) Then
  474. If String.IsNullOrEmpty(element.SetterCommandFormat) Then
  475. element.SetterCommandFormat = Syntax.BuildCommandFormat(Me.SyntaxHeader, subHeader)
  476. End If
  477. element.SetterCommand = Syntax.BuildCommand(Me.SyntaxHeader, subHeader, value)
  478. Me.Port.WriteLine(element.SetterCommand)
  479. End If
  480. Return value
  481. End Function
  482. ''' <summary>
  483. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  484. ''' </summary>
  485. ''' <param name="element">Specifies the <see cref="IScpiValueBase">existing element</see> where the getter command is stored.</param>
  486. ''' <param name="modalityName">Specifies the modality name.</param>
  487. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2} {3}' where
  488. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  489. ''' the second item is the <paramref name="modalityName">modality name</paramref>,
  490. ''' the second item is a <paramref name="command">command</paramref> and
  491. ''' the fourth item represents a <paramref name="value">numeric value</paramref>.
  492. ''' </param>
  493. ''' <param name="existingValue">Specifies the existing element value where the instrument.</param>
  494. ''' <param name="access">The desired <see cref="ResourceAccessLevels">access level</see> to the instrument.</param>
  495. ''' <returns></returns>
  496. ''' <remarks></remarks>
  497. Public Function Setter(ByVal element As IScpiValueBase,
  498. ByVal modalityName As String, ByVal subHeader As String,
  499. ByVal existingValue As String, ByVal value As String,
  500. ByVal access As ResourceAccessLevels) As String Implements IController.Setter
  501. If access.IsVerifyAccess Then
  502. Throw New ArgumentException("Verification not supported by this method", "access")
  503. End If
  504. If access.IsDeviceAccess OrElse Not String.Equals(value, existingValue, StringComparison.OrdinalIgnoreCase) Then
  505. If String.IsNullOrEmpty(element.SetterCommandFormat) Then
  506. element.SetterCommandFormat = Syntax.BuildCommandFormat(Me.SyntaxHeader, modalityName, subHeader)
  507. End If
  508. element.SetterCommand = Syntax.BuildCommand(Me.SyntaxHeader, modalityName, subHeader, value)
  509. Me.Port.WriteLine(element.SetterCommand)
  510. End If
  511. Return value
  512. End Function
  513. #End Region
  514. #Region " SETTERS w/ ACCESS w/ SCPI VALUE "
  515. ''' <summary>
  516. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  517. ''' Applies readings to the <paramref name="element">existing element</paramref>
  518. ''' Assume element has both <see cref="IScpiValueBase.GetterCommand">getter</see> and
  519. ''' <see cref="IScpiValueBase.SetterCommand">setter</see> commands specified.
  520. ''' </summary>
  521. ''' <param name="element">Specifies the element holding the existing value, which is updated.</param>
  522. ''' <param name="value">The value to set in the instrument.</param>
  523. ''' <param name="access">The desired <see cref="ResourceAccessLevels">access level</see> to the instrument.</param>
  524. ''' <returns></returns>
  525. ''' <remarks></remarks>
  526. Public Function Setter(ByVal element As IScpiString, ByVal value As String, ByVal access As ResourceAccessLevels) As IScpiString Implements IController.Setter
  527. If access.IsDeviceAccess OrElse (value <> element.Value) Then
  528. element.Value = Me.Setter(CType(element, IScpiValueBase), element.Value, value, access And Not ResourceAccessLevels.Verify)
  529. End If
  530. If access.IsVerifyAccess Then
  531. Me.Getter(element, ResourceAccessLevels.Device)
  532. element.Value = value
  533. ElseIf access.IsCacheAccess Then
  534. element.ActualValue = value
  535. End If
  536. Return element
  537. End Function
  538. ''' <summary>
  539. ''' Sets the instrument <see cref="SyntaxHeader">SCPI subsystem</see> <paramref name="subHeader">element</paramref> value.
  540. ''' Applies readings to the <paramref name="element">existing element</paramref>
  541. ''' </summary>
  542. ''' <param name="element">Specifies the existing element where the instrument readings are applied.</param>
  543. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1} {2}' where
  544. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>
  545. ''' the second item is a <paramref name="command">command</paramref> and
  546. ''' the third item is the <paramref name="value">value</paramref>.
  547. ''' </param>
  548. ''' <param name="value">The value to set in the instrument.</param>
  549. ''' <param name="access">The desired <see cref="ResourceAccessLevels">access level</see> to the instrument.</param>
  550. ''' <returns></returns>
  551. ''' <remarks>
  552. ''' Use the following code in the calling methd if verification is used:
  553. ''' <code>
  554. ''' If Not Me.Elements.IsVerified.GetValueOrDefault(False) Then
  555. ''' If String.IsNullOrEmpty(element.Value) OrElse String.IsNullOrEmpty(element.ActualValue) Then
  556. ''' return "Failed reading values from the instrument."
  557. ''' Else
  558. ''' return String.Format(Globalization.CultureInfo.CurrentCulture, "Instrument settings applied using the command '{0}' did not verify. Expected={1}. Actual={2}.", Me.Elements.Value, Me.Elements.ActualValue.Value)
  559. ''' End If
  560. ''' End If
  561. ''' </code>
  562. ''' </remarks>
  563. Public Function Setter(ByVal element As IScpiString,
  564. ByVal subHeader As String, ByVal value As String, ByVal access As ResourceAccessLevels) As IScpiString Implements IController.Setter
  565. element.Value = Me.Setter(CType(element, IScpiValueBase), subHeader, element.Value, value, access And Not isr.Scpi.ResourceAccessLevels.Verify)
  566. If access.IsVerifyAccess Then
  567. Me.Getter(element, subHeader, ResourceAccessLevels.Device)
  568. element.Value = value
  569. ElseIf access.IsCacheAccess Then
  570. element.ActualValue = value
  571. End If
  572. Return element
  573. End Function
  574. ''' <summary>
  575. ''' Sets the instrument <see cref="SyntaxHeader">SCPI subsystem</see> <paramref name="modalityName">modality</paramref> <paramref name="subHeader">element</paramref> value.
  576. ''' Applies readings to the <paramref name="element">existing element</paramref>
  577. ''' </summary>
  578. ''' <param name="element">Specifies the existing element where the instrument readings are applied.</param>
  579. ''' <param name="modalityName">Specifies the modality name.</param>
  580. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2} {3}' where
  581. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  582. ''' the second item is the <paramref name="modalityName">modality name</paramref>,
  583. ''' the second item is a <paramref name="command">command</paramref> and
  584. ''' the fourth item represents a <paramref name="value">numeric value</paramref>.
  585. ''' </param>
  586. ''' <param name="value">The value to set in the instrument.</param>
  587. ''' <param name="access">The desired <see cref="ResourceAccessLevels">access level</see> to the instrument.</param>
  588. ''' <returns></returns>
  589. ''' <remarks>
  590. ''' Use the following code in the calling methd if verification is used:
  591. ''' <code>
  592. ''' If Not Me.Elements.IsVerified.GetValueOrDefault(False) Then
  593. ''' If String.IsNullOrEmpty(element.Value) OrElse String.IsNullOrEmpty(element.ActualValue) Then
  594. ''' return "Failed reading values from the instrument."
  595. ''' Else
  596. ''' return String.Format(Globalization.CultureInfo.CurrentCulture, "Instrument settings applied using the command '{0}' did not verify. Expected={1}. Actual={2}.", Me.Elements.Value, Me.Elements.ActualValue.Value)
  597. ''' End If
  598. ''' End If
  599. ''' </code>
  600. ''' </remarks>
  601. Public Function Setter(ByVal element As IScpiString,
  602. ByVal modalityName As String, ByVal subHeader As String, ByVal value As String,
  603. ByVal access As ResourceAccessLevels) As IScpiString Implements IController.Setter
  604. element.Value = Me.Setter(CType(element, IScpiValueBase), modalityName, subHeader, element.Value, value, access And Not isr.Scpi.ResourceAccessLevels.Verify)
  605. If access.IsVerifyAccess Then
  606. Me.Getter(element, modalityName, subHeader, ResourceAccessLevels.Device)
  607. element.Value = value
  608. ElseIf access.IsCacheAccess Then
  609. element.ActualValue = value
  610. End If
  611. Return element
  612. End Function
  613. #End Region
  614. #End Region
  615. #Region " BOOLEAN "
  616. #Region " QUERRIES "
  617. ''' <summary>
  618. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  619. ''' </summary>
  620. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}?' where
  621. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see> and
  622. ''' the second item is a <paramref name="command">command</paramref>.
  623. ''' </param>
  624. ''' <param name="parser">The <see cref="isr.Core.IParser(of boolean)">boolean Parser.</see></param>
  625. ''' <returns></returns>
  626. ''' <remarks></remarks>
  627. Public Function QueryBoolean(ByVal subHeader As String, ByVal parser As isr.Core.IParser(Of Boolean)) As Nullable(Of Boolean) Implements IController.QueryBoolean
  628. Return Me.Port.QueryBoolean(Syntax.BuildQuery(Me.SyntaxHeader, subHeader), parser)
  629. End Function
  630. ''' <summary>
  631. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  632. ''' </summary>
  633. ''' <param name="modalityName">Specifies the modality name.</param>
  634. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2}?' where
  635. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  636. ''' the second item is the <paramref name="modalityName">modality name</paramref> and
  637. ''' the thrid item is a <paramref name="command">command</paramref>.
  638. ''' </param>
  639. ''' <param name="Parser">The <see cref="isr.Core.IParser(of boolean)">boolean Parser.</see></param>
  640. ''' <returns></returns>
  641. ''' <remarks></remarks>
  642. Public Function QueryBoolean(ByVal modalityName As String, ByVal subHeader As String, ByVal parser As isr.Core.IParser(Of Boolean)) As Nullable(Of Boolean) Implements IController.QueryBoolean
  643. Return Me.Port.QueryBoolean(Syntax.BuildQuery(Me.SyntaxHeader, modalityName, subHeader), parser)
  644. End Function
  645. #End Region
  646. #Region " GETTERS w/ ACCESS "
  647. ''' <summary>
  648. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  649. ''' </summary>
  650. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}?' where
  651. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see> and
  652. ''' the second item is a <paramref name="command">command</paramref>
  653. ''' </param>
  654. ''' <param name="existingValue">The existing value. The instrument is accessed if this value has no value.</param>
  655. ''' <param name="parser">The <see cref="isr.Core.IParser(of boolean)">boolean Parser.</see></param>
  656. ''' <param name="access">The desired <see cref="ResourceAccessLevels">access level</see> to the instrument.</param>
  657. ''' <returns></returns>
  658. ''' <remarks></remarks>
  659. Public Function Getter(ByVal subHeader As String,
  660. ByVal existingValue As Nullable(Of Boolean), ByVal parser As isr.Core.IParser(Of Boolean),
  661. ByVal access As ResourceAccessLevels) As Nullable(Of Boolean) Implements IController.Getter
  662. If access.IsDeviceAccess OrElse Not existingValue.HasValue Then
  663. existingValue = Me.QueryBoolean(subHeader, parser)
  664. End If
  665. Return existingValue
  666. End Function
  667. ''' <summary>
  668. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  669. ''' </summary>
  670. ''' <param name="modalityName">Specifies the modality name.</param>
  671. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2}?' where
  672. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  673. ''' the second item is the <paramref name="modalityName">modality name</paramref> and
  674. ''' the second item is a <paramref name="command">command</paramref>.
  675. ''' </param>
  676. ''' <param name="existingValue">The existing value. The instrument is accessed if this value has no value.</param>
  677. ''' <param name="Parser">The <see cref="isr.Core.IParser(of boolean)">boolean Parser.</see></param>
  678. ''' <param name="access">The desired <see cref="ResourceAccessLevels">access level</see> to the instrument.</param>
  679. ''' <returns></returns>
  680. ''' <remarks></remarks>
  681. Public Function Getter(ByVal modalityName As String, ByVal subHeader As String,
  682. ByVal existingValue As Nullable(Of Boolean), ByVal parser As isr.Core.IParser(Of Boolean),
  683. ByVal access As ResourceAccessLevels) As Nullable(Of Boolean) Implements IController.Getter
  684. If access.IsDeviceAccess OrElse Not existingValue.HasValue Then
  685. existingValue = Me.QueryBoolean(modalityName, subHeader, parser)
  686. End If
  687. Return existingValue
  688. End Function
  689. #End Region
  690. #Region " GETTERS w/ ACCESS w/ ELEMENT "
  691. ''' <summary>
  692. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  693. ''' Uses or updates the nullable value getter command.
  694. ''' </summary>
  695. ''' <param name="element">Specifies the <see cref="IScpiValueBase">existing element</see> where the getter command is stored.</param>
  696. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}?' where
  697. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see> and
  698. ''' the second item is a <paramref name="command">command</paramref>
  699. ''' </param>
  700. ''' <param name="existingValue">The existing value. The instrument is accessed if this value has no value.</param>
  701. ''' <param name="Parser">The <see cref="isr.Core.IParser(of boolean)">boolean Parser.</see></param>
  702. ''' <param name="access">The desired <see cref="ResourceAccessLevels">access level</see> to the instrument.</param>
  703. ''' <returns></returns>
  704. ''' <remarks></remarks>
  705. Public Function Getter(ByVal element As IScpiValueBase,
  706. ByVal subHeader As String,
  707. ByVal existingValue As Nullable(Of Boolean), ByVal parser As isr.Core.IParser(Of Boolean),
  708. ByVal access As ResourceAccessLevels) As Nullable(Of Boolean) Implements IController.Getter
  709. If access.IsDeviceAccess OrElse Not existingValue.HasValue Then
  710. If String.IsNullOrEmpty(element.GetterCommand) Then
  711. element.GetterCommand = Syntax.BuildQuery(Me.SyntaxHeader, subHeader)
  712. End If
  713. ' existingValue = Me.QueryBoolean(subHeader)
  714. existingValue = Me.Port.QueryBoolean(element.GetterCommand, parser)
  715. End If
  716. Return existingValue
  717. End Function
  718. ''' <summary>
  719. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  720. ''' Uses or updates the nullable value getter command.
  721. ''' </summary>
  722. ''' <param name="element">Specifies the <see cref="IScpiValueBase">existing element</see> where the getter command is stored.</param>
  723. ''' <param name="modalityName">Specifies the modality name.</param>
  724. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2}?' where
  725. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  726. ''' the second item is the <paramref name="modalityName">modality name</paramref> and
  727. ''' the second item is a <paramref name="command">command</paramref>.
  728. ''' </param>
  729. ''' <param name="existingValue">The existing value. The instrument is accessed if this value has no value.</param>
  730. ''' <param name="Parser">The <see cref="isr.Core.IParser(of boolean)">boolean Parser.</see></param>
  731. ''' <param name="access">The desired <see cref="ResourceAccessLevels">access level</see> to the instrument.</param>
  732. ''' <returns></returns>
  733. ''' <remarks></remarks>
  734. Public Function Getter(ByVal element As IScpiValueBase,
  735. ByVal modalityName As String, ByVal subHeader As String,
  736. ByVal existingValue As Nullable(Of Boolean), ByVal parser As isr.Core.IParser(Of Boolean),
  737. ByVal access As ResourceAccessLevels) As Nullable(Of Boolean) Implements IController.Getter
  738. If access.IsDeviceAccess OrElse Not existingValue.HasValue Then
  739. If String.IsNullOrEmpty(element.GetterCommand) Then
  740. element.GetterCommand = Syntax.BuildQuery(Me.SyntaxHeader, modalityName, subHeader)
  741. End If
  742. ' existingValue = Me.QueryBoolean(modalityName, subHeader)
  743. existingValue = Me.Port.QueryBoolean(element.GetterCommand, parser)
  744. End If
  745. Return existingValue
  746. End Function
  747. #End Region
  748. #Region " GETTERS w/ SCPI VALUE "
  749. ''' <summary>
  750. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  751. ''' Uses the nullable value getter command.
  752. ''' </summary>
  753. ''' <param name="element">Specifies the <see cref="IScpiValueBase">existing element</see> where the getter command is stored.</param>
  754. ''' <returns></returns>
  755. ''' <remarks></remarks>
  756. Public Function Getter(ByVal element As IScpiValue(Of Boolean)) As IScpiValue(Of Boolean) Implements IController.Getter
  757. Return Getter(element, CType(element.FormatterParser, Core.IParser(Of Boolean)))
  758. End Function
  759. ''' <summary>
  760. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  761. ''' Uses the nullable value getter command.
  762. ''' </summary>
  763. ''' <param name="element">Specifies the <see cref="IScpiValueBase">existing element</see> where the getter command is stored.</param>
  764. ''' <param name="Parser">The <see cref="isr.Core.IParser(of boolean)">boolean Parser.</see></param>
  765. ''' <returns></returns>
  766. ''' <remarks></remarks>
  767. Public Function Getter(ByVal element As IScpiValue(Of Boolean),
  768. ByVal parser As Core.IParser(Of Boolean)) As IScpiValue(Of Boolean) Implements IController.Getter
  769. element.Value = Me.Port.QueryBoolean(element.GetterCommand, parser)
  770. element.ActualValue = element.Value
  771. Return element
  772. End Function
  773. #End Region
  774. #Region " GETTERS w/ ACCESS w/ SCPI VALUE "
  775. ''' <summary>
  776. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  777. ''' Uses the nullable value getter command.
  778. ''' </summary>
  779. ''' <param name="element">Specifies the <see cref="IScpiValueBase">existing element</see> where the getter command is stored.</param>
  780. ''' <param name="Parser">The <see cref="isr.Core.IParser(of boolean)">boolean Parser.</see></param>
  781. ''' <param name="access">The desired <see cref="ResourceAccessLevels">access level</see> to the instrument.</param>
  782. ''' <returns></returns>
  783. ''' <remarks></remarks>
  784. Public Function Getter(ByVal element As IScpiValue(Of Boolean),
  785. ByVal parser As isr.Core.IParser(Of Boolean),
  786. ByVal access As ResourceAccessLevels) As IScpiValue(Of Boolean) Implements IController.Getter
  787. If access.IsDeviceAccess OrElse Not element.Value.HasValue Then
  788. element.Value = Me.Port.QueryBoolean(element.GetterCommand, parser)
  789. element.ActualValue = element.Value
  790. End If
  791. Return element
  792. End Function
  793. ''' <summary>
  794. ''' Gets a value from the instrument <see cref="SyntaxHeader">SCPI subsystem</see> <paramref name="subHeader">element</paramref>.
  795. ''' Applies readings to the <paramref name="element">existing element</paramref>
  796. ''' </summary>
  797. ''' <param name="element">Specifies the existing element where the instrument readings are applied.</param>
  798. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}?' where
  799. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see> and
  800. ''' the second item is a <paramref name="command">command</paramref>
  801. ''' </param>
  802. ''' <param name="Parser">The <see cref="isr.Core.IParser(of boolean)">boolean Parser.</see></param>
  803. ''' <param name="access">The desired <see cref="ResourceAccessLevels">access level</see> to the instrument.</param>
  804. ''' <returns></returns>
  805. ''' <remarks></remarks>
  806. Public Function Getter(ByVal element As IScpiValue(Of Boolean),
  807. ByVal subHeader As String,
  808. ByVal parser As isr.Core.IParser(Of Boolean),
  809. ByVal access As ResourceAccessLevels) As IScpiValue(Of Boolean) Implements IController.Getter
  810. If access.IsDeviceAccess OrElse Not element.Value.HasValue Then
  811. If String.IsNullOrEmpty(element.GetterCommand) Then
  812. element.GetterCommand = Syntax.BuildQuery(Me.SyntaxHeader, subHeader)
  813. End If
  814. ' element.Value = Me.QueryBoolean(subHeader)
  815. element.Value = Me.Port.QueryBoolean(element.GetterCommand, parser)
  816. element.ActualValue = element.Value
  817. End If
  818. Return element
  819. End Function
  820. ''' <summary>
  821. ''' Gets a value from the instrument <see cref="SyntaxHeader">SCPI subsystem</see> <paramref name="modalityName">modality</paramref> and <paramref name="subHeader">element</paramref>.
  822. ''' Applies readings to the <paramref name="element">existing element</paramref>
  823. ''' </summary>
  824. ''' <param name="element">Specifies the existing element where the instrument readings are applied.</param>
  825. ''' <param name="modalityName">Specifies the modality name.</param>
  826. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2}?' where
  827. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  828. ''' the second item is the <paramref name="modalityName">modality name</paramref> and
  829. ''' the second item is a <paramref name="command">command</paramref>.
  830. ''' </param>
  831. ''' <param name="Parser">The <see cref="isr.Core.IParser(of boolean)">boolean Parser.</see></param>
  832. ''' <param name="access">The desired <see cref="ResourceAccessLevels">access level</see> to the instrument.</param>
  833. ''' <returns></returns>
  834. ''' <remarks></remarks>
  835. Public Function Getter(ByVal element As IScpiValue(Of Boolean),
  836. ByVal modalityName As String, ByVal subHeader As String,
  837. ByVal parser As isr.Core.IParser(Of Boolean), ByVal access As ResourceAccessLevels) As IScpiValue(Of Boolean) Implements IController.Getter
  838. element.Value = Me.Getter(element, modalityName, subHeader, element.Value, parser, access)
  839. element.ActualValue = element.Value
  840. Return element
  841. End Function
  842. #End Region
  843. #Region " SETTERS "
  844. ''' <summary>
  845. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  846. ''' </summary>
  847. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1} {2}' where
  848. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  849. ''' the second item is a <paramref name="command">command</paramref>
  850. ''' the third item represents a <paramref name="value">numeric value</paramref>.
  851. ''' </param>
  852. ''' <param name="value">The value to set in the ins…

Large files files are truncated, but you can click here to view the full file