Launch Visual Studio, select [New]-[Project] from [File] menu.
From the [Templates] of [Create a new project] dialog box, select [Windows Forms App] of [Visual Basic], click the [Next] button.
From the [Configure your new project] dialog box, specify the project name and save location, and click the [Next] button.
From the [Additional information] dialog box, select [.NET 8.0 (Long Term Support)] and click the [Create] button to create the project.
* The above is for Microsoft Visual Studio Professional 2022 (64-bit). Item names and commands may differ depending on the version.
When performing serial communication with Visual Basic .NET, there is a method of using the SerialPort class.
Reference : [SerialPort class] (Since this is an external link, the link may change without notice)
https://learn.microsoft.com/en-us/dotnet/api/system.io.ports.serialport
The Visual Basic .NET default settings do not include the System.IO.Ports class of the .NET8 in your project.
For this reason, we explicitly include the external class.
Select [Project] from the Visual Studio menu bar, and select [Manage NuGet Packages...] from the pull-down menu.
From the [NuGet Packages Manager], select the Browse tab and enter "System.IO.Ports" in the browse box.
As a result of the search, select "System.IO.Ports: Provides classes for controlling serial ports." provided
by Microsoft displayed at the top and install it.
In the tree view in the [Solution Explorer] window of Visual Studio, you can check whether there are installed modules in [Dependencies/Packages].
* The above is for Microsoft Visual Studio Professional 2022 (64-bit). Item names and commands may differ depending on the version.
To use the SerialPort class in Visual Basic .NET, the System.IO.Ports namespace must be available in your project.
Use the Imports statement to declare the use of the System.IO.Ports package.
It also shows an example of creating an instance of System.IO.Ports.SerialPort
using the Dim customer As New application() declaration.
In addition, the Dim WithEvents customer As application()
declaration is used together with System.IO.Ports.SerialPort() event handling.
For details, refer to the source code of the sample program.
Program example :
Imports System.IO.Ports 'Namespace for System.IO.Ports
Public Class Form1
Dim WithEvents SerialPort1 As New System.IO.Ports.SerialPort() 'SerialPort class instance creation and event handling declaration
....
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
....
SerialPort1.BaudRate = 9600 'Setting Baudrate.
SerialPort1.DataBits = 8 'Setting Databits.
SerialPort1.StopBits = StopBits.One 'Setting Stopbits.
SerialPort1.Parity = Parity.None 'Setting Paritybits.
....
End Sub
....
End Class
SerialPort1 declared with Dim WithEvents serialPort1 As New System.IO.Ports.SerialPort() can handle events of the SerialPort class with the following description.
Add the necessary event handling program to SerialPort1_DataReceived().
For details, refer to the source code of the sample program.
Program example :
Imports System.IO.Ports 'Namespace for System.IO.Ports
Public Class Form1
Dim WithEvents SerialPort1 As New System.IO.Ports.SerialPort() 'SerialPort class instance creation and event handling declaration
'Member to start when received
Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
....
End Sub
End Class
In general, an EXE application built with "Any CPU" specified in the [Active solution platform] item in the Visual Studio settings [Configuration Manager] window can be executed in both 64-bit environment and 32-bit OS environment.
However, when developing an EXE application that supports the .NET8 framework, it is necessary to be aware of the target OS.
Please refer ".NET execution environment for .NET8 or later" to know more details.