Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Inheriting a GPIB session - Error in MyBase.New(resourceName) with NI-VISA 3.4

Hello David,

From your last post, I believe there are three different issues you're asking about:

1) ResourceManager.FindResources() returns a null rather than an empty array when there are no resources available.

2) Using CEC GPIB under visa, SendInterfaceClear causes a timeout if no resources are present.

3) The CEC GPIB and NI-488.2 drivers can not coexist.

I saw a post from a while back about the second issue, but I couldn't find any references on the forum to the first one. Since I'm currently the lead developer for the VISA .NET library, though, I'll put my two cents in on it. I can understand your point about preferring an empty array to a null value for the return type of this method. I think that what makes a better return value in this case depends somewhat on what you intend to do with the value once it is returned. If you want to check and see if you have any resources, i think (resources != null) is a little more obvious than (resources.Length != 0). It is also a standard practice across a lot of the .NET Framework to return a null reference when there are no values to return. Also, now that it's released and been in deployment for some time, changing the returned value would introduce a breaking change in the API's behavior. Customers currently checking for null would now have to change their code to check for an empty string array instead. We try very hard not to introduce breaking changes in our API's across version, unless it is to fix incorrect behavior.

I can't really speak to the second and third items, as they are issues with the CEC driver, which I know very little about. In fact, I do not believe that CEC GPIB is officially supported under NI-VISA yet. I would suggest posting these questions to the Instrument Control forum, where the GPIB experts are more likely to see it and be able to respond. Also, I have asked a representative from the GPIB team to respond to your questions about interoperability between NI-488.2 and CEC GPIB.

Best Regards,
Glenn Burnside
0 Kudos
Message 11 of 15
(1,835 Views)

I'm not sure exactly what you mean by "Another thing that troubled me is how to clear the interface and teh device for bringing the system to a predictable state." Are you looking for the commands to send to the device, like "*RST" to reset the device's state and "*CLS" to clear its status bytes, or are you looking for something lower level on the gpib bus? You might want to post that question on the Instrument Control forum with a little more detail about what you're after.

Glenn

0 Kudos
Message 12 of 15
(1,831 Views)

David,

On 2 and 3 that Glenn mentions above, you'll need to contact CEC support.  I thought they did officially support NI-VISA, but they may or may not be aware of your SendInterfaceClear() issue.  With respect to coexistence with NI-488.2, I do know that the CEC driver does have an issue with this at the moment.  It is not recommended to install both NI-488.2 and the CEC GPIB driver on the same system.

Thanks,
Scott B.
GPIB Software

0 Kudos
Message 13 of 15
(1,828 Views)
Scott,

Thank you for you reply.

I did not check if the SendInterfaceClear is only an issues with the CEC driver.

One clearing devices, could you please direct me to where I can find information on how to properly do that using the VISA.NET driver.

This is the code I am using at this time.

Public Enum GpibCommandCode
  None = 0 ' added to conform to FxCop
  GoToLocal = &H1 ' GTL
  SelectiveDeviceClear = &H4 ' SDC
  GroupExecuteTrigger = &H8  ' GET
  LocalLockout = &H11 ' LLO
  DeviceClear = &H14 ' DCL
  SerialPollEnable = &H18  ' SPE
  SerialPollDisable = &H19 ' SPD
  ListenAddressGroup = &H20 ' LAG
  TalkAddressGroup = &H40 ' TAG
  SecondaryCommandGroup = &H60 ' SCG
  Unlisten = &H3F ' UNL
  Untalk = &H5F ' UNT
End Enum

  ''' <summary>Returns all instruments to some default state.</summary>
  ''' -----------------------------------------------------------------------------
  Public Sub DevicesClear()

    Dim commands(4) As Byte
    Dim gpibCommand As GpibCommandCode
    gpibCommand = GpibCommandCode.Untalk
    commands(0) = Convert.ToByte(gpibCommand)
    gpibCommand = GpibCommandCode.Unlisten
    commands(1) = Convert.ToByte(gpibCommand)
    gpibCommand = GpibCommandCode.DeviceClear
    commands(2) = Convert.ToByte(gpibCommand)
    gpibCommand = GpibCommandCode.Untalk
    commands(3) = Convert.ToByte(gpibCommand)
    gpibCommand = GpibCommandCode.Unlisten
    commands(4) = Convert.ToByte(gpibCommand)
    MyBase.SendCommand(commands)

End Sub

  Public Sub SelectiveDeviceClear(ByVal gpibAddress As Int32)

    Dim commands(5) As Byte
    Dim gpibCommand As GpibCommandCode
    gpibCommand = GpibCommandCode.Untalk
    commands(0) = Convert.ToByte(gpibCommand)
    gpibCommand = GpibCommandCode.Unlisten
    commands(1) = Convert.ToByte(gpibCommand)
    gpibCommand = GpibCommandCode.ListenAddressGroup
    commands(2) = Convert.ToByte(gpibCommand) Or Convert.ToByte(gpibAddress)
    gpibCommand = GpibCommandCode.SelectiveDeviceClear
    commands(3) = Convert.ToByte(gpibCommand)
    gpibCommand = GpibCommandCode.Untalk
    commands(4) = Convert.ToByte(gpibCommand)
    gpibCommand = GpibCommandCode.Unlisten
    commands(5) = Convert.ToByte(gpibCommand)
    MyBase.SendCommand(commands)

  End Sub


David



0 Kudos
Message 14 of 15
(1,822 Views)
Glenn,

Indeed I can see the predicament.  

On the philosophical level I respectfully disagree. 

While a null list may seem easier to check at first site, this is hardly the case.  An empty object  is way more graceful to handle than a non-existing one.  For example, you can iterate through an empty list but not through a non-existing one.

Also, I do not recall seeing FX returning null lists - I think it is now goes against programming rules.

Thank you for passing my questions about GPIB to the group as you could see I already received some reply and am following up.

Also, kudos for the great support.  NI is a shining light in programming support and I'll make a point of making this point during my presentation at the LXI Consortium meeting today.

David



0 Kudos
Message 15 of 15
(1,821 Views)