Solved

declare a serial port

Posted on 2014-09-04
2
212 Views
Last Modified: 2014-09-05
I am converting an application from VB6 to .NET

The VB6 code was:
Sub InitComPort(ComPort As Control, PortNum As Integer)
    ' -------------------------------
    ' setups the commport
    ' ------------------------------

    On Local Error Resume Next
    If ComPort.PortOpen = True Then
        ComPort.PortOpen = False
    End If
    ComPort.CommPort = PortNum
   
    ComPort.Settings = "9600,N,8,1"
   
    ComPort.PortOpen = True
   
    ComPort.RThreshold = 0
   
    SendingCmd = False
   
End Sub

How does the ComPort get defined in VB.NET.
Thanks,
0
Comment
Question by:Adam_930
2 Comments
 

Assisted Solution

by:joekucera2002
joekucera2002 earned 200 total points
Comment Utility
You are looking for the SerialPort class in the System.IO.Ports namespace.

Please let me know if you need a code sample. Keep in mind that in VB6, the ComPort was a control that was placed on a form, and the SerialPort is a class meant to be used in code (preferably not in the UI layer).
0
 
LVL 12

Accepted Solution

by:
Ramkisan Jagtap earned 300 total points
Comment Utility
Hello,

Check the following code:

Function ReceiveSerialData() As String
    ' Receive strings from a serial port.
    Dim returnStr As String = ""

    Dim com1 As IO.Ports.SerialPort = Nothing
    Try
        com1 = My.Computer.Ports.OpenSerialPort("COM1")
        com1.ReadTimeout = 10000
        Do
            Dim Incoming As String = com1.ReadLine()
            If Incoming Is Nothing Then
                Exit Do
            Else
                returnStr &= Incoming & vbCrLf
            End If
        Loop
    Catch ex As TimeoutException
        returnStr = "Error: Serial Port read timed out."
    Finally
        If com1 IsNot Nothing Then com1.Close()
    End Try

    Return returnStr
End Function

Check the detailed article
 http://www.dreamincode.net/forums/topic/37361-serial-port-communication-in-vbnet/
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now