How do I send HEX numbers across TCP?

  • Thread starter Thread starter Jerry Spence1
  • Start date Start date
J

Jerry Spence1

I am tring to send out of a TCP port, the hext digits:

FF010040000042

I can't quite get the syntax in my head:

Command="FFH010040000042"
Dim sendBytes As [Byte]() = System.Text.Encoding.ASCII.GetBytes(Command)
networkStream.Write(sendBytes, 0, sendBytes.Length)

This isn't going to work as it will send the ascii characters instead of
the hex values.

Can anyone help please?

-Jerry
 
Hello,

jim said:
nevermind.....I got it.

Can you please post how you are doing this? I am trying to determine if a PC
is connected to a certain netwoek.

Thanks,

Michel
 
How about

byte[] bytes = new byte[] {0xff, ... } - this is C# syntax

and writing them to the stream?

But I am not sure what if H0 after FF - probably typo?
 
Sorry - the H0 was a typo. I was originally thinking of sending FFh as a
single byte and I forgot to remove it when I sent the post.

Sorry I don't understand C#

It's hard to explain what I mean, but I am trying to send out the actual Hex
values, rather than the string itself. It's the difference between sending
FFh (ie 11111111) and "FF" (which will send the ascii values for FF).

-I hope that helps

Thanks so far!

-Jerry

AlexS said:
How about

byte[] bytes = new byte[] {0xff, ... } - this is C# syntax

and writing them to the stream?

But I am not sure what if H0 after FF - probably typo?


Jerry Spence1 said:
I am tring to send out of a TCP port, the hext digits:

FF010040000042

I can't quite get the syntax in my head:

Command="FFH010040000042"
Dim sendBytes As [Byte]() = System.Text.Encoding.ASCII.GetBytes(Command)
networkStream.Write(sendBytes, 0, sendBytes.Length)

This isn't going to work as it will send the ascii characters instead of
the hex values.

Can anyone help please?

-Jerry
 
Jerry Spence1 said:
Sorry - the H0 was a typo. I was originally thinking of sending FFh as a
single byte and I forgot to remove it when I sent the post.

Sorry I don't understand C#

It's hard to explain what I mean, but I am trying to send out the actual
Hex values, rather than the string itself. It's the difference between
sending FFh (ie 11111111) and "FF" (which will send the ascii values for
FF).

-I hope that helps

Thanks so far!

-Jerry

AlexS said:
How about

byte[] bytes = new byte[] {0xff, ... } - this is C# syntax

and writing them to the stream?

But I am not sure what if H0 after FF - probably typo?


Jerry Spence1 said:
I am tring to send out of a TCP port, the hext digits:

FF010040000042

I can't quite get the syntax in my head:

Command="FFH010040000042"
Dim sendBytes As [Byte]() = System.Text.Encoding.ASCII.GetBytes(Command)
networkStream.Write(sendBytes, 0, sendBytes.Length)

This isn't going to work as it will send the ascii characters instead
of the hex values.

Can anyone help please?

-Jerry

something like this?...

Dim mydata() As Byte = New Byte(0 To 7) { _
&H1, &HFF, &HF1, &H55, &H1, &HFF, &HFF, &H0}

Send(mydata)




-Blake
 
This should work:

dim sendBytes() as Byte = { &Hff, &H01, &H00, &H40, ... }

networkStream.Write(sendBytes, 0, sendBytes.Length)


Jerry Spence1 said:
Sorry - the H0 was a typo. I was originally thinking of sending FFh as a
single byte and I forgot to remove it when I sent the post.

Sorry I don't understand C#

It's hard to explain what I mean, but I am trying to send out the actual
Hex values, rather than the string itself. It's the difference between
sending FFh (ie 11111111) and "FF" (which will send the ascii values for
FF).

-I hope that helps

Thanks so far!

-Jerry

AlexS said:
How about

byte[] bytes = new byte[] {0xff, ... } - this is C# syntax

and writing them to the stream?

But I am not sure what if H0 after FF - probably typo?


Jerry Spence1 said:
I am tring to send out of a TCP port, the hext digits:

FF010040000042

I can't quite get the syntax in my head:

Command="FFH010040000042"
Dim sendBytes As [Byte]() = System.Text.Encoding.ASCII.GetBytes(Command)
networkStream.Write(sendBytes, 0, sendBytes.Length)

This isn't going to work as it will send the ascii characters instead
of the hex values.

Can anyone help please?

-Jerry
 
Blake said:
Jerry Spence1 said:
Sorry - the H0 was a typo. I was originally thinking of sending FFh as a
single byte and I forgot to remove it when I sent the post.

Sorry I don't understand C#

It's hard to explain what I mean, but I am trying to send out the actual
Hex values, rather than the string itself. It's the difference between
sending FFh (ie 11111111) and "FF" (which will send the ascii values for
FF).

-I hope that helps

Thanks so far!

-Jerry

AlexS said:
How about

byte[] bytes = new byte[] {0xff, ... } - this is C# syntax

and writing them to the stream?

But I am not sure what if H0 after FF - probably typo?


I am tring to send out of a TCP port, the hext digits:

FF010040000042

I can't quite get the syntax in my head:

Command="FFH010040000042"
Dim sendBytes As [Byte]() =
System.Text.Encoding.ASCII.GetBytes(Command)
networkStream.Write(sendBytes, 0, sendBytes.Length)

This isn't going to work as it will send the ascii characters instead
of the hex values.

Can anyone help please?

-Jerry

something like this?...

Dim mydata() As Byte = New Byte(0 To 7) { _
&H1, &HFF, &HF1, &H55, &H1, &HFF, &HFF, &H0}

Send(mydata)




-Blake

Thank you Blake and Alex. That was it. Very grateful

-Jerry
 
Back
Top