Okay I've managed to figure out its something to do with this subroutine....
I've also shown the DIM's and other headers, as I have a funny feeling I may not of Dim'd correctly as its to do with something reporting as null exception
Any ideas?
Thanks in advance for anyone who can tell me whats wrong!
I've also shown the DIM's and other headers, as I have a funny feeling I may not of Dim'd correctly as its to do with something reporting as null exception
Any ideas?
Thanks in advance for anyone who can tell me whats wrong!
VB.NET:
Imports System.IO.Ports
Imports System.Text
Imports System
Public Class Form1
Dim comPort As IO.Ports.SerialPort
Dim returnStr As String = ""
Dim Incoming As String = ""
Dim n As Integer
Dim sn As Integer
Dim cpnames As System.Object
Dim uport As String = ""
Dim uportstate As Integer
Dim Phnum As String = ""
Dim ex As String = ""
Dim sp As String = ""
Sub GetSerialPortNames()
' Show all available COM ports.
uport = ListBox1.Text
ListBox1.Items.Clear()
cpnames = My.Computer.Ports.SerialPortNames
' MsgBox(uport)
uportstate = 1
For Each sp As String In cpnames
ListBox1.Items.Add(sp)
'TextBox1.Text &= sp & "--- " & uport & vbCrLf
If sp = uport Then
ListBox1.SelectedIndex = ListBox1.Items.Count - 1
uportstate = 0
End If
If sn <> 1 Then
Try
comPort = My.Computer.Ports.OpenSerialPort(sp, 240)
sn = 1
TextBox1.Text &= vbCrLf & "** OPENING " & sp & " ***" & vbCrLf
Catch ex As Exception
'MsgBox(ex.ToString & " PORT FAIL")
TextBox1.Text &= vbCrLf & "** CANNOT OPEN " & sp & " ***" & vbCrLf
End Try
TextBox1.SelectionStart = TextBox1.Text.Length
TextBox1.ScrollToCaret()
End If
Next
If uportstate = 1 Then
comPort.ReadTimeout = 500
TextBox1.Text &= vbCrLf & "** CLOSING PORT NO LONGER AVAIL ***" & vbCrLf
TextBox1.SelectionStart = TextBox1.Text.Length
TextBox1.ScrollToCaret()
Try
ListBox1.SelectedIndex = 0
Catch
'
End Try
Try
comPort.Close()
Catch
'
End Try
End If
End Sub