Beispiel #1
0
 public void ReadMultipleVars(Int64 plcId, List <DataItem> nodes)
 {
     if (PlcDic.ContainsKey(plcId))
     {
         var plc = PlcDic[plcId];
         if (plc.IsConnected)
         {
             plc.ReadMultipleVars(nodes);
         }
     }
 }
Beispiel #2
0
 public object Read(Int64 plcId, DataItem node)
 {
     if (PlcDic.ContainsKey(plcId))
     {
         var plc = PlcDic[plcId];
         if (node.BitAdr == 0)
         {
             return(plc.Read(node.DataType, node.DB, node.StartByteAdr, node.VarType, node.Count));
         }
         else
         {
             return(plc.Read(node.DataType, node.DB, node.StartByteAdr, node.VarType, node.Count, node.BitAdr));
         }
     }
     else
     {
         return(null);
     }
 }
Beispiel #3
0
        public async Task ConnectAsync(Channel channel)
        {
            if (channel == null)
            {
                return;
            }

            if (!PlcDic.ContainsKey(channel.Id))
            {
                try
                {
                    var _p = new Plc(DataTypeHelper.GetPlcType(channel.CpuType), channel.IP, channel.Port, channel.Rack, channel.Slot);
                    await _p.OpenAsync();

                    PlcDic.Add(channel.Id, _p);

                    channel.IsAvailable = true;
                    channel.IsConnected = true;//PlcDic[channel.Id].IsConnected;
                }
                catch (Exception ex)
                {
                    channel.Message     = ex.ToString();
                    channel.IsAvailable = false;
                    channel.IsConnected = false;
                }
            }
            else
            {
                try
                {
                    await PlcDic[channel.Id].OpenAsync();
                    channel.IsAvailable = true;
                    channel.IsConnected = true;// PlcDic[channel.Id].IsConnected;
                }
                catch (Exception ex)
                {
                    channel.Message     = ex.ToString();
                    channel.IsAvailable = false;
                    channel.IsConnected = false;
                }
            }
        }