You did not initialize the
Firmata
variable. It seems like your
session
variable is already of a type implementing
IFirmataProtocol
interface anyway. Try to use it instead, and only initialize it once the connection has been opened:
Dim connection As SerialConnection
Dim session As ArduinoSession
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
connection = New SerialConnection("COM6", SerialBaudRate.Bps_9600)
If Not connection Is Nothing Then
connection.Open()
session = New ArduinoSession(connection, 2500)
If Not session Is Nothing Then
session.SetDigitalPinMode(13, PinMode.DigitalOutput)
End If
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If Not session Is Nothing Then
session.SetDigitalPin(13, True)
End If
End Sub
This is only a quick-fix; judging by the documentation at
GitHub - SolidSoils/Arduino: C# .NET - Arduino library supporting simultaneous serial ASCII, Firmata and I2C communication[
^], you seem to have skipped basic sanity checks and disposal measures.