locked
plotting a point graph for a continuous real time data in c# windows form application RRS feed

  • Question

  • I have  c# windows form application which displays the real time data from a board. I want to plot this data in a point graph in c#. Help me with this. I have given my code below which displays the data from board.

    namespace flowboard_v2
    {
        public partial class flow_click : Form
        {
            
            public flow_click()
            {
                InitializeComponent();
            }

            [DllImport("C:\\Users\\JivaSci\\Desktop\\fluigent\\bin\\SDK\\FRP\\C++\\Cpp_Windows\\frp_c_64.dll", CallingConvention = CallingConvention.StdCall)]
            public static extern UInt64 frp_initialization(ushort serial);
            [DllImport("C:\\Users\\JivaSci\\Desktop\\fluigent\\bin\\SDK\\FRP\\C++\\Cpp_Windows\\frp_c_64.dll", CallingConvention = CallingConvention.StdCall)]
            public static extern Int64 frp_get_serial(UInt64 handle, ref ushort serial, ref ushort version);
            [DllImport("C:\\Users\\JivaSci\\Desktop\\fluigent\\bin\\SDK\\FRP\\C++\\Cpp_Windows\\frp_c_64.dll", CallingConvention = CallingConvention.StdCall)]
            public static extern Int64 frp_close(UInt64 handle);
            [DllImport("C:\\Users\\JivaSci\\Desktop\\fluigent\\bin\\SDK\\FRP\\C++\\Cpp_Windows\\frp_c_64.dll", CallingConvention = CallingConvention.StdCall)]
            public static extern Int64 frp_read_flow(UInt64 handle, byte index, ref byte timestamp, ref float flow);
            [DllImport("C:\\Users\\JivaSci\\Desktop\\fluigent\\bin\\SDK\\FRP\\C++\\Cpp_Windows\\frp_c_64.dll", CallingConvention = CallingConvention.StdCall)]
            public static extern Int64 frp_data_FU(UInt64 handle, byte index, ref byte cal, ref byte res, ref byte artcod, ref byte sf, ref byte unit, ref byte tb);

            public void Test()
            {
               
                /* Flow board variable declaration */
                UInt64 frpHandle = 0;
                ushort Serial = 0;
                ushort Version = 0;

                /* Flow-rate acquisition variables */
                byte sensor_index = 0; // sensor index coresponds to flow-unit port on the flowboard from 0 to 7
                byte TimeCheck = 0;
                float flow_rate = 0;
                uint loop = 0;

                frpHandle = frp_initialization(0);

                RTBox.Text+=("\n FRP session initialized");
           

                frp_get_serial(frpHandle, ref Serial, ref Version);
                RTBox.Text += ("\n FLOWBOARD SN:" + Convert.ToInt32(Serial));
               

                if (Serial != 0)
                {
                  
                        frp_read_flow(frpHandle, sensor_index, ref TimeCheck, ref flow_rate);
                        RTBox.Text += ("\n Flow-rate:" + Convert.ToSingle(flow_rate) + "\t ul/min");
                        

                   
                }

                frp_close(frpHandle);
                RTBox.Text += ("\n FRP session closed");

            }

            private void button1_Click(object sender, EventArgs e)
            {

                Test();

            }

    Monday, November 25, 2019 9:46 AM

All replies

  • Hi varun_bwazz,
    >> [DllImport("C:\\Users\\JivaSci\\Desktop\\fluigent\\bin\\SDK\\FRP\\C++\\Cpp_Windows\\frp_c_64.dll", CallingConvention = CallingConvention.StdCall)]
    I can’t reuse your code, because you import other DLL in the project. So I made a demo that use the chart and timer to display the real time data and hope it useful for you.

    private Random Rand = new Random();
    private double Counter = 1;
    private void timer1_Tick(object sender, EventArgs e)
    {
        chart1.Series[0].Points.AddXY(Counter, Convert.ToDouble(Rand.Next(0, 20)));
        chart1.ChartAreas[0].AxisX.CustomLabels.Add(Counter - 1, Counter + 1, DateTime.Now.ToString("HH:mm:ss fff"));
        Counter += 1;
    }
    
    private void button1_Click(object sender, EventArgs e)
    {
        if (timer1.Enabled == false)
            timer1.Enabled = true;
        else
            timer1.Enabled = false;
    }
    private void Form1_Load(object sender, EventArgs e)
    {
        Location = new Point(Convert.ToInt32(Screen.PrimaryScreen.WorkingArea.Width / 2 - this.Width / 2), Convert.ToInt32(Screen.PrimaryScreen.WorkingArea.Height / 2 - this.Height / 2));
        chart1.ChartAreas[0].AxisX.Interval = 1;
        chart1.ChartAreas[0].AxisX.Minimum = 0;
        chart1.ChartAreas[0].AxisX.LabelStyle.Angle = 90;
        chart1.ChartAreas[0].AxisY.Interval = 1;
        chart1.ChartAreas[0].AxisY.Minimum = 0;
        chart1.Series[0].ChartType = SeriesChartType.Point;
        chart1.Series[0].IsVisibleInLegend = false;
        timer1.Interval = 1000;
    }

    Best Regards,
    Daniel Zhang


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, November 26, 2019 6:51 AM