コード例 #1
0
        protected float ReadSingle(DeviceAdress adress)
        {
            S7Adress signalAdress = (S7Adress)adress;
            float    result       = (float)plc.Read((DataType)signalAdress.dataType, signalAdress.dbAdress, signalAdress.startAdress, VarType.Real, 1);

            return(result);
        }
コード例 #2
0
        protected string ReadString(DeviceAdress adress, ushort length)
        {
            S7Adress signalAdress = (S7Adress)adress;
            string   result       = (string)plc.Read((DataType)signalAdress.dataType, signalAdress.dbAdress, signalAdress.startAdress, VarType.String, length);

            return(result);
        }
コード例 #3
0
        protected int ReadInt32(DeviceAdress adress)
        {
            S7Adress signalAdress = (S7Adress)adress;
            int      result       = (int)plc.Read((DataType)signalAdress.dataType, signalAdress.dbAdress, signalAdress.startAdress, VarType.DInt, 1);

            return(result);
        }
コード例 #4
0
        protected long ReadInt64(DeviceAdress adress)
        {
            S7Adress signalAdress = (S7Adress)adress;
            long     result       = (long)plc.Read((DataType)signalAdress.dataType, signalAdress.dbAdress, signalAdress.startAdress, VarType.DWord, 1);

            return(result);
        }
コード例 #5
0
        protected short ReadInt16(DeviceAdress adress)
        {
            S7Adress signalAdress = (S7Adress)adress;
            short    result       = (short)plc.Read((DataType)signalAdress.dataType, signalAdress.dbAdress, signalAdress.startAdress, VarType.Int, 1);

            return(result);
        }
コード例 #6
0
        protected double ReadDouble(DeviceAdress adress)
        {
            S7Adress signalAdress = (S7Adress)adress;

            byte[] result = (byte[])plc.Read((DataType)signalAdress.dataType, signalAdress.dbAdress, signalAdress.startAdress, VarType.DInt, signalAdress.byteCount);
            return(result[0]);
        }
コード例 #7
0
        protected byte ReadByte(DeviceAdress adress)
        {
            S7Adress signalAdress = (S7Adress)adress;
            byte     result       = (byte)plc.Read((DataType)signalAdress.dataType, signalAdress.dbAdress, signalAdress.startAdress, VarType.Byte, 1);

            return(result);
        }
コード例 #8
0
        protected bool ReadBoolean(DeviceAdress adress)
        {
            S7Adress signalAdress = (S7Adress)adress;
            bool     result       = (bool)plc.Read((DataType)signalAdress.dataType, signalAdress.dbAdress, signalAdress.startAdress, VarType.Bit, 1);

            return(result);
        }
コード例 #9
0
 public override void WriteOutputSignal(string signalName, object value)
 {
     if (Outputs.ContainsKey(signalName))
     {
         AdressValueInfo output       = (AdressValueInfo)Outputs[signalName];
         S7Adress        signalAdress = (S7Adress)output.adress;
         plc.Write((DataType)signalAdress.dataType, signalAdress.dbAdress, signalAdress.startAdress, value);
     }
 }
コード例 #10
0
 protected override void WriteRealTimeSignal()
 {
     if (outputThreadRun)
     {
         return;
     }
     outputThreadRun = true;
     while (IsConnect() && outputThreadRun)
     {
         S7Adress signalAdress = (S7Adress)startOutputsAdress;
         plc.WriteBytes((DataType)signalAdress.dataType, signalAdress.dbAdress, signalAdress.startAdress, SynOutputs);
         Thread.Sleep(100);
     }
 }
コード例 #11
0
        protected override void ReadRealTimeSignal()
        {
            if (inputThreadRun)
            {
                return;
            }
            inputThreadRun = true;
            S7Adress startAdress = (S7Adress)startInputsAdress;

            while (IsConnect() && inputThreadRun)
            {
                SynInputs = plc.ReadBytes((DataType)startAdress.dataType, startAdress.dbAdress, startAdress.startAdress, startAdress.byteCount);
                Thread.Sleep(100);
            }
        }
コード例 #12
0
        public void ReadAressFile(string filePath)
        {
            string path = System.Environment.CurrentDirectory;

            path = filePath + "\\S7Adress";
            if (!File.Exists(path))
            {
                throw new Exception("配置文件不存在!");
            }
            using (StreamReader sr = new StreamReader(path)) {
                var line = sr.ReadLine();
                while (line != null)
                {
                    line = sr.ReadLine();
                    string[] strs = line.Split(',');
                    if (strs[0] != "No" && strs[0] != string.Empty)
                    {
                        if (strs[(int)eS7AdresssTitle.IsInput].Trim(' ') == "1")
                        {
                            S7Adress adress = new S7Adress();
                            adress.startAdress = Convert.ToInt32(strs[(int)eS7AdresssTitle.StartAdress]);
                            adress.dbAdress    = Convert.ToInt32(strs[(int)eS7AdresssTitle.DBAdress]);
                            adress.dataType    = GetAdressDataType(strs[(int)eS7AdresssTitle.DataType]);
                            AdressValueInfo valueInfo = new AdressValueInfo()
                            {
                                adress      = adress,
                                deviceValue = new S7Value(),
                                length      = Convert.ToUInt16(strs[(int)eS7AdresssTitle.ByteCount]),
                                valueType   = GetAdressType(strs[(int)eS7AdresssTitle.AdressType]),
                            };
                            this.AddInputSignal(strs[(int)eS7AdresssTitle.AdressName], valueInfo);
                        }
                        if (strs[(int)eS7AdresssTitle.IsOutput].Trim(' ') == "1")
                        {
                        }
                    }
                }
            }
        }