PageRenderTime 64ms CodeModel.GetById 21ms RepoModel.GetById 0ms 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
  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 instrument.</param>
  853. ''' <param name="formatterParser">The <see cref="isr.Core.IFormatterParser(of boolean)">boolean formatter and parser.</see></param>
  854. ''' <returns></returns>
  855. ''' <remarks></remarks>
  856. Public Function Setter(ByVal subHeader As String, ByVal value As Boolean, ByVal formatterParser As isr.Core.IFormatterParser(Of Boolean), ByVal verify As Boolean) As Boolean Implements IController.Setter
  857. Dim scpiMessage As String = Syntax.BuildCommand(Me.SyntaxHeader, subHeader, value, formatterParser)
  858. Me.Port.WriteLine(scpiMessage)
  859. If verify Then
  860. Dim actual As Nullable(Of Boolean) = Me.QueryBoolean(scpiMessage, formatterParser)
  861. Return actual.HasValue AndAlso (value = actual.Value)
  862. Else
  863. Return True
  864. End If
  865. End Function
  866. ''' <summary>
  867. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  868. ''' </summary>
  869. ''' <param name="modalityName">Specifies the modality name.</param>
  870. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2} {3}' where
  871. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  872. ''' the second item is the <paramref name="modalityName">modality name</paramref>,
  873. ''' the third item is a <paramref name="command">command</paramref>
  874. ''' the fourth item represents a <paramref name="value">numeric value</paramref>.
  875. ''' </param>
  876. ''' <param name="value">The value to set in the instrument.</param>
  877. ''' <param name="formatterParser">The <see cref="isr.Core.IFormatterParser(of boolean)">boolean formatter and parser.</see></param>
  878. ''' <returns></returns>
  879. ''' <remarks></remarks>
  880. Public Function Setter(ByVal modalityName As String, ByVal subHeader As String, ByVal formatterParser As isr.Core.IFormatterParser(Of Boolean), ByVal value As Boolean, ByVal verify As Boolean) As Boolean Implements IController.Setter
  881. Dim scpiMessage As String = Syntax.BuildCommand(Me.SyntaxHeader, modalityName, subHeader, value, formatterParser)
  882. Me.Port.WriteLine(scpiMessage)
  883. If verify Then
  884. Dim actual As Nullable(Of Boolean) = Me.QueryBoolean(modalityName, subHeader, formatterParser)
  885. Return actual.HasValue AndAlso (value = actual.Value)
  886. Else
  887. Return True
  888. End If
  889. End Function
  890. #End Region
  891. #Region " SETTERS w/ ACCESS "
  892. ''' <summary>
  893. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  894. ''' </summary>
  895. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1} {2}' where
  896. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>
  897. ''' the second item is a <paramref name="command">command</paramref> and
  898. ''' the third item is the <paramref name="value">value</paramref>.
  899. ''' </param>
  900. ''' <param name="existingValue">The existing value. The instrument is accessed if this value has no value or is not equal to the specified <paramref name="value"/>.</param>
  901. ''' <param name="formatter">The <see cref="isr.Core.IFormatter(of boolean)">boolean formatter.</see></param>
  902. ''' <param name="access">The desired <see cref="ResourceAccessLevels">access level</see> to the instrument.</param>
  903. ''' <returns></returns>
  904. ''' <remarks></remarks>
  905. Public Function Setter(ByVal subHeader As String,
  906. ByVal existingValue As Nullable(Of Boolean), ByVal value As Boolean,
  907. ByVal formatter As isr.Core.IFormatter(Of Boolean),
  908. ByVal access As ResourceAccessLevels) As Nullable(Of Boolean) Implements IController.Setter
  909. If access.IsVerifyAccess Then
  910. Throw New ArgumentException("Verification not supported by this method", "access")
  911. End If
  912. If access.IsDeviceAccess OrElse (value <> existingValue) Then
  913. Me.Port.WriteLine(Syntax.BuildCommand(Me.SyntaxHeader, subHeader, value, formatter))
  914. End If
  915. Return New Nullable(Of Boolean)(value)
  916. End Function
  917. ''' <summary>
  918. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  919. ''' </summary>
  920. ''' <param name="modalityName">Specifies the modality name.</param>
  921. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2} {3}' where
  922. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  923. ''' the second item is the <paramref name="modalityName">modality name</paramref>,
  924. ''' the second item is a <paramref name="command">command</paramref> and
  925. ''' the fourth item represents a <paramref name="value">numeric value</paramref>.
  926. ''' </param>
  927. ''' <param name="existingValue">The existing value. The instrument is accessed if this value has no value or is not equal to the specified <paramref name="value"/>.</param>
  928. ''' <param name="value">The value to set in the instrument.</param>
  929. ''' <param name="formatter">The <see cref="isr.Core.IFormatter(of boolean)">boolean formatter.</see></param>
  930. ''' <param name="access">The desired <see cref="ResourceAccessLevels">access level</see> to the instrument.</param>
  931. ''' <returns></returns>
  932. ''' <remarks></remarks>
  933. Public Function Setter(ByVal modalityName As String, ByVal subHeader As String,
  934. ByVal existingValue As Nullable(Of Boolean), ByVal value As Boolean,
  935. ByVal formatter As isr.Core.IFormatter(Of Boolean),
  936. ByVal access As ResourceAccessLevels) As Nullable(Of Boolean) Implements IController.Setter
  937. If access.IsVerifyAccess Then
  938. Throw New ArgumentException("Verification not supported by this method", "access")
  939. End If
  940. If access.IsDeviceAccess OrElse (value <> existingValue) Then
  941. Me.Port.WriteLine(Syntax.BuildCommand(Me.SyntaxHeader, modalityName, subHeader, value, formatter))
  942. End If
  943. Return New Nullable(Of Boolean)(value)
  944. End Function
  945. #End Region
  946. #Region " SETTERS w/ ELEMENT "
  947. ''' <summary>
  948. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  949. ''' </summary>
  950. ''' <param name="element">Specifies the <see cref="IScpiValueBase">existing element</see> where the getter command is stored.</param>
  951. ''' <param name="value">Specifies the value to be set using the element <see cref="IScpiValueBase.SetterCommandFormat">command</see>.</param>
  952. ''' <param name="existingValue">The existing value. The instrument is accessed if this value has no value or is not equal to the specified <paramref name="value"/>.</param>
  953. ''' <param name="formatter">The <see cref="isr.Core.IFormatter(of boolean)">boolean formatter.</see></param>
  954. ''' <returns></returns>
  955. ''' <remarks></remarks>
  956. Public Function Setter(ByVal element As IScpiValueBase,
  957. ByVal existingValue As Boolean, ByVal value As Boolean,
  958. ByVal formatter As isr.Core.IFormatter(Of Boolean)) As Boolean Implements IController.Setter
  959. If value <> existingValue Then
  960. If Not String.IsNullOrEmpty(element.SetterCommandFormat) Then
  961. element.SetterCommand = String.Format(Globalization.CultureInfo.InvariantCulture,
  962. element.SetterCommandFormat, formatter.Text(value))
  963. ElseIf String.IsNullOrEmpty(element.SetterCommand) Then
  964. Throw New ArgumentException("Element setter command is empty", "element")
  965. End If
  966. Me.Port.WriteLine(element.SetterCommand)
  967. End If
  968. Return value
  969. End Function
  970. #End Region
  971. #Region " SETTERS w/ ACCESS w/ ELEMENT "
  972. ''' <summary>
  973. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  974. ''' </summary>
  975. ''' <param name="element">Specifies the <see cref="IScpiValueBase">existing element</see> where the getter command is stored.</param>
  976. ''' <param name="value">Specifies the value to be set using the element <see cref="IScpiValueBase.SetterCommandFormat">command</see>.</param>
  977. ''' <param name="existingValue">The existing value. The instrument is accessed if this value has no value or is not equal to the specified <paramref name="value"/>.</param>
  978. ''' <param name="formatter">The <see cref="isr.Core.IFormatter(of boolean)">boolean formatter.</see></param>
  979. ''' <param name="access">The desired <see cref="ResourceAccessLevels">access level</see> to the instrument.</param>
  980. ''' <returns></returns>
  981. ''' <remarks></remarks>
  982. Public Function Setter(ByVal element As IScpiValueBase,
  983. ByVal existingValue As Boolean, ByVal value As Boolean,
  984. ByVal formatter As isr.Core.IFormatter(Of Boolean),
  985. ByVal access As ResourceAccessLevels) As Boolean Implements IController.Setter
  986. If access.IsVerifyAccess Then
  987. Throw New ArgumentException("Verification not supported by this method", "access")
  988. End If
  989. If access.IsDeviceAccess OrElse value <> existingValue Then
  990. If Not String.IsNullOrEmpty(element.SetterCommandFormat) Then
  991. element.SetterCommand = String.Format(Globalization.CultureInfo.InvariantCulture,
  992. element.SetterCommandFormat, formatter.Text(value))
  993. ElseIf String.IsNullOrEmpty(element.SetterCommand) Then
  994. Throw New ArgumentException("Element setter command is empty", "element")
  995. End If
  996. Me.Port.WriteLine(element.SetterCommand)
  997. End If
  998. Return value
  999. End Function
  1000. ''' <summary>
  1001. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  1002. ''' Uses or updates the nullable value getter command.
  1003. ''' </summary>
  1004. ''' <param name="element">Specifies the <see cref="IScpiValueBase">existing element</see> where the getter command is stored.</param>
  1005. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1} {2}' where
  1006. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>
  1007. ''' the second item is a <paramref name="command">command</paramref> and
  1008. ''' the third item is the <paramref name="value">value</paramref>.
  1009. ''' </param>
  1010. ''' <param name="value">The value which to set.</param>
  1011. ''' <param name="existingValue">The existing value. The instrument is accessed if this value has no value or is not equal to the specified <paramref name="value"/>.</param>
  1012. ''' <param name="formatter">The <see cref="isr.Core.IFormatter(of boolean)">boolean formatter.</see></param>
  1013. ''' <param name="access">The desired <see cref="ResourceAccessLevels">access level</see> to the instrument.</param>
  1014. ''' <returns></returns>
  1015. ''' <remarks></remarks>
  1016. Public Function Setter(ByVal element As IScpiValueBase,
  1017. ByVal subHeader As String,
  1018. ByVal existingValue As Nullable(Of Boolean), ByVal value As Boolean,
  1019. ByVal formatter As isr.Core.IFormatter(Of Boolean),
  1020. ByVal access As ResourceAccessLevels) As Nullable(Of Boolean) Implements IController.Setter
  1021. If access.IsVerifyAccess Then
  1022. Throw New ArgumentException("Verification not supported by this method", "access")
  1023. End If
  1024. If access.IsDeviceAccess OrElse (value <> existingValue) Then
  1025. If String.IsNullOrEmpty(element.SetterCommandFormat) Then
  1026. element.SetterCommandFormat = Syntax.BuildCommandFormat(Me.SyntaxHeader, subHeader)
  1027. End If
  1028. element.SetterCommand = Syntax.BuildCommand(Me.SyntaxHeader, subHeader, value, formatter)
  1029. Me.Port.WriteLine(element.SetterCommand)
  1030. End If
  1031. Return New Nullable(Of Boolean)(value)
  1032. End Function
  1033. ''' <summary>
  1034. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  1035. ''' Uses or updates the nullable value getter command.
  1036. ''' </summary>
  1037. ''' <param name="element">Specifies the <see cref="IScpiValueBase">existing element</see> where the getter command is stored.</param>
  1038. ''' <param name="modalityName">Specifies the modality name.</param>
  1039. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2} {3}' where
  1040. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  1041. ''' the second item is the <paramref name="modalityName">modality name</paramref>,
  1042. ''' the second item is a <paramref name="command">command</paramref> and
  1043. ''' the fourth item represents a <paramref name="value">numeric value</paramref>.
  1044. ''' </param>
  1045. ''' <param name="existingValue">The existing value. The instrument is accessed if this value has no value or is not equal to the specified <paramref name="value"/>.</param>
  1046. ''' <param name="value">The value to set in the instrument.</param>
  1047. ''' <param name="formatter">The <see cref="isr.Core.IFormatter(of boolean)">boolean formatter.</see></param>
  1048. ''' <param name="access">The desired <see cref="ResourceAccessLevels">access level</see> to the instrument.</param>
  1049. ''' <returns></returns>
  1050. ''' <remarks></remarks>
  1051. Public Function Setter(ByVal element As IScpiValueBase,
  1052. ByVal modalityName As String, ByVal subHeader As String,
  1053. ByVal existingValue As Nullable(Of Boolean), ByVal value As Boolean,
  1054. ByVal formatter As isr.Core.IFormatter(Of Boolean),
  1055. ByVal access As ResourceAccessLevels) As Nullable(Of Boolean) Implements IController.Setter
  1056. If access.IsVerifyAccess Then
  1057. Throw New ArgumentException("Verification not supported by this method", "access")
  1058. End If
  1059. If access.IsDeviceAccess OrElse (value <> existingValue) Then
  1060. If String.IsNullOrEmpty(element.SetterCommandFormat) Then
  1061. element.SetterCommandFormat = Syntax.BuildCommandFormat(Me.SyntaxHeader, modalityName, subHeader)
  1062. End If
  1063. element.SetterCommand = Syntax.BuildCommand(Me.SyntaxHeader, modalityName, subHeader, value, formatter)
  1064. Me.Port.WriteLine(element.SetterCommand)
  1065. End If
  1066. Return New Nullable(Of Boolean)(value)
  1067. End Function
  1068. #End Region
  1069. #Region " SETTERS w/ SCPI VALUE "
  1070. ''' <summary>
  1071. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  1072. ''' Applies readings to the <paramref name="element">existing element</paramref>
  1073. ''' Assume element has both <see cref="IScpiValueBase.GetterCommand">getter</see> and
  1074. ''' <see cref="IScpiValueBase.SetterCommand">setter</see> commands specified.
  1075. ''' </summary>
  1076. ''' <param name="element">Specifies the element holding the existing value, which is updated.</param>
  1077. ''' <param name="value">The value to set in the instrument.</param>
  1078. ''' <returns></returns>
  1079. ''' <remarks></remarks>
  1080. Public Function Setter(ByVal element As IScpiValue(Of Boolean), ByVal value As Boolean) As IScpiValue(Of Boolean) Implements IController.Setter
  1081. element.Value = Me.Setter(CType(element, IScpiValueBase), element.Value.Value, value, CType(element.FormatterParser, Core.IFormatterParser(Of Boolean)))
  1082. Return element
  1083. End Function
  1084. ''' <summary>
  1085. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  1086. ''' Applies readings to the <paramref name="element">existing element</paramref>
  1087. ''' Assume element has both <see cref="IScpiValueBase.GetterCommand">getter</see> and
  1088. ''' <see cref="IScpiValueBase.SetterCommand">setter</see> commands specified.
  1089. ''' </summary>
  1090. ''' <param name="element">Specifies the element holding the existing value, which is updated.</param>
  1091. ''' <param name="value">The value to set in the instrument.</param>
  1092. ''' <param name="formatterParser">The <see cref="isr.Core.IFormatterParser(of boolean)">boolean formatter and parser.</see></param>
  1093. ''' <returns></returns>
  1094. ''' <remarks></remarks>
  1095. Public Function Setter(ByVal element As IScpiValue(Of Boolean), ByVal value As Boolean,
  1096. ByVal formatterParser As isr.Core.IFormatterParser(Of Boolean)) As IScpiValue(Of Boolean) Implements IController.Setter
  1097. element.Value = Me.Setter(CType(element, IScpiValueBase), element.Value.Value, value, formatterParser)
  1098. Return element
  1099. End Function
  1100. #End Region
  1101. #Region " SETTERS w/ ACCESS w/ SCPI VALUE "
  1102. ''' <summary>
  1103. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  1104. ''' Applies readings to the <paramref name="element">existing element</paramref>
  1105. ''' Assume element has both <see cref="IScpiValueBase.GetterCommand">getter</see> and
  1106. ''' <see cref="IScpiValueBase.SetterCommand">setter</see> commands specified.
  1107. ''' </summary>
  1108. ''' <param name="element">Specifies the element holding the existing value, which is updated.</param>
  1109. ''' <param name="value">The value to set in the instrument.</param>
  1110. ''' <param name="formatterParser">The <see cref="isr.Core.IFormatterParser(of boolean)">boolean formatter and parser.</see></param>
  1111. ''' <param name="access">The desired <see cref="ResourceAccessLevels">access level</see> to the instrument.</param>
  1112. ''' <returns></returns>
  1113. ''' <remarks></remarks>
  1114. Public Function Setter(ByVal element As IScpiValue(Of Boolean), ByVal value As Boolean,
  1115. ByVal formatterParser As isr.Core.IFormatterParser(Of Boolean), ByVal access As ResourceAccessLevels) As IScpiValue(Of Boolean) Implements IController.Setter
  1116. If access.IsDeviceAccess OrElse (value <> element.Value) Then
  1117. element.Value = Me.Setter(CType(element, IScpiValueBase), element.Value.Value, value, formatterParser, access And Not ResourceAccessLevels.Verify)
  1118. End If
  1119. If access.IsVerifyAccess Then
  1120. Me.Getter(element, formatterParser, ResourceAccessLevels.Device)
  1121. element.Value = value
  1122. ElseIf access.IsCacheAccess Then
  1123. element.ActualValue = value
  1124. End If
  1125. Return element
  1126. End Function
  1127. ''' <summary>
  1128. ''' Sets the instrument <see cref="SyntaxHeader">SCPI subsystem</see> <paramref name="subHeader">element</paramref> value.
  1129. ''' Applies readings to the <paramref name="element">existing element</paramref>
  1130. ''' </summary>
  1131. ''' <param name="element">Specifies the existing element where the instrument readings are applied.</param>
  1132. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1} {2}' where
  1133. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>
  1134. ''' the second item is a <paramref name="command">command</paramref> and
  1135. ''' the third item is the <paramref name="value">value</paramref>.
  1136. ''' </param>
  1137. ''' <param name="formatterParser">The <see cref="isr.Core.IFormatterParser(of boolean)">boolean formatter and parser.</see></param>
  1138. ''' <param name="access">The desired <see cref="ResourceAccessLevels">access level</see> to the instrument.</param>
  1139. ''' <returns></returns>
  1140. ''' <remarks>
  1141. ''' Use the following code in the calling methd if verification is used:
  1142. ''' <code>
  1143. ''' If Not element.IsVerified.GetValueOrDefault(False) Then
  1144. ''' If element.Value.HasValue AndAlso element.ActualValue.HasValue Then
  1145. ''' return String.Format(Globalization.CultureInfo.CurrentCulture,
  1146. ''' "Instrument settings applied using the command '{0}' did not verify. Expected={1}. Actual={2}.",
  1147. ''' element.Value, element.ActualValue.Value)
  1148. ''' Else
  1149. ''' return "Failed reading values from the instrument."
  1150. ''' End If
  1151. ''' End If
  1152. ''' </code>
  1153. ''' </remarks>
  1154. Public Function Setter(ByVal element As IScpiValue(Of Boolean),
  1155. ByVal subHeader As String,
  1156. ByVal value As Boolean,
  1157. ByVal formatterParser As isr.Core.IFormatterParser(Of Boolean), ByVal access As ResourceAccessLevels) As IScpiValue(Of Boolean) Implements IController.Setter
  1158. element.Value = Me.Setter(CType(element, IScpiValueBase), subHeader, element.Value, value, formatterParser, access And Not ResourceAccessLevels.Verify)
  1159. If access.IsVerifyAccess Then
  1160. Me.Getter(element, subHeader, formatterParser, ResourceAccessLevels.Device)
  1161. element.Value = value
  1162. ElseIf access.IsCacheAccess Then
  1163. element.ActualValue = value
  1164. End If
  1165. Return element
  1166. End Function
  1167. ''' <summary>
  1168. ''' Sets the instrument <see cref="SyntaxHeader">SCPI subsystem</see> <paramref name="modalityName">modality</paramref> <paramref name="subHeader">element</paramref> value.
  1169. ''' </summary>
  1170. ''' <param name="element">Specifies the existing element where the instrument readings are applied.</param>
  1171. ''' <param name="modalityName">Specifies the modality name.</param>
  1172. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2} {3}' where
  1173. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  1174. ''' the second item is the <paramref name="modalityName">modality name</paramref>,
  1175. ''' the second item is a <paramref name="command">command</paramref> and
  1176. ''' the fourth item represents a <paramref name="value">numeric value</paramref>.
  1177. ''' </param>
  1178. ''' <param name="formatterParser">The <see cref="isr.Core.IFormatterParser(of boolean)">boolean formatter and parser</see></param>
  1179. ''' <param name="access">The desired <see cref="ResourceAccessLevels">access level</see> to the instrument.</param>
  1180. ''' <returns></returns>
  1181. ''' <remarks>
  1182. ''' Use the following code in the calling methd if verification is used:
  1183. ''' <code>
  1184. ''' If Not element.IsVerified.GetValueOrDefault(False) Then
  1185. ''' If element.Value.HasValue AndAlso element.ActualValue.HasValue Then
  1186. ''' return String.Format(Globalization.CultureInfo.CurrentCulture,
  1187. ''' "Instrument settings applied using the command '{0}' did not verify. Expected={1}. Actual={2}.",
  1188. ''' element.Value, element.ActualValue.Value)
  1189. ''' Else
  1190. ''' return "Failed reading values from the instrument."
  1191. ''' End If
  1192. ''' End If
  1193. ''' </code>
  1194. ''' </remarks>
  1195. Public Function Setter(ByVal element As IScpiValue(Of Boolean),
  1196. ByVal modalityName As String, ByVal subHeader As String,
  1197. ByVal value As Boolean,
  1198. ByVal formatterParser As isr.Core.IFormatterParser(Of Boolean), ByVal access As ResourceAccessLevels) As IScpiValue(Of Boolean) Implements IController.Setter
  1199. element.Value = Me.Setter(CType(element, IScpiValueBase), modalityName, subHeader, element.Value, value, formatterParser, access And Not ResourceAccessLevels.Verify)
  1200. If access.IsVerifyAccess Then
  1201. Me.Getter(element, modalityName, subHeader, formatterParser, ResourceAccessLevels.Device)
  1202. element.Value = value
  1203. ElseIf access.IsCacheAccess Then
  1204. element.ActualValue = value
  1205. End If
  1206. Return element
  1207. End Function
  1208. #End Region
  1209. #End Region
  1210. #Region " DOUBLE "
  1211. #Region " QUERRIES: DOUBLE "
  1212. ''' <summary>
  1213. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  1214. ''' </summary>
  1215. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}?' where
  1216. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see> and
  1217. ''' the second item is a <paramref name="command">command</paramref>.
  1218. ''' </param>
  1219. ''' <returns></returns>
  1220. ''' <remarks></remarks>
  1221. Public Function QueryDouble(ByVal subHeader As String) As Nullable(Of Double) Implements IController.QueryDouble
  1222. Return Me.Port.QueryDouble(Syntax.BuildQuery(Me.SyntaxHeader, subHeader))
  1223. End Function
  1224. ''' <summary>
  1225. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  1226. ''' </summary>
  1227. ''' <param name="modalityName">Specifies the modality name.</param>
  1228. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2}?' where
  1229. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  1230. ''' the second item is the <paramref name="modalityName">modality name</paramref> and
  1231. ''' the thrid item is a <paramref name="command">command</paramref>.
  1232. ''' </param>
  1233. ''' <returns></returns>
  1234. ''' <remarks></remarks>
  1235. Public Function QueryDouble(ByVal modalityName As String, ByVal subHeader As String) As Nullable(Of Double) Implements IController.QueryDouble
  1236. Return Me.Port.QueryDouble(Syntax.BuildQuery(Me.SyntaxHeader, modalityName, subHeader))
  1237. End Function
  1238. #End Region
  1239. #Region " GETTERS w/ ACCESS "
  1240. ''' <summary>
  1241. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  1242. ''' </summary>
  1243. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}?' where
  1244. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see> and
  1245. ''' the second item is a <paramref name="command">command</paramref>
  1246. ''' </param>
  1247. ''' <param name="existingValue">Specifies the existing value.</param>
  1248. ''' <returns></returns>
  1249. ''' <remarks></remarks>
  1250. Public Function Getter(ByVal subHeader As String,
  1251. ByVal existingValue As Nullable(Of Double),
  1252. ByVal access As ResourceAccessLevels) As Nullable(Of Double) Implements IController.Getter
  1253. If access.IsDeviceAccess OrElse Not existingValue.HasValue Then
  1254. existingValue = Me.QueryDouble(subHeader)
  1255. End If
  1256. Return existingValue
  1257. End Function
  1258. ''' <summary>
  1259. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  1260. ''' </summary>
  1261. ''' <param name="modalityName">Specifies the modality name.</param>
  1262. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2}?' where
  1263. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  1264. ''' the second item is the <paramref name="modalityName">modality name</paramref> and
  1265. ''' the second item is a <paramref name="command">command</paramref>.
  1266. ''' </param>
  1267. ''' <param name="existingValue">Specifies the existing value.</param>
  1268. ''' <returns></returns>
  1269. ''' <remarks></remarks>
  1270. Public Function Getter(ByVal modalityName As String, ByVal subHeader As String,
  1271. ByVal existingValue As Nullable(Of Double),
  1272. ByVal access As ResourceAccessLevels) As Nullable(Of Double) Implements IController.Getter
  1273. If access.IsDeviceAccess OrElse Not existingValue.HasValue Then
  1274. existingValue = Me.QueryDouble(modalityName, subHeader)
  1275. End If
  1276. Return existingValue
  1277. End Function
  1278. #End Region
  1279. #Region " GETTERS w/ ACCESS w/ ELEMENT "
  1280. ''' <summary>
  1281. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  1282. ''' Uses or updates the nullable value getter command.
  1283. ''' </summary>
  1284. ''' <param name="element">Specifies the <see cref="IScpiValueBase">existing element</see> where the getter command is stored.</param>
  1285. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}?' where
  1286. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see> and
  1287. ''' the second item is a <paramref name="command">command</paramref>
  1288. ''' </param>
  1289. ''' <param name="existingValue">Specifies the existing value.</param>
  1290. ''' <returns></returns>
  1291. ''' <remarks></remarks>
  1292. Public Function Getter(ByVal element As IScpiValueBase,
  1293. ByVal subHeader As String,
  1294. ByVal existingValue As Nullable(Of Double),
  1295. ByVal access As ResourceAccessLevels) As Nullable(Of Double) Implements IController.Getter
  1296. If access.IsDeviceAccess OrElse Not existingValue.HasValue Then
  1297. If String.IsNullOrEmpty(element.GetterCommand) Then
  1298. element.GetterCommand = Syntax.BuildQuery(Me.SyntaxHeader, subHeader)
  1299. End If
  1300. 'existingValue = Me.QueryDouble(subHeader)
  1301. existingValue = Me.Port.QueryDouble(element.GetterCommand)
  1302. End If
  1303. Return existingValue
  1304. End Function
  1305. ''' <summary>
  1306. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  1307. ''' Uses or updates the nullable value getter command.
  1308. ''' </summary>
  1309. ''' <param name="element">Specifies the <see cref="IScpiValueBase">existing element</see> where the getter command is stored.</param>
  1310. ''' <param name="modalityName">Specifies the modality name.</param>
  1311. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2}?' where
  1312. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  1313. ''' the second item is the <paramref name="modalityName">modality name</paramref> and
  1314. ''' the second item is a <paramref name="command">command</paramref>.
  1315. ''' </param>
  1316. ''' <param name="existingValue">Specifies the existing value.</param>
  1317. ''' <returns></returns>
  1318. ''' <remarks></remarks>
  1319. Public Function Getter(ByVal element As IScpiValueBase,
  1320. ByVal modalityName As String, ByVal subHeader As String,
  1321. ByVal existingValue As Nullable(Of Double),
  1322. ByVal access As ResourceAccessLevels) As Nullable(Of Double) Implements IController.Getter
  1323. If access.IsDeviceAccess OrElse Not existingValue.HasValue Then
  1324. If String.IsNullOrEmpty(element.GetterCommand) Then
  1325. element.GetterCommand = Syntax.BuildQuery(Me.SyntaxHeader, modalityName, subHeader)
  1326. End If
  1327. ' existingValue = Me.QueryDouble(subHeader)
  1328. existingValue = Me.Port.QueryDouble(element.GetterCommand)
  1329. End If
  1330. Return existingValue
  1331. End Function
  1332. #End Region
  1333. #Region " GETTERS w/ ACCESS w/ SCPI VALUE "
  1334. ''' <summary>
  1335. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  1336. ''' Uses or updates the nullable value getter command.
  1337. ''' </summary>
  1338. ''' <param name="element">Specifies the <see cref="IScpiValueBase">existing element</see> where the getter command is stored.</param>
  1339. ''' <returns></returns>
  1340. ''' <remarks></remarks>
  1341. Public Function Getter(ByVal element As IScpiValue(Of Double), ByVal access As ResourceAccessLevels) As IScpiValue(Of Double) Implements IController.Getter
  1342. If access.IsDeviceAccess OrElse Not element.Value.HasValue Then
  1343. element.Value = Me.Port.QueryDouble(element.GetterCommand)
  1344. element.ActualValue = element.Value
  1345. End If
  1346. Return element
  1347. End Function
  1348. ''' <summary>
  1349. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  1350. ''' Applies readings to the <paramref name="element">existing element</paramref>
  1351. ''' </summary>
  1352. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}?' where
  1353. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see> and
  1354. ''' the second item is a <paramref name="command">command</paramref>
  1355. ''' </param>
  1356. ''' <param name="element">Specifies the element holding the existing value, which is updated.</param>
  1357. ''' <returns></returns>
  1358. ''' <remarks></remarks>
  1359. Public Function Getter(ByVal element As IScpiValue(Of Double),
  1360. ByVal subHeader As String,
  1361. ByVal access As ResourceAccessLevels) As IScpiValue(Of Double) Implements IController.Getter
  1362. element.Value = Me.Getter(element, subHeader, element.Value, access)
  1363. element.ActualValue = element.Value
  1364. Return element
  1365. End Function
  1366. ''' <summary>
  1367. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  1368. ''' Applies readings to the <paramref name="element">existing element</paramref>
  1369. ''' </summary>
  1370. ''' <param name="modalityName">Specifies the modality name.</param>
  1371. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2}?' where
  1372. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  1373. ''' the second item is the <paramref name="modalityName">modality name</paramref> and
  1374. ''' the second item is a <paramref name="command">command</paramref>.
  1375. ''' </param>
  1376. ''' <param name="element">Specifies the element holding the existing value, which is updated.</param>
  1377. ''' <returns></returns>
  1378. ''' <remarks></remarks>
  1379. Public Function Getter(ByVal element As IScpiValue(Of Double),
  1380. ByVal modalityName As String, ByVal subHeader As String,
  1381. ByVal access As ResourceAccessLevels) As IScpiValue(Of Double) Implements IController.Getter
  1382. element.Value = Me.Getter(element, modalityName, subHeader, element.Value, access)
  1383. element.ActualValue = element.Value
  1384. Return element
  1385. End Function
  1386. #End Region
  1387. #Region " SETTERS "
  1388. ''' <summary>
  1389. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  1390. ''' </summary>
  1391. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1} {2}' where
  1392. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  1393. ''' the second item is a <paramref name="command">command</paramref>
  1394. ''' the third item represents a <paramref name="value">numeric value</paramref>.
  1395. ''' </param>
  1396. ''' <param name="value">The value to set in the instrument.</param>
  1397. ''' <returns></returns>
  1398. ''' <remarks></remarks>
  1399. Public Function Setter(ByVal subHeader As String, ByVal value As Double, ByVal verify As Boolean) As Boolean Implements IController.Setter
  1400. Dim scpiMessage As String = Syntax.BuildCommand(Me.SyntaxHeader, subHeader, value)
  1401. Me.Port.WriteLine(scpiMessage)
  1402. If verify Then
  1403. Dim actual As Nullable(Of Double) = Me.QueryDouble(scpiMessage)
  1404. Return actual.HasValue AndAlso (value = actual.Value)
  1405. Else
  1406. Return True
  1407. End If
  1408. End Function
  1409. ''' <summary>
  1410. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  1411. ''' </summary>
  1412. ''' <param name="modalityName">Specifies the modality name.</param>
  1413. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2} {3}' where
  1414. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  1415. ''' the second item is the <paramref name="modalityName">modality name</paramref>,
  1416. ''' the third item is a <paramref name="command">command</paramref>
  1417. ''' the fourth item represents a <paramref name=" value">numeric value</paramref>.
  1418. ''' </param>
  1419. ''' <param name="value">The value to set in the instrument.</param>
  1420. ''' <returns></returns>
  1421. ''' <remarks></remarks>
  1422. Public Function Setter(ByVal modalityName As String, ByVal subHeader As String, ByVal value As Double, ByVal verify As Boolean) As Boolean Implements IController.Setter
  1423. Dim scpiMessage As String = Syntax.BuildCommand(Me.SyntaxHeader, modalityName, subHeader, value)
  1424. Me.Port.WriteLine(scpiMessage)
  1425. If verify Then
  1426. Dim actual As Nullable(Of Double) = Me.QueryDouble(modalityName, subHeader)
  1427. Return actual.HasValue AndAlso (value = actual.Value)
  1428. Else
  1429. Return True
  1430. End If
  1431. End Function
  1432. #End Region
  1433. #Region " SETTERS w/ ACCESS "
  1434. ''' <summary>
  1435. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  1436. ''' </summary>
  1437. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1} {2}' where
  1438. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>
  1439. ''' the second item is a <paramref name="command">command</paramref> and
  1440. ''' the third item is the <paramref name="value">value</paramref>.
  1441. ''' </param>
  1442. ''' <param name="existingValue">Specifies the existing value.</param>
  1443. ''' <returns></returns>
  1444. ''' <remarks></remarks>
  1445. Public Function Setter(ByVal subHeader As String,
  1446. ByVal existingValue As Nullable(Of Double), ByVal value As Double,
  1447. ByVal access As ResourceAccessLevels) As Nullable(Of Double) Implements IController.Setter
  1448. If access.IsVerifyAccess Then
  1449. Throw New ArgumentException("Verification not supported by this method", "access")
  1450. End If
  1451. If access.IsDeviceAccess OrElse Not ScpiDouble.Approximates(value, existingValue, Single.Epsilon) Then
  1452. Me.Port.WriteLine(Syntax.BuildCommand(Me.SyntaxHeader, subHeader, value))
  1453. End If
  1454. Return New Nullable(Of Double)(value)
  1455. End Function
  1456. ''' <summary>
  1457. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  1458. ''' </summary>
  1459. ''' <param name="modalityName">Specifies the modality name.</param>
  1460. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2} {3}' where
  1461. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  1462. ''' the second item is the <paramref name="modalityName">modality name</paramref>,
  1463. ''' the second item is a <paramref name="command">command</paramref> and
  1464. ''' the fourth item represents a <paramref name="value">numeric value</paramref>.
  1465. ''' </param>
  1466. ''' <param name="existingValue">Specifies the existing value.</param>
  1467. ''' <returns></returns>
  1468. ''' <remarks></remarks>
  1469. Public Function Setter(ByVal modalityName As String, ByVal subHeader As String,
  1470. ByVal existingValue As Nullable(Of Double), ByVal value As Double,
  1471. ByVal access As ResourceAccessLevels) As Nullable(Of Double) Implements IController.Setter
  1472. If access.IsVerifyAccess Then
  1473. Throw New ArgumentException("Verification not supported by this method", "access")
  1474. End If
  1475. If access.IsDeviceAccess OrElse Not ScpiDouble.Approximates(value, existingValue, Single.Epsilon) Then
  1476. Me.Port.WriteLine(Syntax.BuildCommand(Me.SyntaxHeader, modalityName, subHeader, value))
  1477. End If
  1478. Return New Nullable(Of Double)(value)
  1479. End Function
  1480. #End Region
  1481. #Region " SETTERS w/ ACCESS w/ ELEMENT "
  1482. ''' <summary>
  1483. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  1484. ''' </summary>
  1485. ''' <param name="element">Specifies the <see cref="IScpiValueBase">existing element</see> where the getter command is stored.</param>
  1486. ''' <param name="existingValue">Specifies the existing element value where the instrument.</param>
  1487. ''' <param name="value">The value to be set using the element <see cref="IScpiValueBase.SetterCommandFormat">command</see>.</param>
  1488. ''' <param name="access">The desired <see cref="ResourceAccessLevels">access level</see> to the instrument.</param>
  1489. ''' <returns></returns>
  1490. ''' <remarks></remarks>
  1491. Public Function Setter(ByVal element As IScpiValueBase,
  1492. ByVal existingValue As Double, ByVal value As Double,
  1493. ByVal access As ResourceAccessLevels) As Double Implements IController.Setter
  1494. If access.IsVerifyAccess Then
  1495. Throw New ArgumentException("Verification not supported by this method", "access")
  1496. End If
  1497. If access.IsDeviceAccess OrElse Not ScpiDouble.Approximates(value, existingValue, Single.Epsilon) Then
  1498. If Not String.IsNullOrEmpty(element.SetterCommandFormat) Then
  1499. element.SetterCommand = String.Format(Globalization.CultureInfo.InvariantCulture, element.SetterCommandFormat, value)
  1500. ElseIf String.IsNullOrEmpty(element.SetterCommand) Then
  1501. Throw New ArgumentException("Element setter command is empty", "element")
  1502. End If
  1503. Me.Port.WriteLine(element.SetterCommand)
  1504. End If
  1505. Return value
  1506. End Function
  1507. ''' <summary>
  1508. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  1509. ''' Uses or updates the nullable value getter command.
  1510. ''' </summary>
  1511. ''' <param name="element">Specifies the <see cref="IScpiValueBase">existing element</see> where the getter command is stored.</param>
  1512. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1} {2}' where
  1513. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>
  1514. ''' the second item is a <paramref name="command">command</paramref> and
  1515. ''' the third item is the <paramref name="value">value</paramref>.
  1516. ''' </param>
  1517. ''' <param name="existingValue">Specifies the existing value.</param>
  1518. ''' <param name="value">The value to set in the instrument.</param>
  1519. ''' <param name="access">The desired <see cref="ResourceAccessLevels">access level</see> to the instrument.</param>
  1520. ''' <returns></returns>
  1521. ''' <remarks></remarks>
  1522. Public Function Setter(ByVal element As IScpiValueBase,
  1523. ByVal subHeader As String,
  1524. ByVal existingValue As Nullable(Of Double), ByVal value As Double,
  1525. ByVal access As ResourceAccessLevels) As Nullable(Of Double) Implements IController.Setter
  1526. If access.IsVerifyAccess Then
  1527. Throw New ArgumentException("Verification not supported by this method", "access")
  1528. End If
  1529. If access.IsDeviceAccess OrElse Not ScpiDouble.Approximates(value, existingValue, Single.Epsilon) Then
  1530. If String.IsNullOrEmpty(element.SetterCommandFormat) Then
  1531. element.SetterCommandFormat = Syntax.BuildCommandFormat(Me.SyntaxHeader, subHeader)
  1532. End If
  1533. element.SetterCommand = Syntax.BuildCommand(Me.SyntaxHeader, subHeader, value)
  1534. Me.Port.WriteLine(element.SetterCommand)
  1535. End If
  1536. Return New Nullable(Of Double)(value)
  1537. End Function
  1538. ''' <summary>
  1539. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  1540. ''' Uses or updates the nullable value getter command.
  1541. ''' </summary>
  1542. ''' <param name="element">Specifies the <see cref="IScpiValueBase">existing element</see> where the getter command is stored.</param>
  1543. ''' <param name="modalityName">Specifies the modality name.</param>
  1544. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2} {3}' where
  1545. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  1546. ''' the second item is the <paramref name="modalityName">modality name</paramref>,
  1547. ''' the second item is a <paramref name="command">command</paramref> and
  1548. ''' the fourth item represents a <paramref name="value">numeric value</paramref>.
  1549. ''' </param>
  1550. ''' <param name="existingValue">Specifies the existing value.</param>
  1551. ''' <param name="value">The value to set in the instrument.</param>
  1552. ''' <param name="access">The desired <see cref="ResourceAccessLevels">access level</see> to the instrument.</param>
  1553. ''' <returns></returns>
  1554. ''' <remarks></remarks>
  1555. Public Function Setter(ByVal element As IScpiValueBase,
  1556. ByVal modalityName As String, ByVal subHeader As String,
  1557. ByVal existingValue As Nullable(Of Double), ByVal value As Double,
  1558. ByVal access As ResourceAccessLevels) As Nullable(Of Double) Implements IController.Setter
  1559. If access.IsVerifyAccess Then
  1560. Throw New ArgumentException("Verification not supported by this method", "access")
  1561. End If
  1562. If access.IsDeviceAccess OrElse Not ScpiDouble.Approximates(value, existingValue, Single.Epsilon) Then
  1563. If String.IsNullOrEmpty(element.SetterCommandFormat) Then
  1564. element.SetterCommandFormat = Syntax.BuildCommandFormat(Me.SyntaxHeader, modalityName, subHeader)
  1565. End If
  1566. element.SetterCommand = Syntax.BuildCommand(Me.SyntaxHeader, modalityName, subHeader, value)
  1567. Me.Port.WriteLine(element.SetterCommand)
  1568. End If
  1569. Return New Nullable(Of Double)(value)
  1570. End Function
  1571. #End Region
  1572. #Region " SETTERS w/ ACCESS w/ SCPI VALUE "
  1573. ''' <summary>
  1574. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  1575. ''' Applies readings to the <paramref name="element">existing element</paramref>
  1576. ''' Assume element has both <see cref="IScpiValueBase.GetterCommand">getter</see> and
  1577. ''' <see cref="IScpiValueBase.SetterCommand">setter</see> commands specified.
  1578. ''' </summary>
  1579. ''' <param name="element">Specifies the element holding the existing value, which is updated.</param>
  1580. ''' <param name="value">The value to be set using the element <see cref="IScpiValueBase.SetterCommandFormat">command</see>.</param>
  1581. ''' <param name="access">The desired <see cref="ResourceAccessLevels">access level</see> to the instrument.</param>
  1582. ''' <returns></returns>
  1583. ''' <remarks></remarks>
  1584. Public Function Setter(ByVal element As IScpiValue(Of Double), ByVal value As Double, ByVal access As ResourceAccessLevels) As IScpiValue(Of Double) Implements IController.Setter
  1585. If access.IsDeviceAccess OrElse (value <> element.Value) Then
  1586. element.Value = Me.Setter(CType(element, IScpiValueBase), element.Value.Value, value, access And Not ResourceAccessLevels.Verify)
  1587. End If
  1588. If access.IsVerifyAccess Then
  1589. Me.Getter(element, ResourceAccessLevels.Device)
  1590. element.Value = value
  1591. ElseIf access.IsCacheAccess Then
  1592. element.ActualValue = value
  1593. End If
  1594. Return element
  1595. End Function
  1596. ''' <summary>
  1597. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  1598. ''' Applies readings to the <paramref name="element">existing element</paramref>
  1599. ''' </summary>
  1600. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1} {2}' where
  1601. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>
  1602. ''' the second item is a <paramref name="command">command</paramref> and
  1603. ''' the third item is the <paramref name="value">value</paramref>.
  1604. ''' </param>
  1605. ''' <param name="element">Specifies the element holding the existing value, which is updated.</param>
  1606. ''' <returns></returns>
  1607. ''' <remarks></remarks>
  1608. Public Function Setter(ByVal element As IScpiValue(Of Double),
  1609. ByVal subHeader As String, ByVal value As Double,
  1610. ByVal access As ResourceAccessLevels) As IScpiValue(Of Double) Implements IController.Setter
  1611. element.Value = Me.Setter(CType(element, IScpiValueBase), subHeader, element.Value, value, access And Not ResourceAccessLevels.Verify)
  1612. ' element.Value = Me.Setter(CType(element, IScpiValueBase), subHeader, element.Value, element.BoundValue(value), access And Not ResourceAccessLevels.Verify)
  1613. If access.IsVerifyAccess Then
  1614. Me.Getter(element, subHeader, ResourceAccessLevels.Device)
  1615. element.Value = value
  1616. ElseIf access.IsCacheAccess Then
  1617. element.ActualValue = value
  1618. End If
  1619. Return element
  1620. End Function
  1621. ''' <summary>
  1622. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  1623. ''' Applies readings to the <paramref name="element">existing element</paramref>
  1624. ''' </summary>
  1625. ''' <param name="modalityName">Specifies the modality name.</param>
  1626. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2} {3}' where
  1627. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  1628. ''' the second item is the <paramref name="modalityName">modality name</paramref>,
  1629. ''' the second item is a <paramref name="command">command</paramref> and
  1630. ''' the fourth item represents a <paramref name="value">numeric value</paramref>.
  1631. ''' </param>
  1632. ''' <param name="element">Specifies the element holding the existing value, which is updated.</param>
  1633. ''' <returns></returns>
  1634. ''' <remarks></remarks>
  1635. Public Function Setter(ByVal element As IScpiValue(Of Double),
  1636. ByVal modalityName As String, ByVal subHeader As String, ByVal value As Double,
  1637. ByVal access As ResourceAccessLevels) As IScpiValue(Of Double) Implements IController.Setter
  1638. element.Value = Me.Setter(CType(element, IScpiValueBase), modalityName, subHeader, element.Value, value, access And Not ResourceAccessLevels.Verify)
  1639. 'element.Value = Me.Setter(CType(element, IScpiValueBase), modalityName, subHeader, element.Value, element.BoundValue(value), access And Not ResourceAccessLevels.Verify)
  1640. If access.IsVerifyAccess Then
  1641. Me.Getter(element, subHeader, ResourceAccessLevels.Device)
  1642. element.Value = value
  1643. ElseIf access.IsCacheAccess Then
  1644. element.ActualValue = value
  1645. End If
  1646. Return element
  1647. End Function
  1648. #End Region
  1649. #End Region
  1650. #Region " INTEGER "
  1651. #Region " QUERRIES "
  1652. ''' <summary>
  1653. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  1654. ''' </summary>
  1655. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}?' where
  1656. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see> and
  1657. ''' the second item is a <paramref name="command">command</paramref>.
  1658. ''' </param>
  1659. ''' <returns></returns>
  1660. ''' <remarks></remarks>
  1661. Public Function QueryInteger(ByVal subHeader As String) As Nullable(Of Integer) Implements IController.QueryInteger
  1662. Return Me.Port.QueryInteger(Syntax.BuildQuery(Me.SyntaxHeader, subHeader))
  1663. End Function
  1664. ''' <summary>
  1665. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  1666. ''' </summary>
  1667. ''' <param name="modalityName">Specifies the modality name.</param>
  1668. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2}?' where
  1669. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  1670. ''' the second item is the <paramref name="modalityName">modality name</paramref> and
  1671. ''' the thrid item is a <paramref name="command">command</paramref>.
  1672. ''' </param>
  1673. ''' <returns></returns>
  1674. ''' <remarks></remarks>
  1675. Public Function QueryInteger(ByVal modalityName As String, ByVal subHeader As String) As Nullable(Of Integer) Implements IController.QueryInteger
  1676. Return Me.Port.QueryInteger(Syntax.BuildQuery(Me.SyntaxHeader, modalityName, subHeader))
  1677. End Function
  1678. #End Region
  1679. #Region " QUERRIES - INFINITY "
  1680. ''' <summary>
  1681. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  1682. ''' </summary>
  1683. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}?' where
  1684. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see> and
  1685. ''' the second item is a <paramref name="command">command</paramref>.
  1686. ''' </param>
  1687. ''' <returns></returns>
  1688. ''' <remarks></remarks>
  1689. Public Function QueryInfInteger(ByVal subHeader As String) As Nullable(Of Integer) Implements IController.QueryInfInteger
  1690. Return Me.Port.QueryInfInteger(Syntax.BuildQuery(Me.SyntaxHeader, subHeader))
  1691. End Function
  1692. ''' <summary>
  1693. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  1694. ''' </summary>
  1695. ''' <param name="modalityName">Specifies the modality name.</param>
  1696. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2}?' where
  1697. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  1698. ''' the second item is the <paramref name="modalityName">modality name</paramref> and
  1699. ''' the thrid item is a <paramref name="command">command</paramref>.
  1700. ''' </param>
  1701. ''' <returns></returns>
  1702. ''' <remarks></remarks>
  1703. Public Function QueryInfInteger(ByVal modalityName As String, ByVal subHeader As String) As Nullable(Of Integer) Implements IController.QueryInfInteger
  1704. Return Me.Port.QueryInfInteger(Syntax.BuildQuery(Me.SyntaxHeader, modalityName, subHeader))
  1705. End Function
  1706. #End Region
  1707. #Region " GETTERS "
  1708. ''' <summary>
  1709. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  1710. ''' </summary>
  1711. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}?' where
  1712. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see> and
  1713. ''' the second item is a <paramref name="command">command</paramref>
  1714. ''' </param>
  1715. ''' <param name="existingValue">Specifies the existing value.</param>
  1716. ''' <returns></returns>
  1717. ''' <remarks></remarks>
  1718. Public Function Getter(ByVal subHeader As String,
  1719. ByVal existingValue As Nullable(Of Integer),
  1720. ByVal access As ResourceAccessLevels) As Nullable(Of Int32) Implements IController.Getter
  1721. If access.IsDeviceAccess OrElse Not existingValue.HasValue Then
  1722. existingValue = Me.QueryInteger(subHeader)
  1723. End If
  1724. Return existingValue
  1725. End Function
  1726. ''' <summary>
  1727. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  1728. ''' </summary>
  1729. ''' <param name="modalityName">Specifies the modality name.</param>
  1730. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2}?' where
  1731. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  1732. ''' the second item is the <paramref name="modalityName">modality name</paramref> and
  1733. ''' the second item is a <paramref name="command">command</paramref>.
  1734. ''' </param>
  1735. ''' <param name="existingValue">Specifies the existing value.</param>
  1736. ''' <returns></returns>
  1737. ''' <remarks></remarks>
  1738. Public Function Getter(ByVal modalityName As String, ByVal subHeader As String,
  1739. ByVal existingValue As Nullable(Of Integer),
  1740. ByVal access As ResourceAccessLevels) As Nullable(Of Integer) Implements IController.Getter
  1741. If access.IsDeviceAccess OrElse Not existingValue.HasValue Then
  1742. existingValue = Me.QueryInteger(modalityName, subHeader)
  1743. End If
  1744. Return existingValue
  1745. End Function
  1746. ''' <summary>
  1747. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  1748. ''' </summary>
  1749. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}?' where
  1750. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see> and
  1751. ''' the second item is a <paramref name="command">command</paramref>
  1752. ''' </param>
  1753. ''' <param name="existingValue">Specifies the existing value.</param>
  1754. ''' <returns></returns>
  1755. ''' <remarks></remarks>
  1756. Public Function GetterInfinity(ByVal subHeader As String,
  1757. ByVal existingValue As Nullable(Of Integer),
  1758. ByVal access As ResourceAccessLevels) As Nullable(Of Integer) Implements IController.GetterInfinity
  1759. If access.IsDeviceAccess OrElse Not existingValue.HasValue Then
  1760. existingValue = Me.QueryInfInteger(subHeader)
  1761. End If
  1762. Return existingValue
  1763. End Function
  1764. ''' <summary>
  1765. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  1766. ''' </summary>
  1767. ''' <param name="modalityName">Specifies the modality name.</param>
  1768. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2}?' where
  1769. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  1770. ''' the second item is the <paramref name="modalityName">modality name</paramref> and
  1771. ''' the second item is a <paramref name="command">command</paramref>.
  1772. ''' </param>
  1773. ''' <param name="existingValue">Specifies the existing value.</param>
  1774. ''' <returns></returns>
  1775. ''' <remarks></remarks>
  1776. Public Function GetterInfinity(ByVal modalityName As String, ByVal subHeader As String,
  1777. ByVal existingValue As Nullable(Of Integer),
  1778. ByVal access As ResourceAccessLevels) As Nullable(Of Integer) Implements IController.GetterInfinity
  1779. If access.IsDeviceAccess OrElse Not existingValue.HasValue Then
  1780. existingValue = Me.QueryInfInteger(modalityName, subHeader)
  1781. End If
  1782. Return existingValue
  1783. End Function
  1784. #End Region
  1785. #Region " GETTERS w/ ELEMENT "
  1786. ''' <summary>
  1787. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  1788. ''' Uses or updates the nullable value getter command.
  1789. ''' </summary>
  1790. ''' <param name="element">Specifies the <see cref="IScpiValueBase">existing element</see> where the getter command is stored.</param>
  1791. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}?' where
  1792. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see> and
  1793. ''' the second item is a <paramref name="command">command</paramref>
  1794. ''' </param>
  1795. ''' <param name="existingValue">Specifies the existing value.</param>
  1796. ''' <returns></returns>
  1797. ''' <remarks></remarks>
  1798. Public Function Getter(ByVal element As IScpiValueBase,
  1799. ByVal subHeader As String,
  1800. ByVal existingValue As Nullable(Of Integer),
  1801. ByVal access As ResourceAccessLevels) As Nullable(Of Int32) Implements IController.Getter
  1802. If access.IsDeviceAccess OrElse Not existingValue.HasValue Then
  1803. If String.IsNullOrEmpty(element.GetterCommand) Then
  1804. element.GetterCommand = Syntax.BuildQuery(Me.SyntaxHeader, subHeader)
  1805. End If
  1806. ' existingValue = Me.QueryInteger(subHeader)
  1807. existingValue = Me.Port.QueryInteger(element.GetterCommand)
  1808. End If
  1809. Return existingValue
  1810. End Function
  1811. ''' <summary>
  1812. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  1813. ''' Uses or updates the nullable value getter command.
  1814. ''' </summary>
  1815. ''' <param name="element">Specifies the <see cref="IScpiValueBase">existing element</see> where the getter command is stored.</param>
  1816. ''' <param name="modalityName">Specifies the modality name.</param>
  1817. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2}?' where
  1818. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  1819. ''' the second item is the <paramref name="modalityName">modality name</paramref> and
  1820. ''' the second item is a <paramref name="command">command</paramref>.
  1821. ''' </param>
  1822. ''' <param name="existingValue">Specifies the existing value.</param>
  1823. ''' <returns></returns>
  1824. ''' <remarks></remarks>
  1825. Public Function Getter(ByVal element As IScpiValueBase,
  1826. ByVal modalityName As String, ByVal subHeader As String,
  1827. ByVal existingValue As Nullable(Of Integer),
  1828. ByVal access As ResourceAccessLevels) As Nullable(Of Integer) Implements IController.Getter
  1829. If access.IsDeviceAccess OrElse Not existingValue.HasValue Then
  1830. If String.IsNullOrEmpty(element.GetterCommand) Then
  1831. element.GetterCommand = Syntax.BuildQuery(Me.SyntaxHeader, modalityName, subHeader)
  1832. End If
  1833. ' existingValue = Me.QueryInteger(modalityName, subHeader)
  1834. existingValue = Me.Port.QueryInteger(element.GetterCommand)
  1835. End If
  1836. Return existingValue
  1837. End Function
  1838. ''' <summary>
  1839. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  1840. ''' Uses or updates the nullable value getter command.
  1841. ''' </summary>
  1842. ''' <param name="element">Specifies the <see cref="IScpiValueBase">existing element</see> where the getter command is stored.</param>
  1843. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}?' where
  1844. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see> and
  1845. ''' the second item is a <paramref name="command">command</paramref>
  1846. ''' </param>
  1847. ''' <param name="existingValue">Specifies the existing value.</param>
  1848. ''' <returns></returns>
  1849. ''' <remarks></remarks>
  1850. Public Function GetterInfinity(ByVal element As IScpiValueBase,
  1851. ByVal subHeader As String,
  1852. ByVal existingValue As Nullable(Of Integer),
  1853. ByVal access As ResourceAccessLevels) As Nullable(Of Integer) Implements IController.GetterInfinity
  1854. If access.IsDeviceAccess OrElse Not existingValue.HasValue Then
  1855. If String.IsNullOrEmpty(element.GetterCommand) Then
  1856. element.GetterCommand = Syntax.BuildQuery(Me.SyntaxHeader, subHeader)
  1857. End If
  1858. ' existingValue = Me.QueryInfInteger(subHeader)
  1859. existingValue = Me.Port.QueryInfInteger(element.GetterCommand)
  1860. End If
  1861. Return existingValue
  1862. End Function
  1863. ''' <summary>
  1864. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  1865. ''' Uses or updates the nullable value getter command.
  1866. ''' </summary>
  1867. ''' <param name="element">Specifies the <see cref="IScpiValueBase">existing element</see> where the getter command is stored.</param>
  1868. ''' <param name="modalityName">Specifies the modality name.</param>
  1869. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2}?' where
  1870. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  1871. ''' the second item is the <paramref name="modalityName">modality name</paramref> and
  1872. ''' the second item is a <paramref name="command">command</paramref>.
  1873. ''' </param>
  1874. ''' <param name="existingValue">Specifies the existing value.</param>
  1875. ''' <returns></returns>
  1876. ''' <remarks></remarks>
  1877. Public Function GetterInfinity(ByVal element As IScpiValueBase,
  1878. ByVal modalityName As String, ByVal subHeader As String,
  1879. ByVal existingValue As Nullable(Of Integer),
  1880. ByVal access As ResourceAccessLevels) As Nullable(Of Integer) Implements IController.GetterInfinity
  1881. If access.IsDeviceAccess OrElse Not existingValue.HasValue Then
  1882. If String.IsNullOrEmpty(element.GetterCommand) Then
  1883. element.GetterCommand = Syntax.BuildQuery(Me.SyntaxHeader, modalityName, subHeader)
  1884. End If
  1885. ' existingValue = Me.QueryInfInteger(modalityName, subHeader)
  1886. existingValue = Me.Port.QueryInfInteger(element.GetterCommand)
  1887. End If
  1888. Return existingValue
  1889. End Function
  1890. #End Region
  1891. #Region " GETTERS w/ SCPI VALUE DEVICE ACCESS "
  1892. ''' <summary>
  1893. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  1894. ''' Uses or updates the nullable value getter command.
  1895. ''' </summary>
  1896. ''' <param name="element">Specifies the <see cref="IScpiValueBase">existing element</see> where the getter command is stored.</param>
  1897. ''' <returns></returns>
  1898. ''' <remarks></remarks>
  1899. Public Function Getter(ByVal element As IScpiValue(Of Integer)) As IScpiValue(Of Integer) Implements IController.Getter
  1900. element.Value = Me.Port.QueryInteger(element.GetterCommand)
  1901. element.ActualValue = element.Value
  1902. Return element
  1903. End Function
  1904. #End Region
  1905. #Region " GETTERS w/ SCPI VALUE "
  1906. ''' <summary>
  1907. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  1908. ''' Uses or updates the nullable value getter command.
  1909. ''' </summary>
  1910. ''' <param name="element">Specifies the <see cref="IScpiValueBase">existing element</see> where the getter command is stored.</param>
  1911. ''' <returns></returns>
  1912. ''' <remarks></remarks>
  1913. Public Function Getter(ByVal element As IScpiValue(Of Integer), ByVal access As ResourceAccessLevels) As IScpiValue(Of Integer) Implements IController.Getter
  1914. If access.IsDeviceAccess OrElse Not element.Value.HasValue Then
  1915. element.Value = Me.Port.QueryInteger(element.GetterCommand)
  1916. element.ActualValue = element.Value
  1917. End If
  1918. Return element
  1919. End Function
  1920. ''' <summary>
  1921. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  1922. ''' Uses or updates the nullable value getter command.
  1923. ''' </summary>
  1924. ''' <param name="element">Specifies the <see cref="IScpiValueBase">existing element</see> where the getter command is stored.</param>
  1925. ''' <returns></returns>
  1926. ''' <remarks></remarks>
  1927. Public Function GetterInfinity(ByVal element As IScpiValue(Of Integer), ByVal access As ResourceAccessLevels) As IScpiValue(Of Integer) Implements IController.GetterInfinity
  1928. If access.IsDeviceAccess OrElse Not element.Value.HasValue Then
  1929. element.Value = Me.Port.QueryInfInteger(element.GetterCommand)
  1930. element.ActualValue = element.Value
  1931. End If
  1932. Return element
  1933. End Function
  1934. ''' <summary>
  1935. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  1936. ''' Applies readings to the <paramref name="element">existing element</paramref>
  1937. ''' </summary>
  1938. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}?' where
  1939. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see> and
  1940. ''' the second item is a <paramref name="command">command</paramref>
  1941. ''' </param>
  1942. ''' <param name="element">Specifies the element holding the existing value, which is updated.</param>
  1943. ''' <returns></returns>
  1944. ''' <remarks></remarks>
  1945. Public Function Getter(ByVal element As IScpiValue(Of Integer),
  1946. ByVal subHeader As String,
  1947. ByVal access As ResourceAccessLevels) As IScpiValue(Of Integer) Implements IController.Getter
  1948. element.Value = Me.Getter(element, subHeader, element.Value, access)
  1949. element.ActualValue = element.Value
  1950. Return element
  1951. End Function
  1952. ''' <summary>
  1953. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  1954. ''' Applies readings to the <paramref name="element">existing element</paramref>
  1955. ''' </summary>
  1956. ''' <param name="modalityName">Specifies the modality name.</param>
  1957. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2}?' where
  1958. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  1959. ''' the second item is the <paramref name="modalityName">modality name</paramref> and
  1960. ''' the second item is a <paramref name="command">command</paramref>.
  1961. ''' </param>
  1962. ''' <param name="element">Specifies the element holding the existing value, which is updated.</param>
  1963. ''' <returns></returns>
  1964. ''' <remarks></remarks>
  1965. Public Function Getter(ByVal element As IScpiValue(Of Integer),
  1966. ByVal modalityName As String, ByVal subHeader As String,
  1967. ByVal access As ResourceAccessLevels) As IScpiValue(Of Integer) Implements IController.Getter
  1968. element.Value = Me.Getter(element, modalityName, subHeader, element.Value, access)
  1969. element.ActualValue = element.Value
  1970. Return element
  1971. End Function
  1972. ''' <summary>
  1973. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  1974. ''' Applies readings to the <paramref name="element">existing element</paramref>
  1975. ''' </summary>
  1976. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}?' where
  1977. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see> and
  1978. ''' the second item is a <paramref name="command">command</paramref>
  1979. ''' </param>
  1980. ''' <param name="element">Specifies the element holding the existing value, which is updated.</param>
  1981. ''' <returns></returns>
  1982. ''' <remarks></remarks>
  1983. Public Function GetterInfinity(ByVal element As IScpiValue(Of Integer),
  1984. ByVal subHeader As String, ByVal access As ResourceAccessLevels) As IScpiValue(Of Integer) Implements IController.GetterInfinity
  1985. element.Value = Me.GetterInfinity(element, subHeader, element.Value, access)
  1986. element.ActualValue = element.Value
  1987. Return element
  1988. End Function
  1989. ''' <summary>
  1990. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  1991. ''' Applies readings to the <paramref name="element">existing element</paramref>
  1992. ''' </summary>
  1993. ''' <param name="modalityName">Specifies the modality name.</param>
  1994. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2}?' where
  1995. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  1996. ''' the second item is the <paramref name="modalityName">modality name</paramref> and
  1997. ''' the second item is a <paramref name="command">command</paramref>.
  1998. ''' </param>
  1999. ''' <param name="element">Specifies the element holding the existing value, which is updated.</param>
  2000. ''' <returns></returns>
  2001. ''' <remarks></remarks>
  2002. Public Function GetterInfinity(ByVal element As IScpiValue(Of Integer),
  2003. ByVal modalityName As String, ByVal subHeader As String,
  2004. ByVal access As ResourceAccessLevels) As IScpiValue(Of Integer) Implements IController.GetterInfinity
  2005. element.Value = Me.GetterInfinity(element, modalityName, subHeader, element.Value, access)
  2006. element.ActualValue = element.Value
  2007. Return element
  2008. End Function
  2009. #End Region
  2010. #Region " SETTERS "
  2011. ''' <summary>
  2012. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  2013. ''' </summary>
  2014. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1} {2}' where
  2015. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  2016. ''' the second item is a <paramref name="command">command</paramref>
  2017. ''' the third item represents a <paramref name="value">numeric value</paramref>.
  2018. ''' </param>
  2019. ''' <param name="value">Specifies the command value.</param>
  2020. ''' <returns></returns>
  2021. ''' <remarks></remarks>
  2022. Public Function Setter(ByVal subHeader As String, ByVal value As Integer, ByVal verify As Boolean) As Boolean Implements IController.Setter
  2023. Dim scpiMessage As String = Syntax.BuildCommand(Me.SyntaxHeader, subHeader, value)
  2024. Me.Port.WriteLine(scpiMessage)
  2025. If verify Then
  2026. Dim actual As Nullable(Of Integer) = Me.QueryInteger(scpiMessage)
  2027. Return actual.HasValue AndAlso (value = actual.Value)
  2028. Else
  2029. Return True
  2030. End If
  2031. End Function
  2032. ''' <summary>
  2033. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  2034. ''' </summary>
  2035. ''' <param name="modalityName">Specifies the modality name.</param>
  2036. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2} {3}' where
  2037. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  2038. ''' the second item is the <paramref name="modalityName">modality name</paramref>,
  2039. ''' the third item is a <paramref name="command">command</paramref>
  2040. ''' the fourth item represents a <paramref name="value">numeric value</paramref>.
  2041. ''' </param>
  2042. ''' <param name="value">Specifies the command value.</param>
  2043. ''' <returns></returns>
  2044. ''' <remarks></remarks>
  2045. Public Function Setter(ByVal modalityName As String, ByVal subHeader As String, ByVal value As Integer, ByVal verify As Boolean) As Boolean Implements IController.Setter
  2046. Dim scpiMessage As String = Syntax.BuildCommand(Me.SyntaxHeader, modalityName, subHeader, value)
  2047. Me.Port.WriteLine(scpiMessage)
  2048. If verify Then
  2049. Dim actual As Nullable(Of Integer) = Me.QueryInteger(modalityName, subHeader)
  2050. Return actual.HasValue AndAlso (value = actual.Value)
  2051. Else
  2052. Return True
  2053. End If
  2054. End Function
  2055. ''' <summary>
  2056. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  2057. ''' </summary>
  2058. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1} {2}' where
  2059. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  2060. ''' the second item is a <paramref name="command">command</paramref>
  2061. ''' the third item represents a <paramref name="value">numeric value</paramref>.
  2062. ''' </param>
  2063. ''' <param name="value">Specifies the command value.</param>
  2064. ''' <returns></returns>
  2065. ''' <remarks></remarks>
  2066. Public Function SetterInfinity(ByVal subHeader As String, ByVal value As Integer, ByVal verify As Boolean) As Boolean Implements IController.SetterInfinity
  2067. Dim scpiMessage As String = Syntax.BuildCommand(Me.SyntaxHeader, subHeader, value)
  2068. Me.Port.WriteLine(scpiMessage)
  2069. If verify Then
  2070. Dim actual As Nullable(Of Integer) = Me.QueryInteger(scpiMessage)
  2071. Return actual.HasValue AndAlso (value = actual.Value)
  2072. Else
  2073. Return True
  2074. End If
  2075. End Function
  2076. ''' <summary>
  2077. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  2078. ''' </summary>
  2079. ''' <param name="modalityName">Specifies the modality name.</param>
  2080. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2} {3}' where
  2081. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  2082. ''' the second item is the <paramref name="modalityName">modality name</paramref>,
  2083. ''' the third item is a <paramref name="command">command</paramref>
  2084. ''' the fourth item represents a <paramref name="value">numeric value</paramref>.
  2085. ''' </param>
  2086. ''' <param name="value">Specifies the command value.</param>
  2087. ''' <returns></returns>
  2088. ''' <remarks></remarks>
  2089. Public Function SetterInfinity(ByVal modalityName As String, ByVal subHeader As String, ByVal value As Integer, ByVal verify As Boolean) As Boolean Implements IController.SetterInfinity
  2090. Dim scpiMessage As String = Syntax.BuildCommand(Me.SyntaxHeader, modalityName, subHeader, value)
  2091. Me.Port.WriteLine(scpiMessage)
  2092. If verify Then
  2093. Dim actual As Nullable(Of Integer) = Me.QueryInteger(modalityName, subHeader)
  2094. Return actual.HasValue AndAlso (value = actual.Value)
  2095. Else
  2096. Return True
  2097. End If
  2098. End Function
  2099. #End Region
  2100. #Region " SETTERS w/ ACCESS "
  2101. ''' <summary>
  2102. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  2103. ''' </summary>
  2104. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1} {2}' where
  2105. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>
  2106. ''' the second item is a <paramref name="command">command</paramref> and
  2107. ''' the third item is the <paramref name="value">value</paramref>.
  2108. ''' </param>
  2109. ''' <param name="existingValue">Specifies the existing value.</param>
  2110. ''' <returns></returns>
  2111. ''' <remarks></remarks>
  2112. Public Function Setter(ByVal subHeader As String,
  2113. ByVal existingValue As Nullable(Of Integer), ByVal value As Integer,
  2114. ByVal access As ResourceAccessLevels) As Nullable(Of Integer) Implements IController.Setter
  2115. If access.IsVerifyAccess Then
  2116. Throw New ArgumentException("Verification not supported by this method", "access")
  2117. End If
  2118. If access.IsDeviceAccess OrElse (value <> existingValue) Then
  2119. Me.Port.WriteLine(Syntax.BuildCommand(Me.SyntaxHeader, subHeader, value))
  2120. End If
  2121. Return New Nullable(Of Integer)(value)
  2122. End Function
  2123. ''' <summary>
  2124. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  2125. ''' </summary>
  2126. ''' <param name="modalityName">Specifies the modality name.</param>
  2127. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2} {3}' where
  2128. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  2129. ''' the second item is the <paramref name="modalityName">modality name</paramref>,
  2130. ''' the second item is a <paramref name="command">command</paramref> and
  2131. ''' the fourth item represents a <paramref name="value">numeric value</paramref>.
  2132. ''' </param>
  2133. ''' <param name="existingValue">Specifies the existing value.</param>
  2134. ''' <returns></returns>
  2135. ''' <remarks></remarks>
  2136. Public Function Setter(ByVal modalityName As String, ByVal subHeader As String,
  2137. ByVal existingValue As Nullable(Of Integer), ByVal value As Integer,
  2138. ByVal access As ResourceAccessLevels) As Nullable(Of Integer) Implements IController.Setter
  2139. If access.IsVerifyAccess Then
  2140. Throw New ArgumentException("Verification not supported by this method", "access")
  2141. End If
  2142. If access.IsDeviceAccess OrElse (value <> existingValue) Then
  2143. Me.Port.WriteLine(Syntax.BuildCommand(Me.SyntaxHeader, modalityName, subHeader, value))
  2144. End If
  2145. Return New Nullable(Of Integer)(value)
  2146. End Function
  2147. ''' <summary>
  2148. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  2149. ''' </summary>
  2150. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1} {2}' where
  2151. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>
  2152. ''' the second item is a <paramref name="command">command</paramref> and
  2153. ''' the third item is the <paramref name="value">value</paramref>.
  2154. ''' </param>
  2155. ''' <param name="existingValue">Specifies the existing value.</param>
  2156. ''' <returns></returns>
  2157. ''' <remarks></remarks>
  2158. Public Function SetterInfinity(ByVal subHeader As String,
  2159. ByVal existingValue As Nullable(Of Integer), ByVal value As Integer,
  2160. ByVal access As ResourceAccessLevels) As Nullable(Of Integer) Implements IController.SetterInfinity
  2161. If access.IsVerifyAccess Then
  2162. Throw New ArgumentException("Verification not supported by this method", "access")
  2163. End If
  2164. If access.IsDeviceAccess OrElse (value <> existingValue) Then
  2165. Me.Port.WriteLine(Syntax.BuildCommand(Me.SyntaxHeader, subHeader, value))
  2166. End If
  2167. Return New Nullable(Of Integer)(value)
  2168. End Function
  2169. ''' <summary>
  2170. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  2171. ''' </summary>
  2172. ''' <param name="modalityName">Specifies the modality name.</param>
  2173. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2} {3}' where
  2174. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  2175. ''' the second item is the <paramref name="modalityName">modality name</paramref>,
  2176. ''' the second item is a <paramref name="command">command</paramref> and
  2177. ''' the fourth item represents a <paramref name="value">numeric value</paramref>.
  2178. ''' </param>
  2179. ''' <param name="existingValue">Specifies the existing value.</param>
  2180. ''' <returns></returns>
  2181. ''' <remarks></remarks>
  2182. Public Function SetterInfinity(ByVal modalityName As String, ByVal subHeader As String,
  2183. ByVal existingValue As Nullable(Of Integer), ByVal value As Integer,
  2184. ByVal access As ResourceAccessLevels) As Nullable(Of Integer) Implements IController.SetterInfinity
  2185. If access.IsVerifyAccess Then
  2186. Throw New ArgumentException("Verification not supported by this method", "access")
  2187. End If
  2188. If access.IsDeviceAccess OrElse (value <> existingValue) Then
  2189. Me.Port.WriteLine(Syntax.BuildCommand(Me.SyntaxHeader, modalityName, subHeader, value))
  2190. End If
  2191. Return New Nullable(Of Integer)(value)
  2192. End Function
  2193. #End Region
  2194. #Region " SETTERS w/ ACCESS w/ ELEMENT "
  2195. ''' <summary>
  2196. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  2197. ''' </summary>
  2198. ''' <param name="element">Specifies the <see cref="IScpiValueBase">existing element</see> where the getter command is stored.</param>
  2199. ''' <param name="existingValue">Specifies the existing element value where the instrument.</param>
  2200. ''' <param name="value">Specifies the value to be set using the element <see cref="IScpiValueBase.SetterCommandFormat">command</see>.</param>
  2201. ''' <returns></returns>
  2202. ''' <remarks></remarks>
  2203. Public Function Setter(ByVal element As IScpiValueBase,
  2204. ByVal existingValue As Integer, ByVal value As Integer,
  2205. ByVal access As ResourceAccessLevels) As Integer Implements IController.Setter
  2206. If access.IsVerifyAccess Then
  2207. Throw New ArgumentException("Verification not supported by this method", "access")
  2208. End If
  2209. If access.IsDeviceAccess OrElse value <> existingValue Then
  2210. If Not String.IsNullOrEmpty(element.SetterCommandFormat) Then
  2211. element.SetterCommand = String.Format(Globalization.CultureInfo.InvariantCulture,
  2212. element.SetterCommandFormat, value)
  2213. ElseIf String.IsNullOrEmpty(element.SetterCommand) Then
  2214. Throw New ArgumentException("Element setter command is empty", "element")
  2215. End If
  2216. Me.Port.WriteLine(element.SetterCommand)
  2217. End If
  2218. Return value
  2219. End Function
  2220. ''' <summary>
  2221. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  2222. ''' Uses or updates the nullable value getter command.
  2223. ''' </summary>
  2224. ''' <param name="element">Specifies the <see cref="IScpiValueBase">existing element</see> where the getter command is stored.</param>
  2225. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1} {2}' where
  2226. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>
  2227. ''' the second item is a <paramref name="command">command</paramref> and
  2228. ''' the third item is the <paramref name="value">value</paramref>.
  2229. ''' </param>
  2230. ''' <param name="existingValue">Specifies the existing value.</param>
  2231. ''' <returns></returns>
  2232. ''' <remarks></remarks>
  2233. Public Function Setter(ByVal element As IScpiValueBase,
  2234. ByVal subHeader As String,
  2235. ByVal existingValue As Nullable(Of Integer), ByVal value As Integer,
  2236. ByVal access As ResourceAccessLevels) As Nullable(Of Integer) Implements IController.Setter
  2237. If access.IsVerifyAccess Then
  2238. Throw New ArgumentException("Verification not supported by this method", "access")
  2239. End If
  2240. If access.IsDeviceAccess OrElse (value <> existingValue) Then
  2241. If String.IsNullOrEmpty(element.SetterCommandFormat) Then
  2242. element.SetterCommandFormat = Syntax.BuildCommandFormat(Me.SyntaxHeader, subHeader)
  2243. End If
  2244. element.SetterCommand = Syntax.BuildCommand(Me.SyntaxHeader, subHeader, value)
  2245. Me.Port.WriteLine(element.SetterCommand)
  2246. End If
  2247. Return New Nullable(Of Integer)(value)
  2248. End Function
  2249. ''' <summary>
  2250. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  2251. ''' Uses or updates the nullable value getter command.
  2252. ''' </summary>
  2253. ''' <param name="element">Specifies the <see cref="IScpiValueBase">existing element</see> where the getter command is stored.</param>
  2254. ''' <param name="modalityName">Specifies the modality name.</param>
  2255. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2} {3}' where
  2256. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  2257. ''' the second item is the <paramref name="modalityName">modality name</paramref>,
  2258. ''' the second item is a <paramref name="command">command</paramref> and
  2259. ''' the fourth item represents a <paramref name="value">numeric value</paramref>.
  2260. ''' </param>
  2261. ''' <param name="existingValue">Specifies the existing value.</param>
  2262. ''' <returns></returns>
  2263. ''' <remarks></remarks>
  2264. Public Function Setter(ByVal element As IScpiValueBase,
  2265. ByVal modalityName As String, ByVal subHeader As String,
  2266. ByVal existingValue As Nullable(Of Integer), ByVal value As Integer,
  2267. ByVal access As ResourceAccessLevels) As Nullable(Of Integer) Implements IController.Setter
  2268. If access.IsVerifyAccess Then
  2269. Throw New ArgumentException("Verification not supported by this method", "access")
  2270. End If
  2271. If access.IsDeviceAccess OrElse (value <> existingValue) Then
  2272. If String.IsNullOrEmpty(element.SetterCommandFormat) Then
  2273. element.SetterCommandFormat = Syntax.BuildCommandFormat(Me.SyntaxHeader, modalityName, subHeader)
  2274. End If
  2275. element.SetterCommand = Syntax.BuildCommand(Me.SyntaxHeader, modalityName, subHeader, value)
  2276. Me.Port.WriteLine(element.SetterCommand)
  2277. End If
  2278. Return New Nullable(Of Integer)(value)
  2279. End Function
  2280. ''' <summary>
  2281. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  2282. ''' Uses or updates the nullable value getter command.
  2283. ''' </summary>
  2284. ''' <param name="element">Specifies the <see cref="IScpiValueBase">existing element</see> where the getter command is stored.</param>
  2285. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1} {2}' where
  2286. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>
  2287. ''' the second item is a <paramref name="command">command</paramref> and
  2288. ''' the third item is the <paramref name="value">value</paramref>.
  2289. ''' </param>
  2290. ''' <param name="existingValue">Specifies the existing value.</param>
  2291. ''' <returns></returns>
  2292. ''' <remarks></remarks>
  2293. Public Function SetterInfinity(ByVal element As IScpiValueBase,
  2294. ByVal subHeader As String,
  2295. ByVal existingValue As Nullable(Of Integer), ByVal value As Integer,
  2296. ByVal access As ResourceAccessLevels) As Nullable(Of Integer) Implements IController.SetterInfinity
  2297. If access.IsVerifyAccess Then
  2298. Throw New ArgumentException("Verification not supported by this method", "access")
  2299. End If
  2300. If access.IsDeviceAccess OrElse (value <> existingValue) Then
  2301. If String.IsNullOrEmpty(element.SetterCommandFormat) Then
  2302. element.SetterCommandFormat = Syntax.BuildCommandFormat(Me.SyntaxHeader, subHeader)
  2303. End If
  2304. element.SetterCommand = Syntax.BuildCommand(Me.SyntaxHeader, subHeader, value)
  2305. Me.Port.WriteLine(element.SetterCommand)
  2306. End If
  2307. Return New Nullable(Of Integer)(value)
  2308. End Function
  2309. ''' <summary>
  2310. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  2311. ''' Uses or updates the nullable value getter command.
  2312. ''' </summary>
  2313. ''' <param name="element">Specifies the <see cref="IScpiValueBase">existing element</see> where the getter command is stored.</param>
  2314. ''' <param name="modalityName">Specifies the modality name.</param>
  2315. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2} {3}' where
  2316. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  2317. ''' the second item is the <paramref name="modalityName">modality name</paramref>,
  2318. ''' the second item is a <paramref name="command">command</paramref> and
  2319. ''' the fourth item represents a <paramref name="value">numeric value</paramref>.
  2320. ''' </param>
  2321. ''' <param name="existingValue">Specifies the existing value.</param>
  2322. ''' <returns></returns>
  2323. ''' <remarks></remarks>
  2324. Public Function SetterInfinity(ByVal element As IScpiValueBase,
  2325. ByVal modalityName As String, ByVal subHeader As String,
  2326. ByVal existingValue As Nullable(Of Integer), ByVal value As Integer,
  2327. ByVal access As ResourceAccessLevels) As Nullable(Of Integer) Implements IController.SetterInfinity
  2328. If access.IsVerifyAccess Then
  2329. Throw New ArgumentException("Verification not supported by this method", "access")
  2330. End If
  2331. If access.IsDeviceAccess OrElse (value <> existingValue) Then
  2332. If String.IsNullOrEmpty(element.SetterCommandFormat) Then
  2333. element.SetterCommandFormat = Syntax.BuildCommandFormat(Me.SyntaxHeader, modalityName, subHeader)
  2334. End If
  2335. element.SetterCommand = Syntax.BuildCommand(Me.SyntaxHeader, modalityName, subHeader, value)
  2336. Me.Port.WriteLine(element.SetterCommand)
  2337. End If
  2338. Return New Nullable(Of Integer)(value)
  2339. End Function
  2340. #End Region
  2341. #Region " SETTERS w/ SCPI VALUE "
  2342. ''' <summary>
  2343. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  2344. ''' Applies readings to the <paramref name="element">existing element</paramref>
  2345. ''' Assume element has both <see cref="IScpiValueBase.GetterCommand">getter</see> and
  2346. ''' <see cref="IScpiValueBase.SetterCommand">setter</see> commands specified.
  2347. ''' </summary>
  2348. ''' <param name="element">Specifies the element holding the existing value, which is updated.</param>
  2349. ''' <returns></returns>
  2350. ''' <remarks></remarks>
  2351. Public Function Setter(ByVal element As IScpiValue(Of Integer), ByVal value As Integer, ByVal access As ResourceAccessLevels) As IScpiValue(Of Integer) Implements IController.Setter
  2352. If access.IsDeviceAccess OrElse (value <> element.Value) Then
  2353. element.Value = Me.Setter(CType(element, IScpiValueBase), element.Value.Value, value, access And Not ResourceAccessLevels.Verify)
  2354. End If
  2355. If access.IsVerifyAccess Then
  2356. Me.Getter(element, ResourceAccessLevels.Device)
  2357. element.Value = value
  2358. ElseIf access.IsCacheAccess Then
  2359. element.ActualValue = value
  2360. End If
  2361. Return element
  2362. End Function
  2363. ''' <summary>
  2364. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  2365. ''' Applies readings to the <paramref name="element">existing element</paramref>
  2366. ''' </summary>
  2367. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1} {2}' where
  2368. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>
  2369. ''' the second item is a <paramref name="command">command</paramref> and
  2370. ''' the third item is the <paramref name="value">value</paramref>.
  2371. ''' </param>
  2372. ''' <param name="element">Specifies the element holding the existing value, which is updated.</param>
  2373. ''' <returns></returns>
  2374. ''' <remarks></remarks>
  2375. Public Function Setter(ByVal element As IScpiValue(Of Integer),
  2376. ByVal subHeader As String, ByVal value As Integer,
  2377. ByVal access As ResourceAccessLevels) As IScpiValue(Of Integer) Implements IController.Setter
  2378. element.Value = Me.Setter(CType(element, IScpiValueBase), subHeader, element.Value, value, access And Not ResourceAccessLevels.Verify)
  2379. If access.IsVerifyAccess Then
  2380. Me.Getter(element, subHeader, ResourceAccessLevels.Device)
  2381. element.Value = value
  2382. ElseIf access.IsCacheAccess Then
  2383. element.ActualValue = value
  2384. End If
  2385. Return element
  2386. End Function
  2387. ''' <summary>
  2388. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  2389. ''' Applies readings to the <paramref name="element">existing element</paramref>
  2390. ''' </summary>
  2391. ''' <param name="modalityName">Specifies the modality name.</param>
  2392. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2} {3}' where
  2393. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  2394. ''' the second item is the <paramref name="modalityName">modality name</paramref>,
  2395. ''' the second item is a <paramref name="command">command</paramref> and
  2396. ''' the fourth item represents a <paramref name="value">numeric value</paramref>.
  2397. ''' </param>
  2398. ''' <param name="element">Specifies the element holding the existing value, which is updated.</param>
  2399. ''' <returns></returns>
  2400. ''' <remarks></remarks>
  2401. Public Function Setter(ByVal element As IScpiValue(Of Integer),
  2402. ByVal modalityName As String, ByVal subHeader As String, ByVal value As Integer,
  2403. ByVal access As ResourceAccessLevels) As IScpiValue(Of Integer) Implements IController.Setter
  2404. element.Value = Me.Setter(CType(element, IScpiValueBase), modalityName, subHeader, element.Value, value, access And Not ResourceAccessLevels.Verify)
  2405. If access.IsVerifyAccess Then
  2406. Me.Getter(element, subHeader, ResourceAccessLevels.Device)
  2407. element.Value = value
  2408. ElseIf access.IsCacheAccess Then
  2409. element.ActualValue = value
  2410. End If
  2411. Return element
  2412. End Function
  2413. ''' <summary>
  2414. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  2415. ''' Applies readings to the <paramref name="element">existing element</paramref>
  2416. ''' </summary>
  2417. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1} {2}' where
  2418. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>
  2419. ''' the second item is a <paramref name="command">command</paramref> and
  2420. ''' the third item is the <paramref name="value">value</paramref>.
  2421. ''' </param>
  2422. ''' <param name="element">Specifies the element holding the existing value, which is updated.</param>
  2423. ''' <returns></returns>
  2424. ''' <remarks></remarks>
  2425. Public Function SetterInfinity(ByVal element As IScpiValue(Of Integer),
  2426. ByVal subHeader As String, ByVal value As Integer,
  2427. ByVal access As ResourceAccessLevels) As IScpiValue(Of Integer) Implements IController.SetterInfinity
  2428. element.Value = Me.SetterInfinity(CType(element, IScpiValueBase), subHeader, element.Value, value, access And Not ResourceAccessLevels.Verify)
  2429. If access.IsVerifyAccess Then
  2430. Me.Getter(element, subHeader, ResourceAccessLevels.Device)
  2431. element.Value = value
  2432. ElseIf access.IsCacheAccess Then
  2433. element.ActualValue = value
  2434. End If
  2435. Return element
  2436. End Function
  2437. ''' <summary>
  2438. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  2439. ''' Applies readings to the <paramref name="element">existing element</paramref>
  2440. ''' </summary>
  2441. ''' <param name="modalityName">Specifies the modality name.</param>
  2442. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2} {3}' where
  2443. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  2444. ''' the second item is the <paramref name="modalityName">modality name</paramref>,
  2445. ''' the second item is a <paramref name="command">command</paramref> and
  2446. ''' the fourth item represents a <paramref name="value">numeric value</paramref>.
  2447. ''' </param>
  2448. ''' <param name="element">Specifies the element holding the existing value, which is updated.</param>
  2449. ''' <returns></returns>
  2450. ''' <remarks></remarks>
  2451. Public Function SetterInfinity(ByVal element As IScpiValue(Of Integer),
  2452. ByVal modalityName As String, ByVal subHeader As String, ByVal value As Integer,
  2453. ByVal access As ResourceAccessLevels) As IScpiValue(Of Integer) Implements IController.SetterInfinity
  2454. element.Value = Me.SetterInfinity(CType(element, IScpiValueBase), modalityName, subHeader, element.Value, value, access And Not ResourceAccessLevels.Verify)
  2455. If access.IsVerifyAccess Then
  2456. Me.Getter(element, subHeader, ResourceAccessLevels.Device)
  2457. element.Value = value
  2458. ElseIf access.IsCacheAccess Then
  2459. element.ActualValue = value
  2460. End If
  2461. Return element
  2462. End Function
  2463. #End Region
  2464. #End Region
  2465. End Class
  2466. Public Module [SystemExtensions]
  2467. #Region " ACCESS LEVEL "
  2468. ''' <summary>
  2469. ''' Returns true if cache only access level is requested.
  2470. ''' </summary>
  2471. ''' <param name="access"></param>
  2472. ''' <returns></returns>
  2473. ''' <remarks></remarks>
  2474. <Runtime.CompilerServices.Extension()>
  2475. Public Function IsCacheAccess(ByVal access As ResourceAccessLevels) As Boolean
  2476. Return (access And ResourceAccessLevels.Cache) <> 0
  2477. End Function
  2478. ''' <summary>
  2479. ''' Returns true if device access level is requested.
  2480. ''' </summary>
  2481. ''' <param name="access"></param>
  2482. ''' <returns></returns>
  2483. ''' <remarks></remarks>
  2484. <Runtime.CompilerServices.Extension()>
  2485. Public Function IsDeviceAccess(ByVal access As ResourceAccessLevels) As Boolean
  2486. Return (access And ResourceAccessLevels.Device) <> 0
  2487. End Function
  2488. ''' <summary>
  2489. ''' Returns true if device verification access level is requested.
  2490. ''' </summary>
  2491. ''' <param name="access"></param>
  2492. ''' <returns></returns>
  2493. ''' <remarks></remarks>
  2494. <Runtime.CompilerServices.Extension()>
  2495. Public Function IsVerifyAccess(ByVal access As ResourceAccessLevels) As Boolean
  2496. Return (access And ResourceAccessLevels.Verify) <> 0
  2497. End Function
  2498. #End Region
  2499. End Module
  2500. #Region " UNUSED "
  2501. #If False Then
  2502. #Region " REMOVE "
  2503. ''' <summary>
  2504. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  2505. ''' Applies readings to the <paramref name="element">existing element</paramref>
  2506. ''' </summary>
  2507. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}?' where
  2508. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see> and
  2509. ''' the second item is a <paramref name="command">command</paramref>
  2510. ''' </param>
  2511. ''' <param name="element">Specifies the element holding the existing value, which is updated.</param>
  2512. ''' <returns></returns>
  2513. ''' <remarks></remarks>
  2514. Public Function Getter(ByVal subHeader As String, ByVal element As ResettableValue(Of Boolean),
  2515. ByVal access As ResourceAccessLevels) As ResettableValue(Of Boolean)
  2516. element.Value = Me.Getter(element, subHeader, element.Value, access)
  2517. element.ActualValue = element.Value
  2518. Return element
  2519. End Function
  2520. ''' <summary>
  2521. ''' Gets a value from the instrument using the <paramref name="command">SCPI command</paramref> syntax.
  2522. ''' Applies readings to the <paramref name="element">existing element</paramref>
  2523. ''' </summary>
  2524. ''' <param name="modalityName">Specifies the modality name.</param>
  2525. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2}?' where
  2526. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  2527. ''' the second item is the <paramref name="modalityName">modality name</paramref> and
  2528. ''' the second item is a <paramref name="command">command</paramref>.
  2529. ''' </param>
  2530. ''' <param name="element">Specifies the element holding the existing value, which is updated.</param>
  2531. ''' <returns></returns>
  2532. ''' <remarks></remarks>
  2533. Public Function Getter(ByVal modalityName As String, ByVal subHeader As String,
  2534. ByVal element As ResettableValue(Of Boolean),
  2535. ByVal access As ResourceAccessLevels) As ResettableValue(Of Boolean)
  2536. If access.IsDeviceAccess OrElse Not element.Value.HasValue Then
  2537. element.Value = Me.QueryBoolean(modalityName, subHeader)
  2538. element.ActualValue = element.Value
  2539. End If
  2540. Return element
  2541. End Function
  2542. #End Region
  2543. ''' <summary>Gets the line frequency for this instrument.
  2544. ''' The line frequency can be read from the instrument. Instruments that do
  2545. ''' not support this command must set the value when initialized.</summary>
  2546. Public ReadOnly Property ControllerLineFrequency() As Double
  2547. Get
  2548. Return Me._controller.SystemSubsystem.LineFrequency
  2549. End Get
  2550. End Property
  2551. #Region " REMOVE "
  2552. ''' <summary>
  2553. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  2554. ''' Applies readings to the <paramref name="element">existing element</paramref>
  2555. ''' </summary>
  2556. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1} {2}' where
  2557. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>
  2558. ''' the second item is a <paramref name="command">command</paramref> and
  2559. ''' the third item is the <paramref name="value">value</paramref>.
  2560. ''' </param>
  2561. ''' <param name="element">Specifies the element holding the existing value, which is updated.</param>
  2562. ''' <returns></returns>
  2563. ''' <remarks></remarks>
  2564. Public Function Setter(ByVal subHeader As String, ByVal element As ResettableValue(Of Boolean),
  2565. ByVal value As Boolean, ByVal boolFormat As BooleanDataFormat,
  2566. ByVal access As ResourceAccessLevels) As ResettableValue(Of Boolean)
  2567. If access.IsDeviceAccess OrElse (value <> element) Then
  2568. MyBase.Controller.Port.WriteLine(Syntax.BuildCommand(MyBase.SyntaxHeader, subHeader, value, boolFormat))
  2569. End If
  2570. If access.IsVerifyAccess Then
  2571. Dim actual As New ResettableValue(Of Boolean)
  2572. Me.Getter(actual, subHeader, ResourceAccessLevels.Device)
  2573. If value <> actual.Value Then
  2574. If actual.Value.HasValue Then
  2575. Throw New VerificationException(
  2576. Syntax.BuildCommand(MyBase.SyntaxHeader, subHeader, value, boolFormat), value, actual.Value.Value)
  2577. Else
  2578. Throw New VerificationException("Getter failed reading.")
  2579. End If
  2580. End If
  2581. End If
  2582. element.Value = value
  2583. Return element
  2584. End Function
  2585. ''' <summary>
  2586. ''' Sets an instrument value using the <paramref name="command">SCPI command</paramref> syntax.
  2587. ''' Applies readings to the <paramref name="element">existing element</paramref>
  2588. ''' </summary>
  2589. ''' <param name="modalityName">Specifies the modality name.</param>
  2590. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2} {3}' where
  2591. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  2592. ''' the second item is the <paramref name="modalityName">modality name</paramref>,
  2593. ''' the second item is a <paramref name="command">command</paramref> and
  2594. ''' the fourth item represents a <paramref name="value">numeric value</paramref>.
  2595. ''' </param>
  2596. ''' <param name="element">Specifies the element holding the existing value, which is updated.</param>
  2597. ''' <returns></returns>
  2598. ''' <remarks></remarks>
  2599. Public Function Setter(ByVal modalityName As String, ByVal subHeader As String,
  2600. ByVal element As IScpiValue(Of Boolean), ByVal value As Boolean,
  2601. ByVal boolFormat As BooleanDataFormat, ByVal access As ResourceAccessLevels) As IScpiValue(Of Boolean)
  2602. If access.IsDeviceAccess OrElse (value <> element) Then
  2603. MyBase.Controller.Port.WriteLine(Syntax.BuildCommand(MyBase.SyntaxHeader, modalityName, subHeader, value, boolFormat))
  2604. End If
  2605. If access.IsVerifyAccess Then
  2606. Dim actual As ResettableValue(Of Boolean)
  2607. actual.Value = Me.Getter(actual, modalityName, subHeader, ResourceAccessLevels.Device).Value
  2608. If value <> actual Then
  2609. If actual.Value.HasValue Then
  2610. Throw New VerificationException(
  2611. Syntax.BuildCommand(MyBase.SyntaxHeader, modalityName, subHeader, value, boolFormat), value, actual.Value.Value)
  2612. Else
  2613. Throw New VerificationException("Getter failed reading.")
  2614. End If
  2615. End If
  2616. End If
  2617. element.Value = value
  2618. Return element
  2619. End Function
  2620. #End Region
  2621. ''' <summary>
  2622. ''' Gets the instrument <see cref="SyntaxHeader">SCPI subsystem</see> <paramref name="modalityName">modality</paramref> <paramref name="subHeader">element</paramref> value.
  2623. ''' Applies readings to the <paramref name="element">existing element</paramref>
  2624. ''' </summary>
  2625. ''' <param name="element">Specifies the existing element where the instrument readings are applied.</param>
  2626. ''' <param name="modalityName">Specifies the modality name.</param>
  2627. ''' <param name="subHeader">Specifies the command sub header for a command string in the form ':{0}:{1}:{2}?' where
  2628. ''' the first item is the <see cref="SyntaxHeader">SCPI subsystem syntax header</see>,
  2629. ''' the second item is the <paramref name="modalityName">modality name</paramref> and
  2630. ''' the third item is a <paramref name="command">command</paramref>
  2631. ''' </param>
  2632. ''' <param name="access">The desired <see cref="ResourceAccessLevels">access level</see> to the instrument.</param>
  2633. ''' <returns></returns>
  2634. ''' <remarks></remarks>
  2635. Public Function Getter(ByVal modalityName As String, ByVal subHeader As String,
  2636. ByVal element As IScpiString,
  2637. ByVal access As ResourceAccessLevels) As IScpiString
  2638. element.Value = Me.Getter(element, modalityName, subHeader, element.Value, access)
  2639. element.ActualValue = element.Value
  2640. Return element
  2641. End Function
  2642. #End If
  2643. #End Region