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:!:
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:!:
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:
— Ancient Dragon 5,243Jump to Post
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:!:
Hi,
You can see some examples in this thread regarding Serial Comm.
http://www.daniweb.com/techtalkforums/thread56527.html
post your code if you still face the same issues.
Regards
Marikanna
Thanks Marikanna
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.