PC Program that reads VEX serial port

I’ve never heard of that before. What exactly is a two state button?

I was looking for a Button that the Text would change when it was “clicked”. I found a way to force the text (and Background Color) to change…

Please note!! I am not a C# programmer… But after a couple hours of looking through the MicroSoft Visual Studio 2008 documentation (which was not too bad) and the Internet, I have what you see attached here…

  1. The COM Port Button, still Opens and Closes the COM Port, but it will change Color, Button is Green when Closed, Red when Open. The Text on the Button also changes with the State of the COM Port.

  2. If the COM Port is not installed, there will be an Exception Dialog Box Message, “The port ‘COMx’ does not exist.”.

  3. If the COM Port is in use, there will be a Exception Dialog Box Message, “Access to the port ‘COMx’ is denied.”.

All other activity is Identical and should work as before… I am still testing the Reading of the Serial Port…
VexSerialPortReader2.zip (503 KB)

Very nice! I never knew how to change the color of a button. I’m definitely going to keep that in mind.

As long as you are not Red/Green Color Blind, it gives you an additional indicator of the State of the COM Port.

If you do a Right Click on the Button and Select Properties, you can look at the Various Colors for each Mode under the Appearance Property. When you try to Edit the Color Name, you will get a Drop Down, with Three Tabs, “Custom”, “Web”, “System”. The Names you can Select from each of these Tabs, seem to available to use in the Code, Like:


            clickedButton.BackColor = System.Drawing.Color.LimeGreen;

I am working on a Variation for the Vex On-Line Code…

https://vexforum.com/attachment.php?attachmentid=1836&stc=1&d=1245967292

I am having Issues with the Button States, since I can only manipulate the Button, after that Button has been pressed, and can not change the States of the Other Buttons.

Also, I need to find out how the Code:


// assigns the data coming in from the serial port to the variable 'data'
data = serialPort1.ReadExisting();

// displays the contents of 'data' in textBox1
textBox1.Text = data.ToString();
  

Can be done on a Timer, verses on a Button Press…

Also, on your Code, I wrapped the above code with:


if (serialPort1.IsOpen)
{

......
           
}

So that a Exception would not be Thrown if you Press the “Read Data” Button, before Opening a COM Port.

The proper way to do that is to Grey Out the “Read Data” Button, if it not a Valid Action. I can set the “Read Data” Button to Greyed Out by Default, but as I stated above, I can currently change the State of a Button only, after it has been Pressed, and if it is Greyed Out, You can not Press It.

I need to discover how to Manipulate the State of a Button(s), based on other Criteria.
Serial_Port_Reader-OLCV.jpg

If you need to use a timer, just drag the timer (from the toolbox) into your form. In it’s properties window you can set it to enabled or use the code


timer1.Enabled = true;

Then set it’s interval (also in the properties window) to what ever you would like - I believe it’s in milliseconds.

Double click the timer and it will create code similar to this:

private void timer1_Tick(object sender, EventArgs e)
        {
            //code that you want to execute every interval goes here
        }

I believe that should work.

I found this in the Helps:



         private void InitializeTimer() 
         {
            //' Run this procedure in an appropriate event.
            // Set to 1 second.
            Timer1.Interval = 1000;
            // Enable timer.
            Timer1.Enabled = true;
            Button1.Text = "Stop";
        } 

        private void Timer1_Tick(object Sender, EventArgs e)
        {
            // Set the caption to the current time.
            Label1.Text = DateTime.Now.ToString();
         }  

From:
"How to: Run Procedures at Set Intervals with the Windows Forms Timer Component "
ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/dv_fxmclictl/html/8025247a-2de4-4d86-b8ab-a8cb8aeab2ea.htm

I added the Init to the:


        private void Form1_Load(object sender, EventArgs e)
        {

        ...

        }


I did it the hard way, by cutting and pasting… :wink: