Click here to Skip to main content
Click here to Skip to main content
Go to top

Graphical Analysis of Process Control Program

, 11 Feb 2007
Rate this:
Please Sign up or sign in to vote.
This mathematical program uses explicit conversion and graphical display
Sample image

Introduction

Mathematical programs can be made more interesting when they use graphics to display their results. I use the graphics in C# to draw a representative diagram of the calculation. This calculation is used for Process Control. An instrumentation transmitter is calibrated to output 4 - 20 Milliamps when measuring a typical column of water. Let's say this column of water is a 0" - 120" span of H2O. The calculation will tell us what delta Milliamps should be output for the given percentage process span, or what delta process span is needed to give us the output delta Milliamps. This will allow us to calibrate our instrument. We generally check calibration at 0 %, 25 %, 50 %, 75 %, and 100 % levels of the process span.

Explicit Conversion

A numerical value must be a string value to be displayed. When that value is used in a calculation, it must be Converted Explicitly. I use a double variable type as it allows decimal places that will be produced by division.

delta1 = Double.Parse(txtDelta1.Text);
delta3 = span2 * ( delta1/ span1);

Data Validation

Interestingly enough, those same lines of code will take care of most of our Data Validation for us. If Double.Parse throws an exception, the code in our catch block will run.

catch(Exception w)
{
    MessageBox.Show(w.ToString(), "Important", MessageBoxButtons.OK,
        MessageBoxIcon.Stop);
}

The next part of our Data Validation is to ensure that our delta falls within the limits of our span. Otherwise, division by zero, or even memory overflow could occur. Actually, at one time, people considered both of these errors to be one and the same thing.

if ( double.Parse( txtDelta1.Text ) >= 0 )
{
    if ( double.Parse( txtDelta1.Text ) <= span1 )
    {
        blue = false;
        delta1 = Double.Parse(txtDelta1.Text);
        delta3 = span2 * ( delta1/ span1);
        span4 = Double.Parse(txtSpan2a.Text);
        txtDelta2.Text = delta3.ToString();
        Answere2 = delta3 + span4;
        lblAnswere2.Text = txtDelta2.Text.ToString()  + 
            " + " +   txtSpan2a.Text.ToString() + 
            " = " + Answere2.ToString();
        lblAnswere2Unit.Visible = true;
    }
    else
    {
        MessageBox.Show("Delta must be within Span limits",
            "Important", MessageBoxButtons.OK, MessageBoxIcon.Stop);
    }
}
else
{
    MessageBox.Show("Delta must be within Span limits",
        "Important", MessageBoxButtons.OK, MessageBoxIcon.Stop);
}

Graphics

Graphics can be manipulated by calculation as well. Here, we convert explicitly to Int32 type variable. We do this because this conversion process will round a double type variable to an integer value.

// Graphics
Graphics graph = this.CreateGraphics();
Pen pen = new Pen(Color.Red);
                    
//Red Line
if( blue == true)
{
    //Red Line
    int line2 = Convert.ToInt32(delta2/ span2 * 200) + 350;
    graph.DrawLine( pen, line2, 435, line2, 615);
}
else
{
    int line = Convert.ToInt32(delta1/ span1 * 200) + 350;
    graph.DrawLine( pen, line, 435, line, 615);
}

Conclusion

There is a lot left to do with this program, but I hope this helps you through "conversion hell". Feel free to develop software as you desire. This code is your code.

History

  • 11th February, 2007: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

David A Brighton
Web Developer
United States United States
I started programming in High School writing Fortran IV on punch cards using a keypunch machine. When I moved to Las Vegas I studied IBM AS-400, and RPG. This was when Windows was really taking over, so I switched to VB-6, then VB.Net, and C#.Net.
 
I have really enjoyed the .Net Platform, and it still amazes me every time I am inspired to the point of writing a new program.
 
Thanks All ! for giving me the time and patience.

Comments and Discussions

 
Generalerror input string not in correct format Pinmemberwinheart22-Apr-07 21:19 
Question???? PinmemberV. Thieme11-Feb-07 21:59 
1. you shouldn't include absolute paths (WATER.ICO couldn't be found)
2. the project MyProcessControllTech is missing
3. the "calculation" could be made with ink and paper within seconds.
 


 
*************************
Do, ut des.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140926.1 | Last Updated 11 Feb 2007
Article Copyright 2007 by David A Brighton
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid