VisionBox .NET Library  1.7.10.0 (2024-04-16)
Rs422_Example.vb

Visual Basic example for using the RS422 device

1 
2 Public Class Rs422_Example
3 
4  Public Shared Sub RsS422()
5  Console.Clear()
6  'acquire a new factory
7  Dim pVIBSystem As VIB_NET.VIBSystem = New VIB_NET.VIBSystem()
8 
9  If (pVIBSystem IsNot Nothing) Then
10  ' Open Rs422 device 0
11  Try
12  Dim pRs422 As VIB_NET.Rs422 = DirectCast(pVIBSystem.OpenDevice(VIB_NET.eDEVICE_TYPE.RS422, 0), VIB_NET.Rs422)
13  If (pRs422 IsNot Nothing) Then
14  Try
15  ' Get type of Rs422
16  Console.WriteLine(pRs422.GetType().ToString())
17 
18  ' Get number of inputs
19  Console.WriteLine("Number of inputs: " + pRs422.NumberOfInputs.ToString())
20 
21  ' Get number of outputs
22  Console.WriteLine("Number of outputs: " + pRs422.NumberOfOutputs.ToString())
23 
24  ' Get state of all inputs
25  Console.WriteLine("Input state: " + pRs422.Input.ToString())
26 
27  ' Get state of input 0
28  Console.WriteLine("State of bit 0: " + pRs422.GetBit(0).ToString())
29 
30  ' Set output 1 and 2 simultaneously
31  pRs422.Output = 6
32  ' Set output 0
33  pRs422.SetBit(0, True)
34 
35  ' Turn off all outputs
36  pRs422.Output = 0
37  Catch e As System.Exception
38  Console.WriteLine(e.Message)
39  Finally
40  ' Close the device
41  pVIBSystem.CloseDevice(pRs422)
42  pRs422 = Nothing
43  End Try
44  End If
45  Catch e As System.Exception
46  Console.WriteLine(e.Message)
47  Finally
48  'release factory
49  pVIBSystem = Nothing
50  End Try
51  End If
52  Console.WriteLine(vbNewLine + "Press enter to proceed...")
53  Console.ReadLine()
54  End Sub
55 End Class