Beispiel #1
0
        public int GetOutput(string outputName)
        {
            this.ValidateEditor();
            if (string.IsNullOrEmpty(outputName))
            {
                throw new ArgumentNullException(nameof(outputName));
            }
            OutputPinSocket pin = this.socket.Outputs.FirstOrDefault(o => o.Pin.Name == outputName);

            if (pin == null)
            {
                throw new CircuitException(Cause.UserError,
                                           string.Format(CultureInfo.InvariantCulture, "Output pin {0} not found on Logical Circuit {1}", outputName, this.logicalCircuitName)
                                           );
            }
            int value;

            if (FunctionProbe.ToInt(pin.Function.Pack(), pin.Pin.BitWidth, out value))
            {
                return(value);
            }
            throw new CircuitException(Cause.UserError,
                                       string.Format(CultureInfo.InvariantCulture,
                                                     "Output value cannot be represented by number because it contains bit(s) in high impedance state: {0}. Use GetStateOutput instead.",
                                                     pin.Function.ToText()
                                                     )
                                       );
        }
 public string this[int index] {
     get {
         if (this.output != null)
         {
             return(this.output[index].ToString("X", CultureInfo.InvariantCulture));
         }
         if (FunctionProbe.ToInt(this.result[index], bitWidth[index], out int unpacked))
         {
             return(unpacked.ToString("X", CultureInfo.InvariantCulture));
         }
         long res = this.result[index];
         return(CircuitFunction.ToText(Enumerable.Range(0, this.bitWidth[index]).Select(i => (State)((res >> i * 2) & 0x3)), false));
     }
 }
 public bool Unpack(int[] bitWidthList)
 {
     Tracer.Assert(bitWidthList.Length == this.result.Length);
     this.bitWidth = bitWidthList;
     int[] res = new int[this.result.Length];
     for (int i = 0; i < res.Length; i++)
     {
         int unpacked;
         if (!FunctionProbe.ToInt(this.result[i], this.bitWidth[i], out unpacked))
         {
             return(false);
         }
         res[i] = unpacked;
     }
     this.output = res;
     return(true);
 }