all groups > vb.net controls > november 2006 >
You're in the

vb.net controls

group:

Serial Control


Serial Control Lou
11/15/2006 10:11:36 AM
vb.net controls:
When I send non-printable text Chr(248) to the control and it shows question
marks (?)
and doesn't recognize the chr(248)
I have tried setting the controls "Encoding" to ASCII, UTF7,UTF8 but
the Buffer does not accept the characters above 128?


Private Shared Sub SerialPort_DataReceived(ByVal sender As Object, ByVal e
As _

System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort.DataReceived

Dim Buffer As String = SerialPort.ReadExisting()

DefInstance.txtTerm.BeginInvoke(New _

DisplayData(AddressOf Display), _

New Object() {Buffer})



-Lou

Re: Serial Control Dick Grier
11/15/2006 12:16:04 PM
Hi,

Use the Read method and assign to an array of type Byte. Do not use a
String.

ReadExisting is for strings. Binary data (values > &H7F) should not attempt
to use String, but rather arrays of bytes. I have more detailed information
and examples in my book (see below). But, to get you started:

Dim Count As Integer = SerialPort.BytesToRead

Dim Buffer(0 To Count - 1) As Byte

Text2Display = ""

SerialPort.Read(Buffer, 0, Count)

If MenuItem13.Checked = False Then 'text display

Text2Display = System.Text.Encoding.ASCII.GetString(Buffer, 0,
Buffer.Length)



Else

'binary display

For I As Integer = 0 To Buffer.GetUpperBound(0)

Text2Display += Buffer(I).ToString("X2") & " "

Next

End If

You now can call Invoke or BeginInvoke to marshal data in the Text2Display
buffer to be shown.

Dick
--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.

Re: Serial Control Lou
11/17/2006 3:43:05 PM
Dick, your the best!

[quoted text, click to view]

Re: Serial Control Lou
11/22/2006 10:18:33 AM
Ok, that code works in getting the bytes but the display text box still
doesn't show the non-printable characters.
If I send chr(248) I want to se"ø" in the text box.
This works fine in VB6 using the MSComm control.
I tried all the different encodings but that didn't seem to work?

Lou


[quoted text, click to view]

Re: Serial Control Lou
11/22/2006 10:19:09 AM
Ok, that code works in gettingthe bytes but the display text box still
doesn't show the non-printable characters.
If i send chr(248) I want to se"ø" in th etext box.
This works fine in VB6 using the MSComm control.
I tried all the different encodings but that didn't seem to work?

Lou


[quoted text, click to view]

AddThis Social Bookmark Button