Help sending hex data through SerialPort

  • Thread starter Thread starter Adriano
  • Start date Start date
A

Adriano

Hello,

I'm developing an application in VB.NET 2005 that communicates with a device
through RS232,
and need to send the following sequence of hexadecimal data to the device:

0xFF, 0x01, 0xC3, 0xE3, 0xFF, 0xFF.


That's the configuration:

SerialPort.PortName = "COM1"
SerialPort.BaudRate = 9600
SerialPort.StopBits = IO.Ports.StopBits.One
SerialPort.DataBits = 8
SerialPort.Parity = IO.Ports.Parity.None

If SerialPort.IsOpen = False Then
SerialPort.Open()
End If

How to send and receive data???

??? SerialPort.Write(??????)
??? TextBox1.Text = SerialPort.ReadExisting

SerialPort.Close()

p.s. according to manual, the responce of device is also in hexadeciaml
format, smt. like 0xFF, 0x01, 0xC3, 0x00, 0x05, 0xFF

Any help would be greatly appreciated,

thanks in advance,
Adriano
 
Hi,

To add to what Terry posted:

Dim Buffer() As Byte = {&HFF, &H01, &HC3, &HE3, &HFF, &HFF)

SerialPort.Write(Buffer, 0, 6) 'for example

--
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.
 
Back
Top