private void S7_Device_Initialize()
        {
            libnoInstance.write_bit_value(address, 61, 1, 3, true); //enable 2d matrix read in STN2   DB61.DBX1.3

            if (libnoInstance.read_bit_value(address, 61, 2, 6).ToString().ToUpper() != "FALSE")
            {
                libnoInstance.write_bit_value(address, 61, 2, 6, true); //Enable traceability server communication on Stn 2
                fillcombo2();
            }
        }
Beispiel #2
0
        private void S7_Device_Initialize()
        {
            libnoInstance.write_bit_value(address, 61, 0, 1, true); //enable 2d matrix read in STN1

            if (libnoInstance.read_bit_value(address, 61, 2, 5).ToString().ToUpper() != "FALSE")
            {
                libnoInstance.write_bit_value(address, 61, 2, 5, true); //Enable traceability server communication on Stn 1
                fillcombo1();
            }

            libnoInstance.write_bit_value(address, 61, 2, 7, true); //Select english language in WINCC
        }
Beispiel #3
0
        private static void user_cycle(LibnoDaveClass libno)
        {
            string optionQuestion = Environment.NewLine +
                                    "Choose one of the options below:" + Environment.NewLine +
                                    "1: Read bytes" + Environment.NewLine +
                                    "2: Write bytes" + Environment.NewLine +
                                    "3: Read bit" + Environment.NewLine +
                                    "4: Write bit" + Environment.NewLine +
                                    "5: Read integers" + Environment.NewLine +
                                    "6: Write integers" + Environment.NewLine +
                                    "7: Read real/float values" + Environment.NewLine +
                                    "8: Write real/float values" + Environment.NewLine +
                                    "Enter the number";
            string optionReq = ask_user_input(optionQuestion);

            LibnoDaveClass.AddressType address; LibnoDaveClass.PLCDataType dataType;
            int           dbNo, byteNo, bitNo, length;
            List <string> readByteList, writeByteList; List <int> readIntList, writeIntList; List <float> readFloatList, writeFloatList;
            bool          readBit, writeBit, isSigned;

            switch (optionReq)
            {
            case "1":
                string addressType  = ask_user_input("Which address type do you want to read? (M for Memory, D for DB)");
                string dbNumber     = ask_user_input("Enter DB address of the registers. (0 for Memory address)");
                string byteNumber   = ask_user_input("Enter the starting address of the registers");
                string lengthNumber = ask_user_input("Enter the byte length of the registers");

                address = addressType == "M" ? LibnoDaveClass.AddressType.Memory : LibnoDaveClass.AddressType.DB;
                int.TryParse(dbNumber, out dbNo);
                int.TryParse(byteNumber, out byteNo);
                int.TryParse(lengthNumber, out length);

                if (libno.read_byte_values(address, dbNo, byteNo, length, out readByteList))
                {
                    print_message("Process is successful!");
                    print_message("Bytes that were read are:");
                    for (int i = 0; i < readByteList.Count; i++)
                    {
                        Console.WriteLine("Byte-" + i + " is " + readByteList[i]);
                    }
                }
                else
                {
                    print_message("Some errors occured. Try to connect to PLC again..");
                }
                break;

            case "2":
                string addressType2 = ask_user_input("Which address type do you want to write? (M for Memory, D for DB)");
                string dbNumber2    = ask_user_input("Enter DB address of the registers. (0 for Memory address)");
                string byteNumber2  = ask_user_input("Enter the starting address of the registers");
                string writeList    = ask_user_input("Enter byte values in 8-bit format and put ':' between bytes");

                address = addressType2 == "M" ? LibnoDaveClass.AddressType.Memory : LibnoDaveClass.AddressType.DB;
                int.TryParse(dbNumber2, out dbNo);
                int.TryParse(byteNumber2, out byteNo);
                writeByteList = new List <string>();
                writeByteList = writeList.Split(':').ToList();

                if (libno.write_byte_values(address, dbNo, byteNo, writeByteList))
                {
                    print_message("Process is successful!");
                }
                else
                {
                    print_message("Some errors occured. Try to connect to PLC again..");
                }
                break;

            case "3":
                string addressType3 = ask_user_input("Which address type do you want to read? (M for Memory, D for DB, I for Input, O for Output)");
                string dbNumber3    = ask_user_input("Enter DB address of the register. (0 for Memory, Input or Output address)");
                string byteNumber3  = ask_user_input("Enter the byte address of the register");
                string bitNumber3   = ask_user_input("Enter the bit address of the register");

                address = addressType3 == "M" ? LibnoDaveClass.AddressType.Memory :
                          addressType3 == "D" ? LibnoDaveClass.AddressType.DB :
                          addressType3 == "I" ? LibnoDaveClass.AddressType.Input :
                          LibnoDaveClass.AddressType.Output;
                int.TryParse(dbNumber3, out dbNo);
                int.TryParse(byteNumber3, out byteNo);
                int.TryParse(bitNumber3, out bitNo);

                if (libno.read_bit_value(address, dbNo, byteNo, bitNo, out readBit))
                {
                    print_message("Process is successful!");
                    print_message("Bit that was read is: " + readBit.ToString());
                }
                else
                {
                    print_message("Some errors occured. Try to connect to PLC again..");
                }
                break;

            case "4":
                string addressType4  = ask_user_input("Which address type do you want to write? (M for Memory, D for DB, O for Output)");
                string dbNumber4     = ask_user_input("Enter DB address of the register. (0 for Memory or Output address)");
                string byteNumber4   = ask_user_input("Enter the byte address of the register");
                string bitNumber4    = ask_user_input("Enter the bit address of the register");
                string writeBitValue = ask_user_input("Enter the bit value of the register (1 for true, 0 for false)");

                address = addressType4 == "M" ? LibnoDaveClass.AddressType.Memory :
                          addressType4 == "D" ? LibnoDaveClass.AddressType.DB :
                          LibnoDaveClass.AddressType.Output;
                int.TryParse(dbNumber4, out dbNo);
                int.TryParse(byteNumber4, out byteNo);
                int.TryParse(bitNumber4, out bitNo);
                writeBit = writeBitValue == "1" ? true : false;

                if (libno.write_bit_value(address, dbNo, byteNo, bitNo, writeBit))
                {
                    print_message("Process is successful!");
                }
                else
                {
                    print_message("Some errors occured. Try to connect to PLC again..");
                }
                break;

            case "5":
                string addressType5  = ask_user_input("Which address type do you want to read? (M for Memory, D for DB)");
                string intType5      = ask_user_input("Which integer type do you want to read? (B for Byte, W for Word or Integer, D for D-Integer)");
                string dbNumber5     = ask_user_input("Enter DB address of the registers. (0 for Memory address)");
                string byteNumber5   = ask_user_input("Enter the starting address of the registers");
                string isSignedStr5  = ask_user_input("Are integer values signed (+/-) ? (y/n)");
                string lengthNumber5 = ask_user_input("Enter the number of integers");

                isSigned = isSignedStr5 == "y" ? true : false;
                address  = addressType5 == "M" ? LibnoDaveClass.AddressType.Memory : LibnoDaveClass.AddressType.DB;
                dataType = intType5 == "B" ? LibnoDaveClass.PLCDataType.Byte :
                           intType5 == "W" ? LibnoDaveClass.PLCDataType.Integer :
                           LibnoDaveClass.PLCDataType.DInteger;
                int.TryParse(dbNumber5, out dbNo);
                int.TryParse(byteNumber5, out byteNo);
                int.TryParse(lengthNumber5, out length);

                if (libno.read_integer_values(address, dbNo, byteNo, length, out readIntList, dataType, isSigned))
                {
                    print_message("Process is successful!");
                    print_message("Integers that were read are:");
                    for (int i = 0; i < readIntList.Count; i++)
                    {
                        Console.WriteLine("Int-" + i + " is " + readIntList[i].ToString());
                    }
                }
                else
                {
                    print_message("Some errors occured. Try to connect to PLC again..");
                }
                break;

            case "6":
                string addressType6 = ask_user_input("Which address type do you want to write? (M for Memory, D for DB)");
                string intType6     = ask_user_input("Which integer type do you want to write? (B for Byte, W for Word or Integer, D for D-Integer)");
                string dbNumber6    = ask_user_input("Enter DB address of the registers. (0 for Memory address)");
                string byteNumber6  = ask_user_input("Enter the starting address of the registers");
                string isSignedStr6 = ask_user_input("Are integer values signed (+/-) ? (y/n)");
                string writeInts    = ask_user_input("Enter int values and put ':' between integers");

                isSigned = isSignedStr6 == "y" ? true : false;
                address  = addressType6 == "M" ? LibnoDaveClass.AddressType.Memory : LibnoDaveClass.AddressType.DB;
                dataType = intType6 == "B" ? LibnoDaveClass.PLCDataType.Byte :
                           intType6 == "W" ? LibnoDaveClass.PLCDataType.Integer :
                           LibnoDaveClass.PLCDataType.DInteger;
                int.TryParse(dbNumber6, out dbNo);
                int.TryParse(byteNumber6, out byteNo);

                List <string> writeIntStrList = writeInts.Split(':').ToList();
                writeIntList = new List <int>();
                writeIntStrList.ForEach(x => writeIntList.Add(int.Parse(x)));

                if (libno.write_integer_values(address, dbNo, byteNo, writeIntList, dataType, isSigned))
                {
                    print_message("Process is successful!");
                }
                else
                {
                    print_message("Some errors occured. Try to connect to PLC again..");
                }
                break;

            case "7":
                string addressType7  = ask_user_input("Which address type do you want to read? (M for Memory, D for DB)");
                string dbNumber7     = ask_user_input("Enter DB address of the registers. (0 for Memory address)");
                string byteNumber7   = ask_user_input("Enter the starting address of the registers");
                string lengthNumber7 = ask_user_input("Enter the number of real/float values");

                address = addressType7 == "M" ? LibnoDaveClass.AddressType.Memory : LibnoDaveClass.AddressType.DB;

                int.TryParse(dbNumber7, out dbNo);
                int.TryParse(byteNumber7, out byteNo);
                int.TryParse(lengthNumber7, out length);

                if (libno.read_real_values(address, dbNo, byteNo, length, out readFloatList))
                {
                    print_message("Process is successful!");
                    print_message("Float values that were read are:");
                    for (int i = 0; i < readFloatList.Count; i++)
                    {
                        Console.WriteLine("Float-" + i + " is " + readFloatList[i].ToString());
                    }
                }
                else
                {
                    print_message("Some errors occured. Try to connect to PLC again..");
                }
                break;

            case "8":
                string addressType8 = ask_user_input("Which address type do you want to write? (M for Memory, D for DB)");
                string dbNumber8    = ask_user_input("Enter DB address of the registers. (0 for Memory address)");
                string byteNumber8  = ask_user_input("Enter the starting address of the registers");
                string writeFloats  = ask_user_input("Enter real/float values and put ':' between integers");

                address = addressType8 == "M" ? LibnoDaveClass.AddressType.Memory : LibnoDaveClass.AddressType.DB;

                int.TryParse(dbNumber8, out dbNo);
                int.TryParse(byteNumber8, out byteNo);

                List <string> writeFloatStrList = writeFloats.Split(':').ToList();
                writeFloatList = new List <float>();
                writeFloatStrList.ForEach(x => writeFloatList.Add(float.Parse(x)));

                if (libno.write_real_values(address, dbNo, byteNo, writeFloatList))
                {
                    print_message("Process is successful!");
                }
                else
                {
                    print_message("Some errors occured. Try to connect to PLC again..");
                }
                break;

            default:
                print_message("You entered an unexpected value. Please try again..");
                break;
            }
        }