Solved

declare a serial port

Posted on 2014-09-04
2
216 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
ID: 40304914
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
ID: 40305093
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

910 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

24 Experts available now in Live!

Get 1:1 Help Now