Download Serial Terminal Software in vb2010

Hello everyone, I hope you all are doing great and having fun. In today's tutorial, I am going to share a new software which I have named Serial Terminal. I have designed this Serial terminal in vb2010. You can download this software from below button. I have already posted a complete tutorial on How to use Serial Port in Visual Studio 2010 in which I have explained how to send and receive data via serial port. It was quite a basic software, which just transmit and receive data from a serial port but today I am gonna provide you a complete serial terminal, which will not only transmit and receive data but will also display that data in different formats.

As shown in the below figure, first of all you need to select the COM Port from which you want to receive the data and then select the Baud Rate. Hit Connect and you are now ready to communicate with the selected com port.Download link for this software is given below:

Download Software

Features added in Serial Terminal

Different features are added in the serial terminal to make it more user friendly. First, let's talk about the Transmitting portion. If you guys have noticed, in the previous version of serial terminal. there was no option for Carriage Return and Line Feed but now these options are added.

  • If you simply want to send data without Carriage Return or Line Feed then uncheck both of them.
  • If you check the Carriage return, then it will be sent after the data.
  • If you check Line feed, then it will be sent after the data.
  • If both are checked, then both will be sent after the data.
  • Here's its final look:
  • Now, coming to the receiving side, the data received will be shown in different formats.
  • In the above figure, I have shown a random data.
  • Now in order to check this data in hex format, simple click on hex tab and the data will be presented in Hex format, as shown in below figure:

  • Similarly you can also convert your data in Decimal Format by clicking the Dec tab, as shown in below figure:

  • In the below figure, the data is displayed in the Binary format.

Showing data in different formats helps in designing the project because understanding of coming data is quite necessary. Give this software a try and let me know your suggestions for the improvement. That was all for today, will see you guys in next tutorial. Have fun !!! :)

How to add a Delay in Visual Studio 2010

Hello friends, hope you all are enjoying good health and having good time. Today's tutorial is not too big and is simple about how to add a delay in visual studio 2010. Before starting this tutorial, let me first tell you that I got an excellent feedback about the last tutorial on How To Use Proteus ISIS & ARES & also got few queries and suggestions. One of them was to post a similar tutorial on the Eagle software as well which I will hopefully start in the coming week.

Today's post is a very small trick but yet very effective one. In a recent project of mine, it helped me a lot and yet its quite a small thing but it took me around half an hour to find it online and that's the reason I decided to share it with you guys. I have to design a software in which I was using a database in visual studio 2010 and in that project I have to add some delay in my readings addition in database so I was like :O how to add delay in visual studio 2010. I searched online and after quite a lot of time I finally able to get it, which I am sharing now in this post. Btw if you wanna learn about database then read How to create a database in visual studio 2010. After the creation of any software in visual studio there's a need of creating its executable file so  that we can use the software standalone and just simply install our software on any computer so I think you should also read How to create exe file in Visual Studio 2010. Anyways coming back to adding delay in visual studio 2010, let's first discuss delay in programming language. :)

What is a delay?

The engineers who had worked on Microcontrollers like Arduino or PIC Microcontroller or 8051 Microcontroller, then they know that what is a delay.
  • A delay in programming is a statement which adds a pause in your code.
For example, in some project you want to turn on two lights one after another with a delay of like 5 sec so now what will you do. You will first turn the first light on and then add a delay of 5 sec and then turn the second light on. That delay just let your code wait for 5 sec and then execute the next line. So, now we have an idea what is a delay so lets have a look at how can we add this delay in visual studio 2010.

Add a Delay in Visual Studio 2010

In Microsoft Visual Studio, the command used for adding the delay is:
System.Threading.Thread.Sleep(1000)
This command will generate a delay of 1sec. You can change this value in order to change the time of delay. i.e.
  • 500 for 0.5 sec delay.
  • 2000 for 2 sec delay.
  • 5000 for 5 sec delay.
You need to calculate this value for your required delay and add it here. Note:
  • You should take much care in using this delay because this delay simply makes your software to sleep and thus while the delay is in process, your software won't do any other task.
As I told earlier, its quite a small tutorial, in fact not a tutorial just a quick trick of adding a delay in visual studio 2010. If you are interested in Visual studio projects then must read How to send Emails in Microsoft Visual Studio 2010. Its quite exciting. :)

Sending Email in Microsoft Visual Studio 2010

No. Sending Email in Visual Studio 2010
Give Your Suggestions !!!
1. Part 1
2. Part 2

Hello friends, today's tutorial is about adding functionality in Microsoft Visual Studio 2010 basic email form. In the previous part of this tutorial How to Send Email in Microsoft Visual Studio 2010, we have seen a basic email form which just sends email to constant email address which is specified in the coding.

Today we will make this email form a bit flexible and will be able to send the emails to any email id we want. If you have read the previous part of this tutorial, then this article will be nothing for you, you will got it just like a piece of cake instantly.

So, I suppose that you have read the previous tutorial and you have the knowledge of smtp etc so I am not gonna explain it further, so i suggest again to read it first if you have any doubt in configuration part, lets come to this part.

Steps to follow:

  • First of all create a new project in your Microsoft Visual Studio 2010 and if you have already created it in the previous part then don't need to create it again, just open that project.
  • Now in your main form add one button, three labels, two text boxes and one rich text box.
  • Change the Name and texts of all these controls from their properties as i specified below and be careful in doing this part and its better if you simple copy paste them.
    • Change Label1 text to Send Email To.
    • Change Label2 text to Subject.
    • Change Label3 text to Mesage.
    • Change TextBox1 name to txtSend and place it after Label1.
    • Change TextBox2 name to txtSubject and place it after Label2.
    • Change RichTextBox name to rtbMessage and place it under the Label3.
    • Now at the end change the Button1 text to Send Email and name to SendEmail.
  • Place them as shown in the image below or you can also change their positions as well. Anyways your final software will look like this :
  • Now the last part is adding code so go into your code editor and remove all the previous code and place this code in it.
Imports System.Net.Mail Public Class Form1 Private Sub SendEmail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SendEmail.Click Dim Mail As New MailMessage Mail.Subject = txtSubject.Text Mail.To.Add(txtSend.Text) Mail.From = New MailAddress("email@gmail.com") Mail.Body = rtbMessage.Text Dim smtp As New SmtpClient("smtp.gmail.com") smtp.EnableSsl = True smtp.Credentials = New System.Net.NetworkCredential("email@gmail.com", "password") smtp.Port = "587" smtp.Send(Mail) End Sub End Class
  • Change email@gmail.com with your email address and password with your password.
  • Now if you compare it with the code in the previous part, you will see there's just a slightest change.
  • In the previous software, we were adding the subject and email id to which we have to send email and the email body in the code section but in this software we have created text boxes and in the code we are getting these things from those text boxes, quite a simple thing.

Things to Notice:

  • One thing you have observed that this software lack the functionality of login so its not kind of a messenger on which we just login with any id and send the email to your recipient.
  •  The reason is we haven't yet covered the login form. In my next article on visual studio, i will cover the login form.
  • By the way you can add a simple login form by yourself, just add two text boxes and in the code, get data from them where we are using our email id and password.
Note:
  • This sotware along with code has been sent to all the subscribed members already.
  • In order to get the complete code and software, kindly Subscribe to our Newsletter and post your subscribed email address in the comments and I will send them to you.

I will recommend you guys to must read these two tutorial on Microsoft Visual Studio as well:

That's all for today guys, if someone having any kind of trouble in any part, ask in comments and help me to help you ..... Take care ..... ALLAH HAFIZ :))

How to Send Email in Microsoft Visual Studio 2010

No. Sending Email in Visual Studio 2010
Give Your Suggestions !!!
1. Part 1
2. Part 2

Hello friends, first of all I am really bad in designing stuff. Although I have tried to design the top image for this post but I know its not much cool well try to bear it .... :))

After the Microsoft Visual Studio 2010 - COM Port and Creating a Database in Microsoft Visual Studio 2010 tutorial, here's my next tutorial on VB.net. As the name suggests, this tutorial is about sending an Email through Visual Studio. Again I will use Microsoft Visual Studio 2010 and the language will be Visual Basic for this tutorial.

