EMBEDDED TWEAKS

Embedded Electronics Tutorials, Coding and lot more

Accessing PC serial port in Visual Basic

All of the electronics engineering students mostly want to create something which has a nice GUI control for their device. But they see softwares like VB6, VB.NET as pure software language. On the other side, Computer engineering students see also these software as pure GUI. Electronics geeks know the hardware and computer geeks know software. But Actually these languages such as VB6, VB.NET, Java can provide us very useful features to control our hardware connected to PCs. Here i am presenting a very basic tutorial to access serial port of PC in the VB6 software.

We will create the GUI (Graphical User Interface) which contains some buttons. Pressing them we can send some data to our PC’s serial port. Though it is a very basic tutorial but this is a must learn step. Further you can receive, send, monitor data, take some decisions based on that, store hardware data in some databases in your software.  We can start with basic mirocontrollers by connecting them with our PC’s serial Ports.  We are creating a software which has 2 buttons. Pressing button 1 it sends value ‘A’ to the serial port and Pressing button 2 it sends value ‘B’ to the serial port. You can monitor them via virtual serial port pairing method. If you dont know virtual serial port emulating then see this .

Step 1: Start New project in VB 6. Create standard EXE file project.1

Step 2: On the main form add two command buttons. If you see carefully then you will find that most of all components are available in the left panel. But as pointed out in the below screen you can see that by default there is no component for serial port available. Hence we need to select it from the project menu, shown in next screen. 2 3Step 3: Select the Microsoft Comm Control 6.0 as shown here.

4

 

So as in below screen now you will get serial port component in your project.

5

Step 4: Write code for each component individually.

This MSComm component is not visible at run time on the GUI. But it operates in the background.

The code for configuring the serial port is as shown below. This code should be executed at the time of loading the form.

Private Sub Form_Load()
‘ Fire Rx Event Every single Bytes
MSComm1.RThreshold = 1

‘ When Inputting Data, Input 1 Byte at a time
MSComm1.InputLen = 1

‘ 9600 Baud, No Parity, 8 Data Bits, 1 Stop Bit
MSComm1.Settings = “9600,N,8,1”
‘ Disable DTR
MSComm1.DTREnable = False

‘ Open COM1
MSComm1.CommPort = 1
MSComm1.PortOpen = True
End Sub

We have created 2 buttons, both can be programmed as follows to send ‘A’ or ‘B’ as per the button.

Private Sub Command1_Click()
‘ Send ‘A’ in ascii means 65 in decimal
MSComm1.Output = Chr$(65)
End Sub

Private Sub Command2_Click()
‘ Send ‘B’ in ascii means 65 in decimal
MSComm1.Output = Chr$(66)
End Sub

Note: Dont forget to write code to close the serial port you used here. So that after you close this software your other softwares be able to use that serial port. Code for that is shown below.

Private Sub Form_Unload(Cancel As Integer)
MSComm1.PortOpen = False
End Sub

Step 5: Run the project, monitor data on your serial port physically with your hardware circuits like microcontrollers or you can also do that virtually using VSPE software

Congratulations. Your task is done. Now further you can do more work related to this by making few modifications.

To see serial port hardware interfacing projects with VB, see this section containing VB6 projects with 8051, PIC microcontrollers.  Click here to view.

Comment below if you have any queries or doubts.

If you found this helpful please give your 5 seconds to rate and press Like button on my post. 

Sharing is caring

