libnodave C# Logo!8 VS2015 .net 4.0 x86 Verständnis fragen

Dragostanii

Level-1
Beiträge
1
Reaktionspunkte
0
Zuviel Werbung?
-> Hier kostenlos registrieren
Guten Abend,


Ich wollte mich mal wieder mit C# und meiner logo!8 beschäftigen.


Jedoch habe ich einige Verständnis Probleme.


Irgendwie funktioniert das Ganze nicht was ich nach und nach zusammen kopiert oder auch bearbeitet habe.


Hat da wer Ideen?

Code:
using System;using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace LOGOTest_libnodave
{
    public partial class Form1 : Form
    {
        static libnodave.daveOSserialType fds;
        static libnodave.daveInterface di;
        static libnodave.daveConnection dc;
        static int rack = 0; // LOGO
        static int slot = 0; // LOGO
        int LOGOInputs = 0, LOGOOutputs = 0, res;


        public Form1()
        {
            InitializeComponent();
            connectlogo();
            timer1.Interval = 500;
            timer1.Start();
        }


        public static bool CheckBitSet(byte b, int BitNumber)
        {
            //Kleine Fehlerbehandlung
            if (BitNumber < 8 && BitNumber > -1)
            {
                return (b & (1 << BitNumber)) > 0;
            }
            else
            {
                throw new InvalidOperationException(
                "Der Wert für BitNumber " + BitNumber.ToString() + " war nicht im zulässigen Bereich! (BitNumber = (min)0 - (max)7)");
            }


        }


        public void connectlogo()
        {
            fds.rfd = libnodave.openSocket(102, textBox1.Text.ToString());


            fds.wfd = fds.rfd;


            if (fds.rfd > 0)
            {


                di = new libnodave.daveInterface(fds, "IF1", 0, libnodave.daveProtoISOTCP, libnodave.daveSpeed187k);


                di.setTimeout(1000000);


                dc = new libnodave.daveConnection(di, 0, rack, slot);


                dc.connectPLC();
            }
        }


        public void disconnectlogo()
        {
            dc.disconnectPLC();
            libnodave.closeSocket(fds.rfd);
        }


        public void readlogo()
        {
            // Eingänge lesen
            res = dc.readBytes(libnodave.daveInputs, 0, 0, 3, null);




            if (res == 0)
            {


                LOGOInputs = dc.getU8();






                cbIn1.Checked = CheckBitSet((byte)LOGOInputs, 0);
                cbIn2.Checked = CheckBitSet((byte)LOGOInputs, 1);
                cbIn3.Checked = CheckBitSet((byte)LOGOInputs, 2);
                cbIn4.Checked = CheckBitSet((byte)LOGOInputs, 3);
                cbIn5.Checked = CheckBitSet((byte)LOGOInputs, 4);
                cbIn6.Checked = CheckBitSet((byte)LOGOInputs, 5);
                cbIn7.Checked = CheckBitSet((byte)LOGOInputs, 6);
                cbIn8.Checked = CheckBitSet((byte)LOGOInputs, 7);


            }
            else
                Console.WriteLine("Error " + res + " " + libnodave.daveStrerror(res));


            // Ausgänge lesen
            res = dc.readBytes(libnodave.daveOutputs, 0, 0, 3, null);


            if (res == 0)
            {
                LOGOOutputs = dc.getU8();


                cbOut1.Checked = CheckBitSet((byte)LOGOOutputs, 0);
                if (cbOut1.Checked) { tbOut1.BackColor = Color.Yellow; } else { tbOut1.BackColor = Color.Green; };
                cbOut2.Checked = CheckBitSet((byte)LOGOOutputs, 1);
                if (cbOut2.Checked) { tbOut2.BackColor = Color.Yellow; } else { tbOut2.BackColor = Color.Green; };
                cbOut3.Checked = CheckBitSet((byte)LOGOOutputs, 2);
                if (cbOut3.Checked) { tbOut3.BackColor = Color.Yellow; } else { tbOut3.BackColor = Color.Green; };
                cbOut4.Checked = CheckBitSet((byte)LOGOOutputs, 3);
                if (cbOut4.Checked) { tbOut4.BackColor = Color.Yellow; } else { tbOut4.BackColor = Color.Green; };


            }
            else
                Console.WriteLine("Error " + res + " " + libnodave.daveStrerror(res));
        }




        private void timer1_Tick(object sender, EventArgs e)
        {
            readlogo();
        }


    }
}
 
Zurück
Oben