Usually Sending an Email through software seems quite a difficult task but in actual its really a very easy task. So at the end of this short and quick tutorial, you will be able to develop a software which will send email on your click. I have divided this tutorial into two sections. Today we will just create a simple app which will send emails on just one click and later on we will add few features in it and make it able to send emails through multiple accounts with log in capability. Two parts of this tutorial are as follows:

Steps to Follow

  • First of all create a new project in Microsoft Visual Studio as shown in figure below:
 
  • Now select Visual Basic from the Installed Templates and then Windows Form Applications.
  • Give your project some name and then click on OK.
  •  Now it will redirect you to your form. Add one button in your form and rename it to Send Email and change the Name of the button to SendEmail.
  • Now move into the code section of your application and remove everything and paste the below code into it.
Imports System.Net.Mail Public Class Form1 Private Sub SendEmail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SendEmail.Click Dim Mail As New MailMessage Mail.Subject = "First Email" Mail.To.Add("Email1") Mail.From = New MailAddress("Email2") Mail.Body = "First Email Through VB.net --- www.TheEngineeringProjects.com" Dim smtp As New SmtpClient("smtp.gmail.com") smtp.EnableSsl = True smtp.Credentials = New System.Net.NetworkCredential("Email2", "Password") smtp.Port = "587" smtp.Send(Mail) End Sub End Class
  • Now make few changes in it.
  • Email1 is the email whom you wanna send the email.
  • Email2 is your email from which the mail will be sent.
  • Password is the password of your email i.e. email2.
Note:
  • SmtpClient and SmtpPort are different for different email providers.The above mentioned are only for Gmail.If you search a little you can easily find these for Hotmail and yahoo etc.
  • If someone needs this software along with complete code, kindly subscribe to our newsletter and post your email in the comments.

Updating Database Table with Programming in VB 2010

Hello friends, I hope you all are fine and having fun. In today's tutorial, we will have a look at updating database table with Programming in VB 2010. In the previous posts of this tutorial, we have seen How to Create a database in VB 2010 and then we have added button control in VB Database in it, which was quite an easy job. But usually in such applications, its necessary that the application update its database automatically. Like in one of my project, I have designed a software for hotel management in which the data is coming from all the rooms wirelessly to the master room where the software is installed. It was quite a big project but the thing, for which I have mentioned this project, is the software installed in the master room was updating its database itself i.e. if data of room 1 changed then software automatically update the info of that room in its database.

So, for students and also for freelancers its essential that they must have full command over database, and in order to understand today's post its also essential that you must read the previous two posts of this tutorial.
  • In the last post of this tutorial, we have designed this application which is shown in the below figure:
  • In this post I am not gonna use images as its really not necessary, because we don't make any change in the layout of application, the whole programming will be at the back end.

Code for Updating Database internally in VB 2010

  • Here's the simple code which you need to place in your application, I have explained each line with comments but still if anyone got any trouble please ask in comments, I am always here to help you out.
  • For this code, things to be noted are:
    • database name is database1,  
    • Var1 and Var2 are two variables,  
    • Contact Form is the name of our table which we have saved in our database.
    • FullName and LastName are the columns name of our table.
Dim Var1 As database1DataSet.ContactFormRow 'Defining a vaiable Dim Var2 As database1DataSet.ContactFormRow 'Defining a variable Var1 = database1DataSet.ContactForm.FindByID(2) 'Here, we are assigning our variable Var1 the location of row 2. Var2 = database1DataSet.ContactForm.FindByID(2) 'Here, we are assigning our variable Var2 the location of row 2. Var1.FullName = Var2.LastName 'Now as our variables are in row 2 so they can access any value in row 2. So in this line of code, I just assign the LastName to First Name. So, after execution of this command whatever present in Full Name of row 2 will be replaced by Last Name of row 2. Me.table5TableAdapter.Update(Me.database1DataSet.ContactForm) 'Now at the the end updated our database or in other words save the database.
Mostly data we receive is through serial port so in that case simple remove the Var2 with the variable in which you are receiving data from serial port. For the programming of serial port in visual basic 2010, check the below tutorial. That's all for today friends and finally this tutorial completed. If you guys have any question regarding any part kindly ask in comments and also subscribe to our newsletter to get the new updates and software.

