keko2004
Active member
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?
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