opening ports

keko2004

Active member
Joined
Feb 13, 2006
Messages
39
Location
Middle Village, NY
Programming Experience
1-3
can someone explain to me how to write a program to open a specific port and then listen on it. or maybe you have a turorial?
 
You mean a COM port?....


VB.NET:
Public Sub Open(ByVal portname As String, _
        ByVal Spd As Integer, ByVal Pty As enumParity, _
        ByVal Dtb As Integer, ByVal Stp As enumStopBits)
        Dim m_CommDCB As String
        Dim m_Baud As String
        Dim m_Parity As String
        Dim m_Data As String
        Dim m_Stop As Byte
        hPort = CreateFile(portname, GENERIC_READ + GENERIC_WRITE, _
              0, 0, OPEN_EXISTING, 0, 0)
        If hPort < 1 Then
            Throw New Exception("Can't open the comport! (Errorcode :" _
                  & GetLastError().ToString() & ")")
        End If
        m_Baud = Spd.ToString()
        m_Parity = PARITYSTRING.Substring(Pty, 1)
        m_Data = Dtb.ToString()
        m_Stop = Stp
        m_CommDCB = String.Format("baud={0} parity={1} data={2} stop={3}", _
              m_Baud, m_Parity, m_Data, m_Stop)
        BuildCommDCB(m_CommDCB, dcbPort)
        If SetCommState(hPort, dcbPort) = 0 Then
            Throw New Exception("Cannot open port(" & _
               GetLastError().ToString() & ")")
        End If
        m_opened = True
End Sub

Here's the link that goes with it...

http://www.codeproject.com/vb/net/Comport_made_simple.asp
 
Back
Top