Button Control in VB Database

Hello everyone, I hope you all are fine and having fun. In today's tutorial, we are gonna have a look at How to add Button Control in VB database 2010. I have posted the first part of this tutorial few days ago in which I have shown that How to Create a Database in Microsoft Visual basic 2010. If you have missed that part then you can't understand the today's lecture. Today we will continue with the same application which we created in the last part and will add few new features in it. Creating database is difficult but adding features in it is very easy job and its also a must requirement of the application because user wants an easy control of application. So in order to make the application user friendly its necessary to add few features in it. In the next post, I have discussed How to Update Database Table with Programming in VB 2010. I have divided this project or tutorial into few parts, as covering the whole database topic in one tutorial is not possible. If any of you have any problem in any part,ask in comments. So let's get started with Button Control in VB Database.
  • In the last part of this tutorial, we have created a database application shown in the below figure:
  • In today's lecture we will add few new features in the above application and at the end of today's lecture, the above application will looks like this.
  • You can see in the below figure that now we have Button Control in VB Database.

Step 1 : Add, Save & Remove Buttons

  • First of all open the application which we created in the previous part of this tutorial.
  • Now add three buttons on it as shown in the below figure :
  •  Now click the button 1 and change its name from properties to Add, button 2 to Save and button 3 to Remove as shown in figure below.
  •  We have added buttons and also changed their names according to our requirement, now we are gonna add functionality in these buttons i.e. what function they perform when someone click them.
  • Double click Add button and put this code in its function.
 Try Me.Contact_FormBindingSource.AddNew() Catch ex As Exception End Try
  • Now double click Save button and add this code in its function.
  Try Me.ValidateChildren() Me.Contact_FormBindingSource.EndEdit() Me.TableAdapterManager.UpdateAll(Me.ContactsDataSet) Catch ex As Exception End Try
  • Now double click the Remove button and add the following code in its function.
Try Me.Contact_FormBindingSource.RemoveCurrent() Catch ex As Exception End Try
  • Now run your application and if everything's fine then when you click Add button, a new line will appear in the database where you can enter the next contact. After adding the contact, when you click on the Save button software will automatically save the contact in database and if you click the Remove button then the selected entry in database will be deleted.

Step 2 : Next & Previous Buttons

  • Now add two more buttons from toolbar, just under these three buttons as shown in the figure below:
 
  • Change their names to Previous and Next as shown in image below:
  • Now double click the Previous button and add the below code in it.
Contact_FormBindingSource.MovePrevious()
  • After that double click the Next button and add the below code in its function.
Contact_FormBindingSource.MoveNext()
  • Now run your application and when you click the Next button the selection in database will move downward i.e towards the next entry and when you press previous it will move upward i.e towards the previous entry.

Step 3 : Move To Top & Move To End Buttons

  • Now again add two more buttons as shown in the figure below:
  •  Remove Button1 to Move To End and Button2 to Move To Top as shown in below figure:
  •  Now double click on Move To End Button and insert the below code in it.
Contact_FormBindingSource.MoveLast()
  • After that double click on Move To Top button and add the below code in its function.
Contact_FormBindingSource.MoveFirst()
  • Now run your application, and check the working of these two buttons. When you click Move To Top button the database will rolled up and you will reached the first line and vice versa for second button.
Okay friends that's all about Button control in VB Database, and I really got tired. Level of today's post is intermediate but its really important as in the next chapter of this tutorial we are gonna move into pro level so if you don't practice it you wont get the next chapter. Okay I gotta go. Stay Blessed. Take care. Note :
  •  This software along with code has already been emailed to all the subscribed members. If someone didn't received it then post your email in the comments and i will send it to you.
  • if someone wants this software along with the code then subscribe to our email newsletter and it will be automatically emailed to you.

Create Database in Microsoft Visual Studio

Hello friends, hope you all are enjoying good health. Today, I am going to share How to create a Database in Microsoft Visual Studio 2010. Around two to three months ago, I have shared a topic on Microsoft Visual Basic 2010 - Com Port  in which I have explained completely how to make the serial communication in Microsoft Visual studio using visual basic language. Today I am going to share another complete tutorial on how to create a database in Microsoft visual studio. Its a most common project in computer science which usually students do as a semester project, so I thought of sharing it here. I have divided this project or tutorial into three parts, today we will just create a simple database in which we can add out objects easily and later on we will add few functionality in it. In this tutorial we are going to create a database driven application. In this tutorial we are going to create a simple contact form database. Simply follow these steps. I have also posted How to add Button Control in VB Database  and How to Update Database Table with Programming in VB 2010. You must read them as well if you are planning to work on VB database. So, let's get started with creating a Database in Microsoft Visual Studio 2010.

Creating a Database in Microsoft Visual Studio 2010

  • I have tried my best to make this creation of database in Microsoft Visual Studio as simple as possible, that's why I have added screenshot of each step with commenting but still if you guys have any problem at any step ask in comments. At the end of this tutorial, we will create a database driven application as shown in the figure below:

Step 1 : Creating New Project

  • First of all open the Microsoft Visual Studio 2010 and click on the New Project as shown in figure below:
  •  After clicking it, the below screen will show. Now, choose the language and the project type and then give this project a name and click OK. In our project I am using Visual Basic language and project type is Windows Form Application.
  •  It will create a new project for you, where we are gonna add the database.

Step 2 : Creating a Database

  • Now we are gonna create a database in our project.
  • For this first go to the Solution Explorer in your project.
  • Now right click on your project name and then click on Add and finally click on New Item.
Note :
  • If you can't find it click on View in the above menu tab and then click on Solution Explorer.
  • If you can't find the Solution Explorer then click on View in the above menu tab and then click on Solution Explorer.
  • After clicking on New Item, a list of items will open up as shown in below figure. Now from these select the Service Based Database. Give it a name like I gave it Contacts.mdf and then click on Add.
  •  That's now gonna open up a data source wizard as shown in below figure. Just cancel it for now as we don't have anything right now to add in our database.
  •  Now our database has been created which you can also see in the solution explorer but rite now its empty, so now in the next step we are gonna add a table in our database.

Step 3 : Creating a Table

  • Now, double click on the database which we just created in the step 2 and named it Contacts.mdf. (You will find it in Solution Explorer)
  • Double clicking the database will open up Server Explorer.
  • Now in the Server Explorer, right click on the Tables and then Add New Table.
  • Now, it will open a Table where we will add the Columns Name of our Table.
  • I have given the first Column as ColumnID and Data Type is int and unmark the Allow Nulls Option.
  • Now click on the Primary Key as shown in below figure.
  • After that go in the properties of table and click on Identity Specification to expand it.
  • Now change the option from No to Yes.
  • I have done this to make it auto incremented, now as you add the data in it the ContactID will be incremented on its own showning you the total number of data present in the Table.
  •  Now quickly fill the other columns name as shown in below figure, you can choose any data type you want but I have choosen varchar(50).
  • Now click on Save button to save the table and it will ask for the table name.
  • Give the table name and click Ok.
  • Now close this tab.
  • Now our table has been created, in the next step we are gonna add some data in the table.

Step 4 : Adding Data in the Table

  • In order to add data in the table we just created, go to Server Explorer and Expand the Table Section.
  • In the Table Section, you will get your table which we created in the Step3.
  • Right Click on the Table which we named Contact Form and then Click on Show Table Data.
  •  It will open up the Contact Form data table. Now fill the few lines as you can see I have added few info in it and then click Save.
  • It will ask for the name, remain the name as it is and click Save.
  •  Uptill now, we have created our database and then we created a table and added some data in it.
  • Now we are gonna attach a data source with our database in the next step.

