For a Specific system that we're developing we have certain USB Modules that connect to a Server, these modules use a pretty standard USB - Serial chip, so they look like Com ports to the OS.. we then send commands back and forth via serial coms..

USB - Serial is pretty standard stuff for us, and have several different products that work this way, and we coms with them very well, and can even handle the fact that USB can been unplugged and plugged back in, Anywhere..

Using a Normal Windows Forms Application, the Module coms works 100%.. I can detect the port, probe the device, and get a result...

However, once the identical code runs as a Installed service (Local System), using sc create "Service Name" binpath= "FULL PATH TO EXECUTABLE" start= auto , is where the 'FUN' starts.... BTW, the EXE is a Windows service project...

Because the Service is Formless, and has no MSGbox's, I write debug info to a log file.. (even in the Form app)

Private Sub Locate_Module(ByVal Ports() As Byte, ByRef Modules As List(Of ComVals.ModList))
Dim TmpStr As String
Dim TmpMod As ComVals.ModList
Modules = New List(Of ComVals.ModList)
For Each Comm In Ports
If _Debug Then
RaiseEvent DebugE("Com Port: " & Comm)
End If
ModComms = New ComObject(_Debug)
ModComms.OPEN(Comm)
If _Debug Then
RaiseEvent DebugE("Checking Module on Com" & Comm)
End If
If ModComms.CheckModem() Then
If _Debug Then
RaiseEvent DebugE("Reply from Module")
End If
TmpStr = ModComms.GetID()
TmpMod = New ComVals.ModList
TmpMod.Name = TmpStr
TmpMod.Port = Comm
TmpMod.ID = Comm
Modules.Add(TmpMod)
End If
ModComms.Close()
ModComms = Nothing
Next
End Sub

Now you might notice that i then have a wrapped the Actual serialport with ComObject.. this was intentially done for Multiple Modules to work simultaneously, as needed.. the important ComObject code is

What have i done wrong, that the service simply does not wana connect to the serial port ???? Must i use a different serial object... Been going nuts on this for the last week now.... Please help .....

Private Sub GetCommStateNative(ByRef lpDcb As Dcb)
Dim commErrors As Integer = 0
Dim Comstat As Comstat = New Comstat()
For i As Integer = 0 To CommStateRetries - 1
If Not (ClearCommError(m_Handle, commErrors, Comstat)) Then WinIoError()
If (GetCommState(m_Handle, lpDcb)) Then Exit Sub
If (i = CommStateRetries - 1) Then WinIoError()
Next
End Sub

Private Sub SetCommStateNative(ByRef lpDcb As Dcb)
Dim commErrors As Integer = 0
Dim Comstat As Comstat = New Comstat()
For i As Integer = 0 To CommStateRetries - 1
If Not (ClearCommError(m_Handle, commErrors, Comstat)) Then WinIoError()
If (SetCommState(m_Handle, lpDcb)) Then Exit Sub
If (i = CommStateRetries - 1) Then WinIoError()
Next
End Sub

#Region "Nested type: COMSTAT"

Private Structure Comstat

Public ReadOnly Flags As UInteger
Public ReadOnly cbInQue As UInteger
Public ReadOnly cbOutQue As UInteger

End Structure
#End Region

#Region "Nested type: DCB"

Private Structure Dcb

Public ReadOnly DCBlength As UInteger
Public ReadOnly BaudRate As UInteger
Public Flags As UInteger
Public ReadOnly wReserved As UShort
Public ReadOnly XonLim As UShort
Public ReadOnly XoffLim As UShort
Public ReadOnly ByteSize As Byte
Public ReadOnly Parity As Byte
Public ReadOnly StopBits As Byte
Public ReadOnly XonChar As Byte
Public ReadOnly XoffChar As Byte
Public ReadOnly ErrorChar As Byte
Public ReadOnly EofChar As Byte
Public ReadOnly EvtChar As Byte
Public ReadOnly wReserved1 As UShort
End Structure
#End Region