Help sending hex data through SerialPort

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Adriano

    #1

    Help sending hex data through SerialPort

    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.Port Name = "COM1"
    SerialPort.Baud Rate = 9600
    SerialPort.Stop Bits = IO.Ports.StopBi ts.One
    SerialPort.Data Bits = 8
    SerialPort.Pari ty = IO.Ports.Parity .None

    If SerialPort.IsOp en = False Then
    SerialPort.Open ()
    End If

    How to send and receive data???

    ??? SerialPort.Writ e(??????)
    ??? TextBox1.Text = SerialPort.Read Existing

    SerialPort.Clos e()

    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


  • Terry Olsen

    #2
    Re: Help sending hex data through SerialPort

    Dim xmtBuf() as byte = {&HFF,&H1,&HC3, &HE3,&HFF,&H FF}
    SerialPort.Writ e(xmtBuf,0,xmtB uf.Length)

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

    http://msdn2.microsoft.com/en-us/lib...rt(VS.80).aspx


    "Adriano" <adriano@mail.i twrote in message
    news:uJSQb$ayHH A.1568@TK2MSFTN GP05.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.Port Name = "COM1"
    SerialPort.Baud Rate = 9600
    SerialPort.Stop Bits = IO.Ports.StopBi ts.One
    SerialPort.Data Bits = 8
    SerialPort.Pari ty = IO.Ports.Parity .None
    >
    If SerialPort.IsOp en = False Then
    SerialPort.Open ()
    End If
    >
    How to send and receive data???
    >
    ??? SerialPort.Writ e(??????)
    ??? TextBox1.Text = SerialPort.Read Existing
    >
    SerialPort.Clos e()
    >
    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
    >

    Comment

    • Dick Grier

      #3
      Re: Help sending hex data through SerialPort

      Hi,

      To add to what Terry posted:

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

      SerialPort.Writ e(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.


      Comment

      • Adriano

        #4
        Re: Help sending hex data through SerialPort

        Thanks Terry,

        seems it worked!

        Regards,
        Adriano

        "Terry Olsen" <tolsen64@hotma il.comñîîáùèë/ñîîáùèëà â íîâîñòÿõ ñëåäóþùåå:
        news:%23Gp2$dby HHA.748@TK2MSFT NGP04.phx.gbl.. .
        Dim xmtBuf() as byte = {&HFF,&H1,&HC3, &HE3,&HFF,&H FF}
        SerialPort.Writ e(xmtBuf,0,xmtB uf.Length)
        >
        Dim rcvBuf(1024) as byte
        SerialPort.Read (rcvBuf,0,rcvBu f.Length)
        >
        http://msdn2.microsoft.com/en-us/lib...rt(VS.80).aspx
        >
        >
        "Adriano" <adriano@mail.i twrote in message
        news:uJSQb$ayHH A.1568@TK2MSFTN GP05.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.Port Name = "COM1"
        > SerialPort.Baud Rate = 9600
        > SerialPort.Stop Bits = IO.Ports.StopBi ts.One
        > SerialPort.Data Bits = 8
        > SerialPort.Pari ty = IO.Ports.Parity .None
        >>
        > If SerialPort.IsOp en = False Then
        > SerialPort.Open ()
        > End If
        >>
        >How to send and receive data???
        >>
        >??? SerialPort.Writ e(??????)
        >??? TextBox1.Text = SerialPort.Read Existing
        >>
        > SerialPort.Clos e()
        >>
        >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
        >>
        >
        >

        Comment

        Working...