By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,537 Members | 1,743 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,537 IT Pros & Developers. It's quick & easy.

Help sending hex data through SerialPort

P: n/a
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
Jul 19 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Dim xmtBuf() as byte = {&HFF,&H1,&HC3,&HE3,&HFF,&HFF}
SerialPort.Write(xmtBuf,0,xmtBuf.Length)

Dim rcvBuf(1024) as byte
SerialPort.Read(rcvBuf,0,rcvBuf.Length)

http://msdn2.microsoft.com/en-us/lib...rt(VS.80).aspx
"Adriano" <ad*****@mail.itwrote in message
news:uJ**************@TK2MSFTNGP05.phx.gbl...
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

Jul 19 '07 #2

P: n/a
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.
Jul 19 '07 #3

P: n/a
Thanks Terry,

seems it worked!

Regards,
Adriano

"Terry Olsen" <to******@hotmail.comсообщил/сообщила в новостях следующее:
news:%2***************@TK2MSFTNGP04.phx.gbl...
Dim xmtBuf() as byte = {&HFF,&H1,&HC3,&HE3,&HFF,&HFF}
SerialPort.Write(xmtBuf,0,xmtBuf.Length)

Dim rcvBuf(1024) as byte
SerialPort.Read(rcvBuf,0,rcvBuf.Length)

http://msdn2.microsoft.com/en-us/lib...rt(VS.80).aspx
"Adriano" <ad*****@mail.itwrote in message
news:uJ**************@TK2MSFTNGP05.phx.gbl...
>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


Jul 20 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.