Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Controling 4-Channel relay NI 9481 with VB.Net

Hi to all,

Just recieved a NI-9481 module this morning. I installed the drivers and software and tried to play with it. Unfortunately there seems to be a problem when starting Vistual Studio 9, and I am not getting the normal Measurement Studio Daq wizard. I'm looking into that (it seems I'm not the only one around by looking at the forum). I will probably need to re-install measurement studio 8.1 at some point. Anyways, I had a go anyways. After going through all the examples which come on the CD I finally got one that made my relay work (the example called WriteDigPort, under NI-DAQ\Examples\DotNET3.5\Digital\Generate Values\WriteDigPort\vb). I seriously doubt this is the best way to make my module work and would be very interested in hearing how other people do it. Here is my code below (a simple form with a single check box). What is the "normal" way to program switching on or off this module?

Thanks for your help,

Charlie

 

   Public Class Form1
  Public device As Device
  Public digitalWriteTask As Task = New Task()
  Public line As String
  Public writer As DigitalSingleChannelWriter = New DigitalSingleChannelWriter(digitalWriteTask.Stream)

  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim str() As String = DaqSystem.Local.Devices
    device = DaqSystem.Local.LoadDevice(str(0))
    line = device.GetPhysicalChannels(PhysicalChannelTypes.DOLine, PhysicalChannelAccess.External)(0)
    digitalWriteTask.DOChannels.CreateChannel(line, "port0", ChannelLineGrouping.OneChannelForAllLines)
  End Sub

  Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
    If CheckBox1.Checked Then
      writer.WriteSingleSampleSingleLine(True, True)
    Else
      writer.WriteSingleSampleSingleLine(True, False)
    End If
  End Sub
End Class

 

0 Kudos
Message 1 of 2
(4,282 Views)

Hey Charlie,

 

Since the card is controlled by a digital output, the best example of how to program it is going to be a digital output example.  I'm curious why you think that's not an efficient way of programming since this is the only way to switch the card.  

 

To sum it up, I think you're on the right track with the digital output example.  Let me know if it's giving you any problems!

Sincerely,

Chris G in AE
0 Kudos
Message 2 of 2
(4,260 Views)