33 Comments

  1. Super-Duper blog! I am loving it!! Will be back later to read some more. I am taking your feeds also.

  2. great publish, very informative. I’m wondering why the opposite
    specialists of this sector don’t notice this. You should continue your writing.
    I’m confident, you’ve a great readers’ base
    already!

  3. This is really interesting, You are a very skilled blogger. I’ve joined your rss feed and look forward to seeking more of your great post. Also, I’ve shared your website in my social networks!

  4. As soon as I found this web site I went on reddit to share some of the love with them.

  5. Hello there, I discovered your website by way of Google at the same time as looking for a comparable topic, your site came up, it looks great. I have bookmarked it in my google bookmarks.

  6. That is the suitable weblog for anyone who needs to seek out out about this topic. You realize so much its nearly hard to argue with you (not that I really would need…HaHa). You undoubtedly put a new spin on a topic thats been written about for years. Great stuff, just nice!

  7. I have recently started a site, the information you offer on this site has helped me tremendously. Thank you for all of your time & work. “The achievements of an organization are the results of the combined effort of each individual.” by Vince Lombardi.

  8. I enjoy you because of each of your effort on this web site. My mum takes pleasure in participating in research and it is easy to understand why. Most people learn all concerning the powerful way you present functional thoughts on your web blog and invigorate response from website visitors on this topic so our own daughter is actually understanding a great deal. Take pleasure in the rest of the new year. Your performing a good job.

  9. Thank you for sharing superb informations. Your site is so cool. I am impressed by the details that you have on this web site. It reveals how nicely you perceive this subject. Bookmarked this website page, will come back for more articles. You, my friend, ROCK! I found just the information I already searched all over the place and simply couldn’t come across. What a great website.

  10. I was studying some of your blog posts on this internet site and I conceive this internet site is real instructive! Keep posting .

  11. Just wanna comment that you have a very nice site, I like the pattern it actually stands out.

  12. Hi there! I’m at work surfing around your blog from my new iphone! Just wanted to say I love reading through your blog and look forward to all your posts! Carry on the excellent work!

  13. Ideal site article. is it possible to be sure to convey to me what topic are you currently using? thanks

  14. I’m extremely impressed with your writing skills as well as with the layout on your blog. Is this a paid theme or did you customize it yourself? Anyway keep up the excellent quality writing, it’s rare to see a nice blog like this one these days.|

  15. I have recently started a website, the info you offer on this web site has helped me greatly. Thanks for all of your time & work. “Never trust anybody who says ‘trust me.’ Except just this once, of course. – from Steel Beach” by John Varley.

  16. Do you have any video of that? I’d want to find out some additional information.|

  17. What a stuff of un-ambiguity and preserveness of precious experience regarding unexpected feelings.|

  18. Link exchange is nothing else except it is just placing the other person’s website link on your page at appropriate place and other person will also do similar in support of you.|

  19. I loved as much as you’ll receive carried out right here. The sketch is attractive, your authored material stylish. nonetheless, you command get got an edginess over that you wish be delivering the following. unwell unquestionably come further formerly again as exactly the same nearly very often inside case you shield this hike.

  20. I really enjoy looking through on this website , it holds excellent content . “The great secret of power is never to will to do more than you can accomplish.” by Henrik Ibsen.

  21. Its like you read my mind! You seem to know a lot about this, like you wrote the book in it or something. I think that you could do with a few pics to drive the message home a bit, but other than that, this is magnificent blog. A fantastic read. I’ll definitely be back.|

  22. I was recommended this blog by my cousin. I am not sure whether this post is written by him as no one else know such detailed about my difficulty. You are incredible! Thanks!

  23. What’s up it’s me, I am also visiting this web site daily, this web page is truly good and the users are genuinely sharing pleasant thoughts.|

  24. With havin so much content and articles do you ever run into any issues of plagorism or copyright violation? My website has a lot of unique content I’ve either written myself or outsourced but it looks like a lot of it is popping it up all over the internet without my permission. Do you know any ways to help prevent content from being ripped off? I’d genuinely appreciate it.

  25. I have been exploring for a little for any high-quality articles or weblog posts on this sort of house . Exploring in Yahoo I at last stumbled upon this website. Studying this info So i’m glad to exhibit that I have an incredibly excellent uncanny feeling I discovered just what I needed. I most no doubt will make sure to don’t fail to remember this site and provides it a glance on a continuing basis.

  26. Just wanna tell that this is very beneficial , Thanks for taking your time to write this.

  27. This is the appropriate weblog for anybody who desires to find out about this topic. You notice a lot its virtually arduous to argue with you (not that I really would want…HaHa). You positively put a new spin on a subject thats been written about for years. Great stuff, simply nice!

  28. After research a couple of of the weblog posts on your website now, and I truly like your means of blogging. I bookmarked it to my bookmark website listing and will be checking back soon. Pls take a look at my web page as nicely and let me know what you think.

  29. I am continually browsing online for ideas that can benefit me. Thanks!

  30. You actually will have to learn this content! I could not presume it either until finally I check out it!

  31. I simply want to say I am newbie to blogging and site-building and honestly liked you’re web-site. Most likely I’m going to bookmark your website . You actually come with remarkable articles and reviews. Thanks a lot for revealing your web-site.

  32. Hey, thanks for the great post. I feel much better after having read this.

Leave a Reply

Your email address will not be published.

*

© 2018 EMBEDDED TWEAKS

Theme by Anders NorenUp ↑

Follow Me

Get the latest posts right delivered in you mailbox

%d bloggers like this: