How to read from comport with vb smart device

Ked

Joined
Jul 14, 2005
Messages
1
Reaction score
0
Hello!

I have problem to read from the comport with my ipaq hx4700. I think it works to open the comport but when I try to read from it then it does not work.

I have tried with following code to open the comport:


Dim intResult As Integer

Dim lpCommTimeouts As COMMTIMEOUTS
Dim lpDCB As New DCB

Try
intHandle = -1

If port > 0 Then

intHandle = CreateFile("COM" & port.ToString & ":", &HC0000000, 0, 0, 3, 0, 0)

If intHandle <> -1 Then

'intResult=PurgeComm(intHandle,


intResult = GetCommState(intHandle, lpDCB)

lpDCB.fBinary = 1

lpDCB.fParity = 1
lpDCB.fOutxCtsFlow = 0
lpDCB.fOutxDsrFlow = 0
lpDCB.fDtrControl = 1
lpDCB.fDsrSensitivity = 0
lpDCB.fTXContinueOnXoff = 1
lpDCB.fOutX = 0
lpDCB.fInX = 0
lpDCB.fErrorChar = 0
lpDCB.fNull = 0
lpDCB.fRtsControl = 1
lpDCB.fAbortOnError = 0
lpDCB.StopBits = stopbits
lpDCB.BytesSize = databits
lpDCB.Parity = parity
lpDCB.BaudRate = baudrate

lpDCB.XonChar = "1"

intResult = SetCommState(intHandle, lpDCB)

intResult = SetupComm(intHandle, rxbufsize, txbufsize)

lpCommTimeouts.ReadIntervalTimeout = 0
lpCommTimeouts.ReadTotalTimeoutMultiplier = 0
lpCommTimeouts.ReadTotalTimeoutConstant = timeout
lpCommTimeouts.WriteTotalTimeoutMultiplier = 10
lpCommTimeouts.WriteTotalTimeoutConstant = 100

intResult = SetCommTimeouts(intHandle, lpCommTimeouts)

Else
intHandle = -1


End If


Return intHandle

End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try


I use following code to read from the comport:

Private Sub connect()

Dim inPortNumber As Short = 8
Dim outPort As Short = 8

Dim lpDCB As New DCB



'infileHandler = CreateFile("COM" & inPortNumber & ":", &HC0000000, 0, 0, 3, 0, 0)

Application.DoEvents()

stopThread = False

t1 = New Threading.Thread(AddressOf receiveLoop)

t1.Start()

End Sub

Private Sub receiveLoop()

Dim inbuff(100) As Byte
Dim retCode As Integer = ReadFile(intHandle, inbuff, 100, numReadWrite, 0)

Try
Application.DoEvents()

While True

If retCode = 0 Or stopThread = True Then
'Error or thread stopped

Exit While


Else
Dim updateDelegate As New myDelegate(AddressOf updateMessageLog)

updateDelegate.Invoke(byteArrayToString(inbuff))

ReDim inbuff(100)

retCode = ReadFile(infileHandler, inbuff, 90, numReadWrite, 0)

Application.DoEvents()

End If

End While
Catch ex As Exception
MsgBox(ex.ToString)
End Try

End Sub


The value of variable "retCode" is always 0 so I wonder what shall I do. Does anybody know how to write code for reading from comport using vb and smart device?

I am very grateful for any help.

Thanks Ked
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top