Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the STX character of hex 02

I have a device to which I'm trying to connect via a socket, and according to the manual, I need the "STX character of hex 02".

How can I do this using C#?

like image 966
David Avatar asked Mar 06 '12 14:03

David


People also ask

What is STX in ascii?

STX. START OF TEXT. A transmission control character which precedes a text and which is used to terminate a heading.

What is STX string?

STX is just an ASCII character. https://en.wikipedia.org/wiki/ASCII const char STX = '\u0002'; And you can work with it like with any other character: String source = ...


1 Answers

Just a comment to GeoffM's answer (I don't have enough points to comment the proper way).

You should never embed STX (or other characters) that way using only two digits.

If the next character (after "\x02") was a valid hex digit, that would also be parsed and it would be a mess.

string s1 = "\x02End";
string s2 = "\x02" + "End";
string s3 = "\x0002End";

Here, s1 equals ".nd", since 2E is the dot character, while s2 and s3 equal STX + "End".

like image 170
Vegard Innerdal Avatar answered Sep 21 '22 21:09

Vegard Innerdal