# use LIBNODAVE read data from S7 200 with PPI



## changjeff (20 November 2017)

Hi：
I want to read data from s7 200  serial port by libnodave.I find that sometimes read normally,sometiems read error return -1025 show timeout when continuous read .why ?I writed by C# and delphi ,but results are the same .ppi cable is diy .

thanks,everybody!

//********************C# ******************

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;




namespace PPI
{
    public partial class Form1 : Form
    {
        static libnodave.daveOSserialType fds;
        static libnodave.daveInterface di;
        static libnodave.daveConnection dc;
        static int localPPI = 0;
        static int PLCPPI = 2;
        static int abc = 0;
        public Form1()
        {
            InitializeComponent();
        }


        private void button1_Click(object sender, EventArgs e)
        {
            fds.rfd = libnodave.setPort("COM3", "9600", 'E');
            fds.wfd = fds.rfd;
            if (fds.rfd > 0)
            {
                di = new libnodave.daveInterface(fds, "IF1", localPPI, libnodave.daveProtoPPI, libnodave.daveSpeed187k);
                di.setTimeout(2000000);
            //    di.initAdapter();
                dc = new libnodave.daveConnection(di, PLCPPI, 0, 0);
                if (0 == dc.connectPLC())
                {
                    btn_Start.Enabled = false;
                    btn_Stop.Enabled = true;
                    timer1.Enabled = true;
                };

            }
            else
            {
                MessageBox.Show("串口打开错误");
            }

        }


        private void btn_Stop_Click(object sender, EventArgs e)
        {
            dc.disconnectPLC();
            libnodave.closePort(fds.rfd);
            timer1.Enabled = false;
            btn_Start.Enabled = true;
            btn_Stop.Enabled = false;
        }


        private void timer1_Tick(object sender, EventArgs e)
        {
            int res = 0;
            byte[] values=new byte[4];
            values[0] = 0;
            values[1] = 0;
            values[2] = 0;
            values[3] = 0;
            res = dc.readBytes(libnodave.daveFlags, 0, 0, 4, values);
            if (res == 0)
            {
                // dc.getS8().ToString()
                //    Form1.text = dc.getS8().ToString();
                lbl_MB0.Text = values[0].ToString();
                abc = abc + 1;
                label5.Text = abc.ToString();
            }
            else
                lbl_MB0.Text = res.ToString();
        }
    }
}


----------

