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. C# Button Click for UART

C# Button Click for UART

Scheduled Pinned Locked Moved C#
csharphardwareworkspace
5 Posts 4 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.
  • J Offline
    J Offline
    John EE
    wrote on last edited by
    #1

    Ok I have setup a simple gui for uart. I am trying to light up 4 LEDS thru a MC. LED0 will be 0x01, LED 1, 2, 3 will be 2, 4, 8. Will this send out the appropriate command I am looking for. I have no way to test it until tomorrow because I do not have the hardware with me but was wondering if this would suffice. I do not get any errors or warnings so I am thinking it should. Thanks

    private void buttonLED0_Click_1(object sender, EventArgs e)
    {
    Data = Data ^= 0x01;
    int BytesToWrite = Data;
    int bytes = serialPort1.BytesToWrite;
    //UInt32 numBytesWritten = 1;
    buttonLED0.Enabled = !buttonLED0.Enabled;

            if (buttonLED0.Enabled)
            {
                pictureBoxLED0.BackgroundImage = imageList1.Images\[(int)LEDColor.GreenOn\];
            }
    
            if (!buttonLED0.Enabled)
            {
                
                pictureBoxLED0.BackgroundImage = imageList1.Images\[(int)LEDColor.RedOn\];
            } 
        }
    
    J B L 3 Replies Last reply
    0
    • J John EE

      Ok I have setup a simple gui for uart. I am trying to light up 4 LEDS thru a MC. LED0 will be 0x01, LED 1, 2, 3 will be 2, 4, 8. Will this send out the appropriate command I am looking for. I have no way to test it until tomorrow because I do not have the hardware with me but was wondering if this would suffice. I do not get any errors or warnings so I am thinking it should. Thanks

      private void buttonLED0_Click_1(object sender, EventArgs e)
      {
      Data = Data ^= 0x01;
      int BytesToWrite = Data;
      int bytes = serialPort1.BytesToWrite;
      //UInt32 numBytesWritten = 1;
      buttonLED0.Enabled = !buttonLED0.Enabled;

              if (buttonLED0.Enabled)
              {
                  pictureBoxLED0.BackgroundImage = imageList1.Images\[(int)LEDColor.GreenOn\];
              }
      
              if (!buttonLED0.Enabled)
              {
                  
                  pictureBoxLED0.BackgroundImage = imageList1.Images\[(int)LEDColor.RedOn\];
              } 
          }
      
      J Offline
      J Offline
      John EE
      wrote on last edited by
      #2

      By the way this will have to be sent out thru the TXD.

      1 Reply Last reply
      0
      • J John EE

        Ok I have setup a simple gui for uart. I am trying to light up 4 LEDS thru a MC. LED0 will be 0x01, LED 1, 2, 3 will be 2, 4, 8. Will this send out the appropriate command I am looking for. I have no way to test it until tomorrow because I do not have the hardware with me but was wondering if this would suffice. I do not get any errors or warnings so I am thinking it should. Thanks

        private void buttonLED0_Click_1(object sender, EventArgs e)
        {
        Data = Data ^= 0x01;
        int BytesToWrite = Data;
        int bytes = serialPort1.BytesToWrite;
        //UInt32 numBytesWritten = 1;
        buttonLED0.Enabled = !buttonLED0.Enabled;

                if (buttonLED0.Enabled)
                {
                    pictureBoxLED0.BackgroundImage = imageList1.Images\[(int)LEDColor.GreenOn\];
                }
        
                if (!buttonLED0.Enabled)
                {
                    
                    pictureBoxLED0.BackgroundImage = imageList1.Images\[(int)LEDColor.RedOn\];
                } 
            }
        
        B Offline
        B Offline
        Bekjong
        wrote on last edited by
        #3

        John-EE wrote:

        I do not get any errors or warnings so I am thinking it should.

        It would be nice if not getting compile time errors or warnings meant that something would work. The code you provided here doesn't look like it'll send anything out of the serial port. If it did, it would use the SerialPort.Write method. Take a look at msdn for details and examples.

        Standards are great! Everybody should have one!

        1 Reply Last reply
        0
        • J John EE

          Ok I have setup a simple gui for uart. I am trying to light up 4 LEDS thru a MC. LED0 will be 0x01, LED 1, 2, 3 will be 2, 4, 8. Will this send out the appropriate command I am looking for. I have no way to test it until tomorrow because I do not have the hardware with me but was wondering if this would suffice. I do not get any errors or warnings so I am thinking it should. Thanks

          private void buttonLED0_Click_1(object sender, EventArgs e)
          {
          Data = Data ^= 0x01;
          int BytesToWrite = Data;
          int bytes = serialPort1.BytesToWrite;
          //UInt32 numBytesWritten = 1;
          buttonLED0.Enabled = !buttonLED0.Enabled;

                  if (buttonLED0.Enabled)
                  {
                      pictureBoxLED0.BackgroundImage = imageList1.Images\[(int)LEDColor.GreenOn\];
                  }
          
                  if (!buttonLED0.Enabled)
                  {
                      
                      pictureBoxLED0.BackgroundImage = imageList1.Images\[(int)LEDColor.RedOn\];
                  } 
              }
          
          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          I don't really know what the rest is about, but this is definitely odd:

          John-EE wrote:

          Data = Data ^= 0x01;

          This will only do something other than the more usual Data ^= 1 if Data is a property with side effects

          OriginalGriffO 1 Reply Last reply
          0
          • L Lost User

            I don't really know what the rest is about, but this is definitely odd:

            John-EE wrote:

            Data = Data ^= 0x01;

            This will only do something other than the more usual Data ^= 1 if Data is a property with side effects

            OriginalGriffO Offline
            OriginalGriffO Offline
            OriginalGriff
            wrote on last edited by
            #5

            harold aptroot wrote:

            if Data is a property with side effects

            ...which we are all really hoping it isn't. :laugh:

            If Barbie is so popular, why do you have to buy her friends? Eagles may soar, but weasels don't get sucked into jet engines. If at first you don't succeed, destroy all evidence that you tried.

            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
            "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

            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