示例#1
0
 public override bool WriteInternal <T>(List <T> value, Dictionary <string, string> parm)
 {
     lock (lockObject)
     {
         try
         {
             int address = -1;
             if (parm.ContainsKey("Start"))
             {
                 address = All.Class.Num.ToUshort(parm["Start"]);
             }
             if (parm.ContainsKey("Address"))
             {
                 address = All.Class.Num.ToUshort(parm["Address"]);
             }
             if (address < 0)
             {
                 All.Class.Error.Add("当前写入数据,起始地址不存在,无法写入");
                 return(false);
             }
             SSMeter.SSWriteMeter.WriteDataStyle ds = new SSMeter.SSWriteMeter.WriteDataStyle(
                 All.Class.TypeUse.GetType <T>(), address, value);
             byte[] readBuff;
             if (WriteAndRead <byte[], byte[]>(ds.GetBytes <T>(), 6, out readBuff, parm))
             {
                 SSMeter.SSWriteMeter.WriteResultStyle rs = SSMeter.SSWriteMeter.WriteResultStyle.Parse(readBuff);
                 if (rs == null || rs.Random != ds.Random || !rs.Result)
                 {
                     return(false);
                 }
             }
             else
             {
                 return(false);
             }
         }
         catch (Exception e)
         {
             All.Class.Error.Add(e);
             return(false);
         }
         return(true);
     }
 }
示例#2
0
        private void Parent_GetArgs(object sender, Communicate.Base.Base.ReciveArgs reciveArgs)
        {
            lock (lockObject)
            {
                Communicate.Communicate parent = (Communicate.Communicate)sender;
                int    len = parent.DataRecive;
                byte[] buff;
                if (len > 0 && this.Read <byte[]>(len, out buff))
                {
                    SSMeter.SSWriteMeter.WriteDataStyle ds = SSMeter.SSWriteMeter.WriteDataStyle.Parse(buff);
                    if (ds == null)
                    {
                        return;
                    }
                    SSMeter.SSWriteMeter.WriteResultStyle rs = new SSMeter.SSWriteMeter.WriteResultStyle(ds.Random, false);
                    if (ds.Value != null)
                    {
                        rs.Result = true;
                        switch (ds.Type)
                        {
                        case Class.TypeUse.TypeList.Boolean:
                            tmpBool = (List <bool>)ds.Value;
                            for (int i = ds.Start; i < boolValue.Length && i < ds.Start + tmpBool.Count; i++)
                            {
                                boolValue[i] = tmpBool[i - ds.Start];
                            }
                            break;

                        case Class.TypeUse.TypeList.Byte:
                            tmpByte = (List <byte>)ds.Value;
                            for (int i = ds.Start; i < byteValue.Length && i < ds.Start + tmpByte.Count; i++)
                            {
                                byteValue[i] = tmpByte[i - ds.Start];
                            }
                            break;

                        case Class.TypeUse.TypeList.DateTime:
                            tmpDateTime = (List <DateTime>)ds.Value;
                            for (int i = ds.Start; i < dateTimeValue.Length && i < ds.Start + tmpDateTime.Count; i++)
                            {
                                dateTimeValue[i] = tmpDateTime[i - ds.Start];
                            }
                            break;

                        case Class.TypeUse.TypeList.Double:
                            tmpDouble = (List <double>)ds.Value;
                            for (int i = ds.Start; i < doubleValue.Length && i < ds.Start + tmpDouble.Count; i++)
                            {
                                doubleValue[i] = tmpDouble[i - ds.Start];
                            }
                            break;

                        case Class.TypeUse.TypeList.Float:
                            tmpFloat = (List <float>)ds.Value;
                            for (int i = ds.Start; i < floatValue.Length && i < ds.Start + tmpFloat.Count; i++)
                            {
                                floatValue[i] = tmpFloat[i - ds.Start];
                            }
                            break;

                        case Class.TypeUse.TypeList.Int:
                            tmpInt = (List <int>)ds.Value;
                            for (int i = ds.Start; i < intValue.Length && i < ds.Start + tmpInt.Count; i++)
                            {
                                intValue[i] = tmpInt[i - ds.Start];
                            }
                            break;

                        case Class.TypeUse.TypeList.Long:
                            tmpLong = (List <long>)ds.Value;
                            for (int i = ds.Start; i < longValue.Length && i < ds.Start + tmpLong.Count; i++)
                            {
                                longValue[i] = tmpLong[i - ds.Start];
                            }
                            break;

                        case Class.TypeUse.TypeList.String:
                            tmpString = (List <string>)ds.Value;
                            for (int i = ds.Start; i < stringValue.Length && i < ds.Start + tmpString.Count; i++)
                            {
                                stringValue[i] = tmpString[i - ds.Start];
                            }
                            break;

                        case Class.TypeUse.TypeList.UShort:
                            tmpUshort = (List <ushort>)ds.Value;
                            for (int i = ds.Start; i < ushortValue.Length && i < ds.Start + tmpUshort.Count; i++)
                            {
                                ushortValue[i] = tmpUshort[i - ds.Start];
                            }
                            break;
                        }
                    }
                    if (parent is Communicate.Udp)
                    {
                        Dictionary <string, string> parm = new Dictionary <string, string>();
                        parm.Add("RemotHost", reciveArgs.RemotIP);
                        parm.Add("RemotPort", reciveArgs.RemotPort.ToString());
                        parent.Send <byte[]>(rs.GetBytes(), parm);
                    }
                    else
                    {
                        parent.Send <byte[]>(rs.GetBytes());
                    }
                }
            }
        }