Step 5 : Attach a Data Source

  • Now we need to attach a data source with our database.
  • For this first click on Data and then Add New Data Source as shown in below figure.
  • Now it will open the data source configuration wizard. Select the database and click on Next.
  •  Again click on the Next as shown in below figure.
  •  Now we need to attach this data source with the database which we created in the Step 2, so select the Contacts.mdf database and click Next.
  •  Now it will ask for the components you want to add in your data source.
  • Click on the Tables to expand and the select Contact Form, this is the table which we created in step 3.
  • Now click Finish.
  •  Now we have created our data source which contains the table. In the next step we are gonna add this database on our form so that we can use it easily.

Step 6 : Adding Database on the Form

  • Now go to the Data Source, if you cant find it then open it from Data tab in the top menu.
  • Now click on the Contact Form (which is our table) and drag it to the Form Board as shown in the below figure.
  • Now re size it using the mouse according to your form.
  • Next click on the Contact Form in the Data Source and select Details, it will give us detail view of our database.
  •  Now again click the Contact Form and drag it in the Form Board and it will show like detail view as you can see in the figure below.
  •  We have add the both views on our board. Now run it and your project will open up.
  • Now you can add or delete or edit any column and then save it.
  •  So the final form of our project is something like that.
  • You can see the above bar where are options to add, delete or move forward, backward etc.
  • In the next tutorial we will add some functionality in it like adding new column with button and save etc.
  • Hope you guys enjoyed it. If someone needs this database in Microsoft Visual studio along with the exe file of this project then Subscribe Us via Email and post your email in the comments and we will email it to you.
That's all for today, and I hope you guys are not familiar with How to create Database in microsoft visual studio 2010, will meet you in the next tutorial, till then take care ALLAH HAFIZ. :))

Create Setup File in Visual Studio 2010

Hello friends, I hope you all are healthy and having fun. Today I am posting a simple tutorial in which I will show you How to Create Setup File in Visual Studio 2010. Actually I got a request from one of our members to post this tutorial, he was having some problems in it, so i thought to share it. In my previous tutorial How to use Serial Port in VB 2010, we have designed a simple tool, now what if I want to create an exe file so that I could easily share my tool with my friends, without giving them the access to my code. So, in today's tutorial, we are gonna have a look at How to create exe or setup file in Visual Studio 2010. No one can get your code from the exe file so its like your code is safe but anyone can use your software. These days I am planning on designing such small free tools, which I think will help our readers and we can add our logo for free publicity. In simple words, there are numerous uses of giving professional look to your software by creating its exe or setup file. So, let's get started with How to Create Setup File in Visual Studio 2010:

Why you Need to Create it ?

  • Suppose you have created your software on Visual Studio 2010 and now you want to use that software on any other computer.
  • So to do this, there's no need to copy whole code and create project in the second computer.
  • Instead just create executable (.exe) file of that software and install it on other computer.
  • You can also publish your software online on your blog etc.
Now follow these simple steps carefully in order to Create Setup File in Visual Studio 2010:

Create Setup File in Visual Studio 2010

  • Complete your software and test it to confirm that its ready.
  • Now click on the Project in your Top Menu Bar and at the bottom click on Properties.
  • CNC Gcode is actually the name of my software as shown in image below :
  •   After clicking on properties a new tab will open as shown in image below :
  •  These are actually the properties of our software, like you can change the icon and can also do many other things.
  • Right now we are not changing anything but if you want you can play with its properties.
  • Now click on the Publish button at the bottom and the below screen will appear.
  • Now click on the Publish Now button and it will create the .exe file of your software.
  • You can change the location of the file where it is gonna store in the properties.
So, in this way you can quite easily Create exe File or Setup File in Visual Studio 2010. If you got into any trouble then ask in comments and we will try our best to help you out. So, that was all for today, will see you guys in the next tutorial. Till then take care and have fun !!! :)

How to use Serial Port in VB 2010

Update: Few bugs were reported by some readers, which I have corrected and updated the code. Now, its fully tested and 100% working.

Hello friends, hope you all are enjoying the start of winter season. By the way, I really hate winter season and I just want to hibernate in this season . :) Well coming to our today's lecture, my today tutorial, serial port in VB 2010, is actually based on a request made by one of the member on my Facebook Page and as it is a really good topic so i thought to share it.

