I need your help regarding serial communication in VB.

I can't able to sand OR receive the data in BYTE form.
(ie. 00 to FF)

There is no proper example in MSDN.
Can you tell me something in this matter?

Thanks
Kishor Soni:!:

Dani AI

Generated

asked about sending/receiving raw bytes (00..FF). The common root cause is treating the port as text (WriteLine/ReadLine or string conversions) instead of using binary I/O. 's suggestion to use a communications control is fine, but use the control's byte/binary interface. As suggested, post the actual init/send/receive code if this does not fix it; that helps pinpoint framing, handshake, or threading mistakes.

Example for VB.NET (System.IO.Ports.SerialPort): use byte arrays and the byte-based Read/Write methods rather than string-based helpers.

' VB.NET - send and receive raw bytes
Dim port As New IO.Ports.SerialPort("COM1", 9600, IO.Ports.Parity.None, 8, IO.Ports.StopBits.One)
AddHandler port.DataReceived, AddressOf Port_DataReceived
port.Open()

Dim outData As Byte() = New Byte() {&H00, &H01, &HFF}
port.Write(outData, 0, outData.Length)

Private Sub Port_DataReceived(sender As Object, e As IO.Ports.SerialDataReceivedEventArgs)
    Dim sp = CType(sender, IO.Ports.SerialPort)
    Dim toRead = sp.BytesToRead
    If toRead > 0 Then
        Dim buffer(toRead - 1) As Byte
        sp.Read(buffer, 0, toRead)
        Dim hex = BitConverter.ToString(buffer)   ' example processing
        ' marshal to UI thread before touching controls
    End If
End Sub

Notes for classic VB (VB6): the MSComm control can accept binary data if a byte array (Variant) is assigned to MSComm.Output. If that does not behave reliably, use Win32 APIs (CreateFile/WriteFile) to open the COM port handle and write raw bytes. Avoid building messages with Chr$/string concatenation for large or null-containing payloads.

Quick troubleshooting checklist:

  • Match baud/data bits/parity/stop bits on both ends.
  • Disable text framing (ReadLine) and use BytesToRead/Read or a length-based protocol.
  • Check hardware flow control (RTS/DTR/CTS) — it can block transmission.
  • Do a local loopback (TX->RX) to verify sent bytes are what the app transmits.
  • Remember receive events run on background threads; marshal UI updates correctly.
    If problems persist, post the exact port setup and the minimal send/receive code as advised so the framing/handshake/threading issues can be diagnosed.

Recommended Answers

All 4 Replies

iam Krishantha From Sri Lanka.
i like to help you to data comunication through seriol port with VB
tell me what is you're prob;am.
and what is the perpase
thanks

Krisha

I need your help regarding serial communication in VB.

I can't able to sand OR receive the data in BYTE form.
(ie. 00 to FF)

There is no proper example in MSDN.
Can you tell me something in this matter?

Thanks
Kishor Soni:!:

Thanks Marikanna

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.