Auto generate Graph file from MySQL database To PDF when a PLC tag goe

  • (2 Pages)
  • +
  • 1
  • 2

18 Replies - 858 Views - Last Post: 02 July 2019 - 02:26 PM

#16 brandonm222   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 18-October 14

Re: Auto generate Graph file from MySQL database To PDF when a PLC tag goe

Posted 26 June 2019 - 03:25 PM

Sorry your right I should have mentioned that part. But yes someone needs to approve it. But ok I see it all making sense now. To break it down this is my plan:

1. Create a program which grabs information from the MySQL database one executable for each CIP system. Meaning I will need to have ODBC connector in there to connect to database.

2. The information will be displayed in three different graphs for temp, flow, and cond. Meaning this will be not a terminal application but rather an Object Oriented C# application. (Correct me if I am wrong here)

3. Create a condition in there that if it sees the completed tag from the PLC to generate a PDF report. Meaning I will need to have OPC connector in there to connect to the PLC

4. Using windows task scheduler have this program launch every 2 minutes. Look for this tag and if the tag is not found set to high close and start again. If it does see it create PDF and set report complete tag in PLC to high.

Does this sound about right?

And haha yes AI is the next step but for now people want it fast without actually needing it fast. In reality your right they can wait 1 minute even 10 if it goes to that. But just to make sure it's possible when the wish lists come in is why I am asking. You know the whole mouse and cheese saying.
Was This Post Helpful? 0
  • +
  • -

#17 brandonm222   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 18-October 14

Re: Auto generate Graph file from MySQL database To PDF when a PLC tag goe

Posted 01 July 2019 - 09:44 PM

Ok so I have gone ahead and done all my steps. My problem is now the export to pdf. I have gotten it to work using a screenshot and PDFSharp. However, my problem is that what if for some reason that screen is not the main screen when the it takes a screenshot it'll take a screenshot of something else and save that as the report. Is there a way to save directly the form or even go one step further and save certain parts of the form. I found this doing my search but I don't know what my next step would be:

public void SaveToPdf()
        {
            Document document = new Document();
            PdfWriter.GetInstance(document, new FileStream("E:/a.pdf", FileMode.Create));
            document.Open();
            Paragraph p = new Paragraph();
            document.Add(p);
            document.Add("DONT KNOW WHAT THE SYNTAX FOR CHART WOULD BE")
            document.Close();
        }


Was This Post Helpful? 0
  • +
  • -

#18 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 6992
  • View blog
  • Posts: 23,765
  • Joined: 05-May 12

Re: Auto generate Graph file from MySQL database To PDF when a PLC tag goe

Posted 02 July 2019 - 03:49 AM

View Postbrandonm222, on 02 July 2019 - 12:44 AM, said:

My problem is now the export to pdf. I have gotten it to work using a screenshot and PDFSharp.

Yikes! If you were taking a screenshot, why even export as PDF. Just save a bitmap.

All along I assumed that you were querying the database, collating the the data and and then rendering the graph directly into PDF. Anyway, PDFSharp has some sample code on how to draw various graphic elements. You'll need to take your code that draws your chart to the screen and port it over to drawing to a PDF. If you wrote your code following SOLID object oriented principles, you would use Liskov Substitution Principle (the 'L' in SOLID) to be able to replace the screen drawing code with PDF drawing code.
Was This Post Helpful? 0
  • +
  • -

#19 brandonm222   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 18-October 14

Re: Auto generate Graph file from MySQL database To PDF when a PLC tag goe

Posted 02 July 2019 - 02:26 PM

I was actually thinking of going down the option of Creating the three different charts and then saving each one as a picture and then putting those three pictures in to one PDF file. Then deleting the pictures once complete this way I can visually see everything just incase I have done something wrong. My only problem I am having so far is that when I create the chart it plots everything correctly but I get a line going from the first point to the last. Here is my code for that part:

public void LoadChart()
        {
            MySql.Data.MySqlClient.MySqlConnection conn;
            string myConnectionString;

            myConnectionString = "server=127.0.0.1;uid=root;" +
                "pwd=password;database=test";

            try
            {
                conn = new MySql.Data.MySqlClient.MySqlConnection();
                conn.ConnectionString = myConnectionString;
                conn.Open();
            }
            catch (MySql.Data.MySqlClient.MySqlException ex)
            {
                MessageBox.Show(ex.Message);
            }



            MySqlConnection conDataBase = new MySqlConnection(myConnectionString);
            MySqlCommand cmdDataBase = new MySqlCommand("select * from reporttesting;", conDataBase);
            MySqlDataReader myReader;
            try
            {
                conDataBase.Open();
                myReader = cmdDataBase.ExecuteReader();

                while (myReader.Read())
                {
                    chart1.Series["Series1"].Points.InsertXY(0, myReader.GetDateTime("Cond"), myReader.GetInt32("Temp"));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            conDataBase.Close();
        }


What am I doing wrong?
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2