Today we will make a software on Microsoft Visual Basic 2010 in which we will send data through the serial port in VB 2010. In this software we will send the data and also receive it. Simply follow all the given steps carefully and you can easily interface the Serial Port in VB 2010, its a fully working project with code so don't do any mistake. Moreover check these two complete tutorials on Microsoft Visual Studio 2010 as well, these are quite fascinating.

First of all download the Microsoft Visual Basic 2010. The installer can be freely downloaded from Microsoft. After installing the software follow these simple steps. So ,let's get started with How to use Serial Port in VB 2010:

How to use Serial Port in VB 2010 ???

Step 1 : Creating a New Project
  • Open your installed Microsoft Visual Studio 2010 software. The first interface will be something like that :
  •  Now click on the New Project and select Windows Form Applications.
  • In the project name box, add name of your project as I have added Serial Port Interface.
  • Click OK and a new window will be opened as shown in below image which contains a blank Form1.
  • In this Form1 we are gonna add our controls buttons etc.
Step 2 : Changing Name of Form
  • Now click on the form1 and the properties panel will be open on the right side. Now, in the properties tab shown on the right side change its name to frmMain (for easier identification specially when adding more forms).
  • Also change the text of the form to something you like as Serial Terminal. This will be shown on the title bar of your application.
Step 3 : Adding Controls To The Project
  • Lets start to add some controls in our software like buttons,combo box and labels etc.
  • So from the Common Controls tab add two buttons, two combo boxes and two labels into your Form1 and  align them as shown below :
  • For Button 1, change the text to Connect and change the name to btnConnect.
  • For Button 2, change the text to Disconnect and change the name to btnDisconnect.
  • For Combo Box 1, change the name to cmbPort.
  • For Combo Box 2, change the name to cmbBaud.
  • For Label 1, change the text to Comm Port.
  • For Label 2, change the text to Baud Rate.
Note :
  • Keep the names and texts of same character as i wrote them.
  • They are case sensitive so be careful. I will recommend to just copy paste them.
  • If you make even a one letter mistake the code will not run.
  • btn and cmb are just to remind that they are button and combo box respectively. Its better to do neat programming.
Step 4 : Adding Serial Port & Boxes
  •  Now from Container tab, add two Group Boxes in the forum.
  • Change the name of Group Box 1 to Transmit Data.
  • Change the name of Group Box 2 to Received Data.
  • Now add a Text Box and a Button in the Transmit Data Group Box.
  • Change the name of the Button to Send and text to btnSend.
  • Change the name of the Text Box to txtTransmit.
  • Now add a Rich Text Box in the Received Data Box and change its text to rtbReceived.
  • Arrange all these components as shown in the below image :
  •  Lastly and i think its the most important part of this tutorial, add a Serial Port Block into your forum. It will appear at the bottom. Don't change any of its parameters just leave it as it is.
Step 5 : Coding Section
  • Now we come to the coding part of our project. If you double click on your forum, it will open a new window something like that :
  • This is the place where we add our code and in other words add functionality to our project, this window is called Code Editor.
  • If you double click on any button or box, its respective code will created in this region automatically.
  • Now what you need to do is copy the below code and paste it in your code editor window.
  • Just remove all the previous code in your Code Editor Window.
  • Here's the code for Serial Port in VB 2010:
    'Code Starts here ....
    'Import Systems which we are gonna use in our code
    Imports System
    Imports System.ComponentModel
    Imports System.Threading
    Imports System.IO.Ports

    'frmMain is the name of our form ....
    'Here starts our main form code .....
    Public Class frmMain
    Dim myPort As Array
    Delegate Sub SetTextCallback(ByVal [text] As String)

    'Page Load Code Starts Here....
    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    myPort = IO.Ports.SerialPort.GetPortNames()
    cmbBaud.Items.Add(9600)
    cmbBaud.Items.Add(19200)
    cmbBaud.Items.Add(38400)
    cmbBaud.Items.Add(57600)
    cmbBaud.Items.Add(115200)
    For i = 0 To UBound(myPort)
    cmbPort.Items.Add(myPort(i))
    Next
    cmbPort.Text = cmbPort.Items.Item(0)
    cmbBaud.Text = cmbBaud.Items.Item(0)
    btnDisconnect.Enabled = False
    End Sub
    'Page Load Code Ends Here ....

    'Connect Button Code Starts Here ....
    Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
    SerialPort1.PortName = cmbPort.Text
    SerialPort1.BaudRate = cmbBaud.Text
    SerialPort1.Parity = IO.Ports.Parity.None
    SerialPort1.StopBits = IO.Ports.StopBits.One
    SerialPort1.DataBits = 8
    SerialPort1.Open()
    btnConnect.Enabled = False
    btnDisconnect.Enabled = True
    End Sub
    'Connect Button Code Ends Here ....

    'Disconnect Button Code Starts Here ....
    Private Sub btnDisconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisconnect.Click
    SerialPort1.Close()
    btnConnect.Enabled = True
    btnDisconnect.Enabled = False
    End Sub
    'Disconnect Button Code Ends Here ....

    'Send Button Code Starts Here ....
    Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
    SerialPort1.Write(txtTransmit.Text)
    End Sub
    'Send Button Code Ends Here ....

    'Serial Port Receiving Code Starts Here ....
    Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
    ReceivedText(SerialPort1.ReadExisting())
    End Sub
    'Serial Port Receiving Code Ends Here ....

    'Serial Port Receiving Code(Invoke) Starts Here ....
    Private Sub ReceivedText(ByVal [text] As String)
    If Me.rtbReceived.InvokeRequired Then
    Dim x As New SetTextCallback(AddressOf ReceivedText)
    Me.Invoke(x, New Object() {(text)})
    Else
    Me.rtbReceived.Text &= [text]
    End If
    End Sub
    'Serial Port Receiving Code(Invoke) Ends Here ....

    'Com Port Change Warning Code Starts Here ....
    Private Sub cmbPort_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbPort.SelectedIndexChanged
    If SerialPort1.IsOpen = False Then
    SerialPort1.PortName = cmbPort.Text
    Else
    MsgBox("Valid only if port is Closed", vbCritical)
    End If
    End Sub
    'Com Port Change Warning Code Ends Here ....

    'Baud Rate Change Warning Code Starts Here ....
    Private Sub cmbBaud_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbBaud.SelectedIndexChanged
    If SerialPort1.IsOpen = False Then
    SerialPort1.BaudRate = cmbBaud.Text
    Else
    MsgBox("Valid only if port is Closed", vbCritical)
    End If
    End Sub
    'Baud Rate Change Warning Code Ends Here ....

    End Class
    'Whole Code Ends Here ....
 
  • After adding the code your Code Editor Window will look something like this one :
Step 6 : Compile Your Project
  • After adding all the code, now you are ready to compile your code and run your application.
  • To compile go to Debug -> Build SerialPortInterface and if everything's going right then your project will pop up.
  •  To test your application, just add some LCD to your serial port or simply short your Rx Tx pins and whatever you send you will receive it.
  • Here's the image of my final application. I have converted it to .exe file, in my coming tutorials i will tell you how to convert a project to .exe file.
Note :
  • The project exe file and the complete code has already been emailed to all our subscribed members.
  • If someone didn't get it or want to get these files then first Subscribe to Our Newsletter and then post your email here and I will email it to them.
So that was all on How to use Serial Port in VB 2010. I hope you guys have enjoyed it and are gonna design it on your own. Take care !!! :)
Syed Zain Nasir

I am Syed Zain Nasir, the founder of <a href=https://www.TheEngineeringProjects.com/>The Engineering Projects</a> (TEP). I am a programmer since 2009 before that I just search things, make small projects and now I am sharing my knowledge through this platform.I also work as a freelancer and did many projects related to programming and electrical circuitry. <a href=https://plus.google.com/+SyedZainNasir/>My Google Profile+</a>

Share
Published by
Syed Zain Nasir