Exemplo n.º 1
0
        protected string ReadString(TCustomTKDevice device, ArrayCharOfTag tag)
        {
            byte[] buffer = new byte[tag.Length];
            int    resNo  =
                CS7TcpClient.ReadString(
                    plcHandle,
                    (int)tag.DB_Type,
                    device.DBNumber,
                    tag.DB_Offset,
                    (short)tag.Length,
                    buffer);

            return(Encoding.Default.GetString(buffer));
        }
Exemplo n.º 2
0
 public void AddDevice(TCustomTKDevice device)
 {
     device.OnWriteback += new S7WriteBackHandler(WritebackToPLC);
     devices.Add(device);
 }
Exemplo n.º 3
0
        /// <summary>
        /// 回写到 PLC 中
        /// </summary>
        private void WritebackToPLC(TCustomTKDevice device, CustomTagTest tag)
        {
            if (tag is BoolOfTag)
            {
                BoolOfTag ltag = tag as BoolOfTag;

                CS7TcpClient.WriteBool(
                    plcHandle,
                    0x84,
                    device.DBNumber,
                    ltag.DB_Offset,
                    ltag.Position,
                    Convert.ToUInt16(ltag.Value));
            }
            else if (tag is ByteOfTag)
            {
                ByteOfTag ltag = tag as ByteOfTag;

                CS7TcpClient.WriteByte(
                    plcHandle,
                    0x84,
                    device.DBNumber,
                    ltag.DB_Offset,
                    ltag.Value);
            }
            else if (tag is WordOfTag)
            {
                WordOfTag ltag = tag as WordOfTag;

                CS7TcpClient.WriteWord(
                    plcHandle,
                    0x84,
                    device.DBNumber,
                    ltag.DB_Offset,
                    (uint)ltag.Value);
            }
            else if (tag is DWordOfTag)
            {
                DWordOfTag ltag = tag as DWordOfTag;

                CS7TcpClient.WriteDWord(
                    plcHandle,
                    0x84,
                    device.DBNumber,
                    ltag.DB_Offset,
                    (uint)ltag.Value);
            }
            else if (tag is ArrayCharOfTag)
            {
                ArrayCharOfTag ltag = tag as ArrayCharOfTag;

                string temp = ltag.Value.PadRight(ltag.Length, ' ').Substring(0, ltag.Length);
                CS7TcpClient.WriteBlockAsByte(
                    plcHandle,
                    0x84,
                    device.DBNumber,
                    ltag.DB_Offset,
                    ltag.Length,
                    Encoding.Default.GetBytes(temp));
            }
        }