Problem With sending values via serial port
-
I have problem when I am try to send byte to serial port. for example int x=153; when i get the hexa decimal of 153 it's 99 but when I am try to send it , it appear as 3F but I want it to be 99 as hexa decimal
-
I have problem when I am try to send byte to serial port. for example int x=153; when i get the hexa decimal of 153 it's 99 but when I am try to send it , it appear as 3F but I want it to be 99 as hexa decimal
Honeyboy_20 wrote:
I have problem when I am try to send byte to serial port.
for example
int x=153;
when i get the hexa decimal of 153 it's 99
but when I am try to send it , it appear as 3F but I want it to be 99 as hexa decimalThere is more text than information here. It needs dissecting.
Honeyboy_20 wrote:
I have problem when I am try to send byte to serial port.
that is not a question. And neither is the rest of your message. So I will ask some questions you can think about.
Honeyboy_20 wrote:
int x=153;
why would you need an int if you want to send a byte. How about declaring a byte instead?
Honeyboy_20 wrote:
when i get the hexa decimal of 153 it's 99
why would you need hex at all? how is that relevant? you can send bytes through a serial port, no matter what values they contain or whatever they represent.
Honeyboy_20 wrote:
but when I am try to send it , it appear as 3F
that is a bit of a surprise. there must be some magical code involved here. I have a rough idea how one could do it, but hey, I trust your code is much better than that. :|
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
Honeyboy_20 wrote:
I have problem when I am try to send byte to serial port.
for example
int x=153;
when i get the hexa decimal of 153 it's 99
but when I am try to send it , it appear as 3F but I want it to be 99 as hexa decimalThere is more text than information here. It needs dissecting.
Honeyboy_20 wrote:
I have problem when I am try to send byte to serial port.
that is not a question. And neither is the rest of your message. So I will ask some questions you can think about.
Honeyboy_20 wrote:
int x=153;
why would you need an int if you want to send a byte. How about declaring a byte instead?
Honeyboy_20 wrote:
when i get the hexa decimal of 153 it's 99
why would you need hex at all? how is that relevant? you can send bytes through a serial port, no matter what values they contain or whatever they represent.
Honeyboy_20 wrote:
but when I am try to send it , it appear as 3F
that is a bit of a surprise. there must be some magical code involved here. I have a rough idea how one could do it, but hey, I trust your code is much better than that. :|
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
Thank you kindly sir. I can hardly wait for the next episode. :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
I have problem when I am try to send byte to serial port. for example int x=153; when i get the hexa decimal of 153 it's 99 but when I am try to send it , it appear as 3F but I want it to be 99 as hexa decimal
I do agree with Luc Pattyn in that sending 153 or 0x99 doesn't make any difference. It's just a matter of output formatting. Maybe there is some decimal-to-hex formatting code in your program, which I believe you don't need at all. The reason for me to suspect that are the following equations:
153 = 0x99
99 = 0x63
63 = 0x3FSo there is a connection between the numerical values you mentioned.
Ciao, luker
-
I have problem when I am try to send byte to serial port. for example int x=153; when i get the hexa decimal of 153 it's 99 but when I am try to send it , it appear as 3F but I want it to be 99 as hexa decimal
Is that a problem with signed versus unsigned bytes? 153 is bigger than the maximum value of a signed byte, while 99 is small enough to fit into a signed byte. But there are no signed bytes in .NET... How do you convert from int to byte?
-
Is that a problem with signed versus unsigned bytes? 153 is bigger than the maximum value of a signed byte, while 99 is small enough to fit into a signed byte. But there are no signed bytes in .NET... How do you convert from int to byte?
-
I have problem when I am try to send byte to serial port. for example int x=153; when i get the hexa decimal of 153 it's 99 but when I am try to send it , it appear as 3F but I want it to be 99 as hexa decimal
int num = 153;
string hex = num.ToString("X2");//99
//byte send = byte.Parse(hex);//0x63 wrong!
byte send = byte.Parse(hex , System.Globalization.NumberStyles.AllowHexSpecifier); //0x99,Better to use TryParse.//May be you are wrong twice,so 153 => "99" => 0x63 => "63" => 0x3F