readline problem for serialport

J

Jan

Hello there,

I've got a strange problem using the readline method in vb2005 for
reading the serial port.
If I use the readchar method I can receive one character from
serialport. This is the code I use:

Function ReceiveSerialData() As String
' Receive strings from a serial port.
Dim returnStr As String = ""

Using com1 As IO.Ports.SerialPort = _
My.Computer.Ports.OpenSerialPort("COM1", 2400,
IO.Ports.Parity.None, 8, 1)
com1.RtsEnable = True



Dim Incoming As Integer = com1.ReadChar()(Y)
returnStr = Chr(Incoming)
End Using

Return returnStr

End Function

this works well, but not with de readline method:

Dim Incoming As String = com1.ReadLine()(N)
returnStr = Incoming

I hope one of you can help me

TIA
 
D

DickGrier

Hi,

I prefer to simply read data into a buffer (append) and then to parse data
out of that buffer in my own code. The problem is that various different OS
use different newline character(s). A new line might be a vbCrLf, as with
most Windows software, a simple vbLF (some unix or mainframes), or a vbCR
(some other devices), while I've seen some that would need vbLf & vbCr
(reversing the order of the carriage return and line feed characters).

If you simply read the data stream, you can parse out each of these
variations with some faily simple code (I have an example of one way to do
this in my book; see below).

Dick
 
K

Ken Halter

DickGrier said:
Hi,

(some other devices), while I've seen some that would need vbLf & vbCr
(reversing the order of the carriage return and line feed characters).

We had a couple of these devices <g> I think the device manufacturer did it
that way to disable "simple terminal support" so we'd have to buy their
readers. I said "HA!" <g> I ended up just writing a little routine that
ignored and "absorbed" all line feeds and appended line feeds to any CR
recv'd. That worked well for the "normal" devices as well as the "wierd"
ones.
 

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