Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Problem With sending values via serial port

Problem With sending values via serial port

Scheduled Pinned Locked Moved C#
helptutorial
8 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Honeyboy_20
    wrote on last edited by
    #1

    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

    L L B S 4 Replies Last reply
    0
    • H Honeyboy_20

      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

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      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 decimal

      There 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.

      L 1 Reply Last reply
      0
      • L Luc Pattyn

        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 decimal

        There 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.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        An excellent analysis; have a 5.

        I must get a clever new signature for 2011.

        L 1 Reply Last reply
        0
        • L Lost User

          An excellent analysis; have a 5.

          I must get a clever new signature for 2011.

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • H Honeyboy_20

            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

            L Offline
            L Offline
            lukeer
            wrote on last edited by
            #5

            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 = 0x3F

            So there is a connection between the numerical values you mentioned.

            Ciao, luker

            1 Reply Last reply
            0
            • H Honeyboy_20

              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

              B Offline
              B Offline
              Bernhard Hiller
              wrote on last edited by
              #6

              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?

              P 1 Reply Last reply
              0
              • B Bernhard Hiller

                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?

                P Offline
                P Offline
                phil o
                wrote on last edited by
                #7

                Bernhard Hiller wrote:

                But there are no signed bytes in .NET...

                And what do you think System.SByte is for ? :p

                1 Reply Last reply
                0
                • H Honeyboy_20

                  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

                  S Offline
                  S Offline
                  Sader_L
                  wrote on last edited by
                  #8

                  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

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups