Exemple #1
0
    void UpdateAbilityMomentumCounters(MomentumData newMomentumData)
    {
        HardwareType[] allEquippedActiveHardware = InventoryController.GetEquippedActiveHardware();
        for (int i = 0; i < abilityMomentumCounters.Length; i++)
        {
            HardwareType activeHardwareType = allEquippedActiveHardware[i];
            if (activeHardwareType != HardwareType.None)
            {
                int newMomentumValue = MomentumManager.GetMomentumPointsByHardwareType(activeHardwareType);

                if (newMomentumValue != displayedMomentumValues[i])
                {
                    Color flashColor = newMomentumValue > displayedMomentumValues[i] ? momentumIncreasedFlashColor : momentumDecreasedFlashColor;

                    Image  momentumCounterImage = abilityMomentumCounters[i].GetComponent <Image>();
                    Sprite counterSprite        = Resources.Load <Sprite>(MOMENTUM_COUNTER_PATH + newMomentumValue.ToString());
                    momentumCounterImage.sprite = counterSprite;

                    StartCoroutine(FlashAbilityMomentumCounter(momentumCounterImage, flashColor));

                    displayedMomentumValues[i] = newMomentumValue;
                }
            }
        }
    }
Exemple #2
0
        public Miner CreateMiner(MinerBaseType minerBaseType, HardwareType hardwareType, bool is64Bit = true)
        {
            switch (minerBaseType)
            {
            case MinerBaseType.CCMiner:
                return(new Ccminer(hardwareType, minerBaseType, hardwareMonitor, is64Bit));

            case MinerBaseType.CCMinerNanashi:
                return(new CCMinerForkNanashi(hardwareType, minerBaseType, hardwareMonitor));

            case MinerBaseType.EWBF:
                return(new EWBF(hardwareType, minerBaseType, hardwareMonitor));

            case MinerBaseType.EWBF_NO_ASIC:
                return(new EWBF_NO_ASIC(hardwareType, minerBaseType, hardwareMonitor));

            case MinerBaseType.DSTM:
                return(new DSTM(hardwareType, minerBaseType, hardwareMonitor));

            case MinerBaseType.Claymore:
                return(new Claymore(hardwareType, minerBaseType, hardwareMonitor));

            default:
                throw new ApplicationException(string.Format("The miner base type {0} is not yet supported.", minerBaseType.ToString()));
            }
        }
Exemple #3
0
    public void UpdateAbilities(ref IHardware[] activeHardwareList)
    {
        for (int i = 0; i < activeHardwareList.Length; i++)
        {
            IHardware activeHardware = activeHardwareList[i];
            Sprite    activeHardwareBubSprite;

            if (activeHardware == null)
            {
                activeHardwareBubSprite    = emptyAbilityBub;
                abilityBubImages[i].sprite = activeHardwareBubSprite;
                abilityMomentumCounters[i].SetActive(false);

                if (cooldownOverlays[i].enabled == true)
                {
                    cooldownOverlays[i].enabled = false;
                }
            }
            else
            {
                HardwareType activeHardwareType = activeHardware.Type;

                activeHardwareBubSprite    = DataAssociations.GetHardwareTypeBubImage(activeHardwareType);
                abilityBubImages[i].sprite = activeHardwareBubSprite;
                abilityMomentumCounters[i].SetActive(true);

                activeHardware.CooldownPercentUpdater  = null;
                activeHardware.CooldownPercentUpdater += GenerateCooldownPercentUpdater(i);

                activeHardware.CooldownDurationUpdater  = null;
                activeHardware.CooldownDurationUpdater += GenerateCooldownDurationUpdater(i);
            }
        }
    }
Exemple #4
0
        private IVideoProvider CreateSigleCaptureObject(XmlNode node, HardwareType hw)
        {
            if (node == null)
            {
                return(null);
            }
            XmlNode item = node.SelectSingleNode(hw.ToString());

            if (item == null)
            {
                return(null);
            }
            if (hwLib.ContainsKey(hw) && hwLib[hw] is IVideoProvider)
            {
                return((IVideoProvider)hwLib[hw]);
            }
            try
            {
                IVideoProvider provider = Serialize.XmlDeSerialize(item) as IVideoProvider;
                return(provider);
            }
            catch (Exception ex)
            {
                LogHelper.WriteDebugException(ex);
                return(null);
            }
        }
        private List <HardwareItemModel> ParseCPU(string[] CPUs, List <ParserRule> cpuRules)
        {
            //Задаем тип комплектующего
            HardwareType type = new HardwareType("Процессор");
            //Создаем новый список процессоров
            List <HardwareItemModel> cpu_list = new List <HardwareItemModel>();
            //Создаем список производителей процессоров
            List <ManufacturerModel> cpu_manufacturers = new List <ManufacturerModel>();

            //Заполняем список производителей из правил
            foreach (ParserRule r in cpuRules)
            {
                cpu_manufacturers.Add(new ManufacturerModel(r.Rule_name));
            }
            //Перебираем все строки процессоров из прайса
            foreach (string s in CPUs)
            {
                //Для каждого правила
                foreach (ParserRule rule in cpuRules)
                {
                    //Если правило подходит к данной строке, заполняем характеристики
                    if (Regex.IsMatch(s, rule.Rule_name, RegexOptions.IgnoreCase))
                    {
                        var description = s.SelectDescription();
                        var cost        = s.SelectCost();
                        var sock        = Regex.Match(s, rule.Property_templates["Сокет"]).Value;
                        var cpu_name    = Regex.Match(s, string.Format(rule.Property_templates["Name"], Regex.Escape(sock))).Value;
                        var cpu         = new HardwareItemModel(cpu_name, cost, description, cpu_manufacturers.Where(m => m.Name == rule.Rule_name).FirstOrDefault(), type);
                        cpu.PropertyList.Add(new CompatibilityPropertyModel("Сокет", sock));
                        cpu_list.Add(cpu);
                    }
                }
            }
            return(cpu_list);
        }
        private List <HardwareItemModel> ParseMB(string[] MBs, List <ParserRule> mbRules)
        {
            List <HardwareItemModel> mb_list       = new List <HardwareItemModel>();
            List <ManufacturerModel> manufacturers = new List <ManufacturerModel>();
            HardwareType             motherboard   = new HardwareType("Материнская плата");

            foreach (ParserRule r in mbRules)
            {
                manufacturers.Add(new ManufacturerModel(r.Rule_name));
            }
            foreach (string s in MBs)
            {
                foreach (ParserRule r in mbRules)
                {
                    if (Regex.IsMatch(s, r.Rule_name))
                    {
                        HardwareItemModel mb = new HardwareItemModel();
                        var socket           = Regex.Match(s, r.Property_templates["Сокет"]).Value;
                        mb.PropertyList.Add(new CompatibilityPropertyModel("Сокет", socket));
                        mb.Name         = Regex.Match(s, r.Property_templates["Name"]).Value;
                        mb.Cost         = s.SelectCost();
                        mb.Description  = s.SelectDescription();
                        mb.Manufacturer = manufacturers.Where(m => m.Name == r.Rule_name).FirstOrDefault();
                        mb.HardwareType = motherboard;
                        mb_list.Add(mb);
                    }
                }
            }
            return(mb_list);
        }
        private List <HardwareItemModel> ParseHDD(string[] hdds, List <ParserRule> hddRules)
        {
            List <HardwareItemModel> hdd_list      = new List <HardwareItemModel>();
            List <ManufacturerModel> manufacturers = new List <ManufacturerModel>();
            HardwareType             hd            = new HardwareType("Жесткий диск");

            foreach (ParserRule r in hddRules)
            {
                manufacturers.Add(new ManufacturerModel(r.Rule_name));
            }
            foreach (string s in hdds)
            {
                foreach (ParserRule r in hddRules)
                {
                    if (Regex.IsMatch(s, r.Rule_name))
                    {
                        HardwareItemModel hdd = new HardwareItemModel();
                        var prop = Regex.Match(s, r.Property_templates["Тип устройства"], RegexOptions.IgnoreCase).Value;
                        hdd.PropertyList.Add(new CompatibilityPropertyModel("Тип устройства", prop));
                        prop = Regex.Match(s, r.Property_templates["Разъём"]).Value;
                        hdd.PropertyList.Add(new CompatibilityPropertyModel("Разъём", prop));
                        prop = Regex.Match(s, r.Property_templates["Объём памяти"], RegexOptions.IgnoreCase).Value;
                        hdd.PropertyList.Add(new CompatibilityPropertyModel("Объём памяти", prop));
                        hdd.Name         = Regex.Match(s, r.Property_templates["Name"]).Value;
                        hdd.Cost         = s.SelectCost();
                        hdd.Description  = s.SelectDescription();
                        hdd.Manufacturer = manufacturers.Where(m => m.Name == r.Rule_name).FirstOrDefault();
                        hdd.HardwareType = hd;
                        hdd_list.Add(hdd);
                    }
                }
            }
            return(hdd_list);
        }
        private List <HardwareItemModel> ParseGPU(string[] gpus, List <ParserRule> gpuRules)
        {
            List <HardwareItemModel> gpu_list      = new List <HardwareItemModel>();
            List <ManufacturerModel> manufacturers = new List <ManufacturerModel>();
            HardwareType             videocard     = new HardwareType("Видеокарта");

            foreach (ParserRule r in gpuRules)
            {
                manufacturers.Add(new ManufacturerModel(r.Rule_name));
            }
            foreach (string s in gpus)
            {
                foreach (ParserRule r in gpuRules)
                {
                    if (Regex.IsMatch(s, r.Rule_name))
                    {
                        HardwareItemModel gpu = new HardwareItemModel();
                        var prop = Regex.Match(s, r.Property_templates["Объём памяти"], RegexOptions.IgnoreCase).Value;
                        gpu.PropertyList.Add(new CompatibilityPropertyModel("Объём памяти", prop));
                        gpu.Name         = Regex.Match(s, r.Property_templates["Name"], RegexOptions.IgnoreCase).Groups[3].Value;
                        gpu.Description  = Regex.Match(s, r.Property_templates["Описание"]).Value;
                        gpu.Cost         = s.SelectCost();
                        gpu.Manufacturer = manufacturers.Where(m => m.Name == r.Rule_name).FirstOrDefault();
                        gpu.HardwareType = videocard;
                        gpu_list.Add(gpu);
                    }
                }
            }
            return(gpu_list);
        }
Exemple #9
0
    Type GetHardwareType(HardwareType hardwareType)
    {
        switch (hardwareType)
        {
        case HardwareType.None:
            return(null);

        case HardwareType.Parry:
            return(typeof(ParryHardware));

        case HardwareType.Blink:
            return(typeof(BlinkHardware));

        case HardwareType.Nullify:
            return(typeof(NullifyHardware));

        case HardwareType.Fracture:
            return(typeof(FractureHardware));

        case HardwareType.Yank:
            return(typeof(YankHardware));

        default:
            return(null);
        }
    }
        private List <HardwareItemModel> ParseMemory(string[] mems, List <ParserRule> memRules)
        {
            List <HardwareItemModel> mem_list      = new List <HardwareItemModel>();
            List <ManufacturerModel> manufacturers = new List <ManufacturerModel>();
            HardwareType             ram           = new HardwareType("Оперативная память");

            foreach (ParserRule r in memRules)
            {
                manufacturers.Add(new ManufacturerModel(r.Rule_name));
            }
            foreach (string s in mems)
            {
                foreach (ParserRule r in memRules)
                {
                    if (Regex.IsMatch(s, r.Rule_name))
                    {
                        HardwareItemModel mem = new HardwareItemModel();
                        var prop = Regex.Match(s, r.Property_templates["Тип памяти"]).Value;
                        mem.PropertyList.Add(new CompatibilityPropertyModel("Тип памяти", prop));
                        prop = Regex.Match(s, r.Property_templates["Объём памяти"]).Value;
                        mem.PropertyList.Add(new CompatibilityPropertyModel("Объём памяти", prop));
                        mem.Name         = Regex.Match(s, r.Property_templates["Name"]).Value;
                        mem.Cost         = s.SelectCost();
                        mem.Description  = Regex.Match(s, r.Property_templates["Description"]).Value;
                        mem.Manufacturer = manufacturers.Where(m => m.Name == r.Rule_name).FirstOrDefault();
                        mem.HardwareType = ram;
                        mem_list.Add(mem);
                    }
                }
            }
            return(mem_list);
        }
Exemple #11
0
        private void SetDevice(HardwareType device)
        {
            CommSettings.HardwareIndex = device;
            switch (device)
            {
            case HardwareType.ELM327:
                m_log.TraceInfo("Set device to ELM327");
                m_obdDevice = new OBDDeviceELM327(m_log);
                break;

            case HardwareType.ELM320:
                m_log.TraceInfo("Set device to ELM320");
                m_obdDevice = new OBDDeviceELM320(m_log);
                break;

            case HardwareType.ELM322:
                m_log.TraceInfo("Set device to ELM322");
                m_obdDevice = new OBDDeviceELM322(m_log);
                break;

            case HardwareType.ELM323:
                m_log.TraceInfo("Set device to ELM323");
                m_obdDevice = new OBDDeviceELM323(m_log);
                break;

            default:
                m_log.TraceInfo("Set device to ELM327");
                m_obdDevice = new OBDDeviceELM327(m_log);
                break;
            }
        }
Exemple #12
0
        // This helper function retrieve active Dll Major version number
        //
        private CANResult DllMajorVersion(HardwareType hType, out int majorVersion)
        {
            CANResult Res;
            String    dllVersionStr = "";

            // We execute the "DllVersionInfo" function of the PCANLight
            // using as parameter the Hardware type and a string
            // variable to get the info like "x.xx"
            //
            Res = PCANLight.DllVersionInfo(hType, out dllVersionStr);

            // We retrieve major version number
            // spliting versionNumberStr based on "." decimal symbol
            //
            String[] versionTabInfo = dllVersionStr.Split('.');
            if (versionTabInfo.Length > 0)
            {
                Int32.TryParse(versionTabInfo[0].ToString(), out majorVersion);
            }
            else
            {
                majorVersion = 0;
            }
            return(Res);
        }
Exemple #13
0
    public void ApplyPassiveHardware(HardwareType activeHardwareType, IHardware hardware, GameObject subject)
    {
        switch (activeHardwareType)
        {
        case HardwareType.Parry:
            ApplyPassiveHardware_Parry(subject);
            break;

        case HardwareType.Blink:
            ApplyPassiveHardware_Blink(hardware as BlinkHardware);
            break;

        case HardwareType.Nullify:
            ApplyPassiveHardware_Nullify(subject);
            break;

        case HardwareType.Fracture:
            Debug.LogError("Trying to apply Fracture pasive effect to Fracture active hardware.");
            break;

        case HardwareType.Yank:
            ApplyPassiveHardware_Yank(subject);
            break;

        default:
            break;
        }
    }
Exemple #14
0
    public void ApplyPassiveHardware(HardwareType activeHardwareType, IHardware activeHardware, GameObject subject)
    {
        switch (activeHardwareType)
        {
        case HardwareType.Parry:
            StartCoroutine(ApplyNullifyToBullet(subject));
            break;

        case HardwareType.Blink:
            StartCoroutine(ApplyPassiveHardware_Blink(activeHardware, subject));
            break;

        case HardwareType.Nullify:
            Debug.LogError("Trying to apply Nullify passive effect to Nullify active hardware.");
            break;

        case HardwareType.Fracture:
            StartCoroutine(ApplyNullifyToBullet(subject));
            break;

        case HardwareType.Yank:
            ApplyPassiveHardware_Yank(subject);
            break;

        default:
            break;
        }
    }
Exemple #15
0
    void UpdateMomentumPointButtons(MomentumData momentumData)
    {
        int availablePoints = momentumData.UnassignedAvailableMomentumPoints;

        if (availablePoints <= 0)
        {
            ToggleMomentumButtons(false);
            return;
        }

        ToggleMomentumButtons(true);

        HardwareType[] activeHardware = InventoryController.GetEquippedActiveHardware();
        for (int i = 0; i < activeHardware.Length; i++)
        {
            HardwareType hardwareType   = activeHardware[i];
            bool         isSlotOccupied = hardwareType != HardwareType.None;
            bool         isMaxedOut     = false;
            if (isSlotOccupied)
            {
                isMaxedOut = momentumData.HardwareTypeToMomentumMap[hardwareType] >= 5;
            }
            assignMomentumButtons[i].interactable = isSlotOccupied && !isMaxedOut;
        }
    }
 public static string GetName(HardwareType OperationEnum)
 {
     switch (OperationEnum)
     {
         case HardwareType.Ethernet:
             return "Ethernet";
         default:
             return "Unknown";
     }
 }
Exemple #17
0
        /// <summary>
        ///   Инициализация ARP-пакета.
        /// </summary>
        /// <param name = "htype">Канальный уровень (тип).</param>
        /// <param name = "ptype">Сетевой уровень (тип).</param>
        /// <param name = "oper">Операция ARP.</param>
        /// <param name = "sha">Канальный адрес источника.</param>
        /// <param name = "spa">Сетевой адрес источника.</param>
        /// <param name = "tha">Канальный адрес назначения.</param>
        /// <param name = "tpa">Сетевой адрес назначения.</param>
        /// <exception cref = "ArgumentNullException"><paramref name = "sha" /> является <c>null</c>.</exception>
        /// <exception cref = "ArgumentNullException"><paramref name = "spa" /> является <c>null</c>.</exception>
        /// <exception cref = "ArgumentNullException"><paramref name = "tha" /> является <c>null</c>.</exception>
        /// <exception cref = "ArgumentNullException"><paramref name = "tpa" /> является <c>null</c>.</exception>
        /// <exception cref = "IncorrectFieldLengthException"><paramref name = "sha" /> имеет недопустимую длину.</exception>
        /// <exception cref = "IncorrectFieldLengthException"><paramref name = "spa" /> имеет недопустимую длину.</exception>
        /// <exception cref = "IncorrectFieldLengthException"><paramref name = "tha" /> имеет недопустимую длину.</exception>
        /// <exception cref = "IncorrectFieldLengthException"><paramref name = "tpa" /> имеет недопустимую длину.</exception>
        public ARPPacket(HardwareType htype,
            L3ProtocolType ptype,
            ARPOperation oper,
            IArray <byte> sha,
            IArray <byte> spa,
            IArray <byte> tha,
            IArray <byte> tpa)
        {
            var hlen = FieldLengthAttribute.GetLength (htype);
            var plen = FieldLengthAttribute.GetLength (ptype);

            if (sha == null)
                throw new ArgumentNullException ("sha");

            if (spa == null)
                throw new ArgumentNullException ("spa");

            if (tha == null)
                throw new ArgumentNullException ("tha");

            if (tpa == null)
                throw new ArgumentNullException ("tpa");

            if (sha.Length != hlen)
                throw new IncorrectFieldLengthException ("SHA", sha.Length, hlen);

            if (spa.Length != plen)
                throw new IncorrectFieldLengthException ("SPA", spa.Length, plen);

            if (tha.Length != hlen)
                throw new IncorrectFieldLengthException ("THA", sha.Length, hlen);

            if (tpa.Length != plen)
                throw new IncorrectFieldLengthException ("TPA", spa.Length, plen);

            this.Data = new Array <byte> (new byte[8 + sha.Length + spa.Length + tha.Length + tpa.Length]);

            this.HardwareType = htype;
            this.ProtocolType = ptype;

            this.HardwareLength = hlen;
            this.ProtocolLength = plen;

            this.Operation = oper;

            this.SenderHardwareAddress = sha;
            this.SenderProtocolAddress = spa;

            this.TargetHardwareAddress = tha;
            this.TargetProtocolAddress = tpa;
        }
Exemple #18
0
 public Form1()
 {
     //
     // Required for Windows Form Designer support
     //
     InitializeComponent();
     // We set the variable to know which hardware is
     // currently selected (none!)
     //
     ActiveHardware = (HardwareType)(-1);
     // Create a list to store the displayed mesasges
     //
     LastMsgsList = new ArrayList();
 }
Exemple #19
0
        public ArpPacket(byte[] bytes)
            : base(bytes)
        {
            _hardwareType = (HardwareType)IPAddress.HostToNetworkOrder(BitConverter.ToInt16(bytes, 14));
            _internetProtocol = (InternetProtocol)IPAddress.HostToNetworkOrder(BitConverter.ToInt16(bytes, 16));
            _hardwareSize = bytes[18];
            _protocolSize = bytes[19];
            _opcode = (ArpOpCode)IPAddress.HostToNetworkOrder(BitConverter.ToInt16(bytes, 20));

            _senderMac = new PhysicalAddress(ReadBytes(22, _hardwareSize, bytes));
            _senderIp = new IPAddress(ReadBytes(22 + _hardwareSize, _protocolSize, bytes));

            _targetMac = new PhysicalAddress(ReadBytes(22 + _hardwareSize + _protocolSize, _hardwareSize, bytes));
            _targetIp = new IPAddress(ReadBytes(22 + _hardwareSize + _protocolSize + _hardwareSize, _protocolSize, bytes));
        }
 public Image GetImage(HardwareType hardwareType)
 {
     Image image;
       if (images.TryGetValue(hardwareType, out image)) {
     return image;
       } else {
     switch (hardwareType) {
       case HardwareType.CPU:
     image = Utilities.EmbeddedResources.GetImage("cpu.png");
     break;
       case HardwareType.GpuNvidia:
     image = Utilities.EmbeddedResources.GetImage("nvidia.png");
     break;
       case HardwareType.GpuAti:
     image = Utilities.EmbeddedResources.GetImage("ati.png");
     break;
       case HardwareType.HDD:
     image = Utilities.EmbeddedResources.GetImage("hdd.png");
     break;
       case HardwareType.Heatmaster:
     image = Utilities.EmbeddedResources.GetImage("bigng.png");
     break;
       case HardwareType.Mainboard:
     image = Utilities.EmbeddedResources.GetImage("mainboard.png");
     break;
       case HardwareType.SuperIO:
     image = Utilities.EmbeddedResources.GetImage("chip.png");
     break;
       case HardwareType.TBalancer:
     image = Utilities.EmbeddedResources.GetImage("bigng.png");
     break;
       case HardwareType.RAM:
     image = Utilities.EmbeddedResources.GetImage("ram.png");
     break;
       case HardwareType.NIC:
     image = Utilities.EmbeddedResources.GetImage("network.png");
     break;
       default:
     image = new Bitmap(1, 1);
     break;
     }
     images.Add(hardwareType, image);
     return image;
       }
 }
Exemple #21
0
      /// <summary>
      /// PCANLight Write function
      /// This function Place a CAN message into the Transmit Queue of the CAN Hardware
      /// </summary>
      /// <param name="HWType">In which hardware should be written the CAN Message</param>3
      /// <param name="MsgToSend">The TCLightMsg message to be written</param>
      /// <returns>A CANResult value - Error/status of the hardware after execute the function</returns>
      public static CANResult Write(HardwareType HWType, TCLightMsg MsgToSend)
      {
         PCAN_ISA.TPCANMsg MsgIsa;
         PCAN_2ISA.TPCANMsg MsgIsa2;
         PCAN_PCI.TPCANMsg MsgPci;
         PCAN_2PCI.TPCANMsg MsgPci2;
         PCAN_PCC.TPCANMsg MsgPcc;
         PCAN_2PCC.TPCANMsg MsgPcc2;
         PCAN_USB.TPCANMsg MsgUsb;
         PCAN_2USB.TPCANMsg MsgUsb2;
         PCAN_DNP.TPCANMsg MsgDnp;
         PCAN_DNG.TPCANMsg MsgDng;

         try
         {
            switch (HWType)
            {
               case HardwareType.ISA_1CH:
                  MsgIsa = MsgToSend;
                  return (CANResult)PCAN_ISA.Write(ref MsgIsa);

               case HardwareType.ISA_2CH:
                  MsgIsa2 = MsgToSend;
                  return (CANResult)PCAN_2ISA.Write(ref MsgIsa2);

               case HardwareType.PCI_1CH:
                  MsgPci = MsgToSend;
                  return (CANResult)PCAN_PCI.Write(ref MsgPci);

               case HardwareType.PCI_2CH:
                  MsgPci2 = MsgToSend;
                  return (CANResult)PCAN_2PCI.Write(ref MsgPci2);

               case HardwareType.PCC_1CH:
                  MsgPcc = MsgToSend;
                  return (CANResult)PCAN_PCC.Write(ref MsgPcc);

               case HardwareType.PCC_2CH:
                  MsgPcc2 = MsgToSend;
                  return (CANResult)PCAN_2PCC.Write(ref MsgPcc2);

               case HardwareType.USB_1CH:
                  MsgUsb = MsgToSend;
                  return (CANResult)PCAN_USB.Write(ref MsgUsb);

               case HardwareType.USB_2CH:
                  MsgUsb2 = MsgToSend;
                  return (CANResult)PCAN_2USB.Write(ref MsgUsb2);

               case HardwareType.DNP:
                  MsgDnp = MsgToSend;
                  return (CANResult)PCAN_DNP.Write(ref MsgDnp);

               case HardwareType.DNG:
                  MsgDng = MsgToSend;
                  return (CANResult)PCAN_DNG.Write(ref MsgDng);

               // Hardware is not valid for this function
               //					
               default:
                  return CANResult.ERR_ILLHW;
            }
         }
         catch (Exception Ex)
         {
            // Error: Dll does not exists or the function is not available
            //
            Tracer.WriteError(TraceGroup.CANBUS, null, "Write {0}", Ex.Message + "\"");
            return CANResult.ERR_NO_DLL;
         }
      }
		/// <summary>Resets the emulated system and emulate a specific hardware.</summary>
		/// <remarks>In order to chaneg the emulated hardware, the emulation has to be reset.</remarks>
		/// <param name="hardwareType">Hardware to emulate.</param>
		public void Reset(HardwareType hardwareType)
		{
			// From now on, the hardware type can only be changed after a "hard" reset of the emulated machine
			HardwareType = hardwareType;

#if WITH_THREADING
			SuspendEmulation();
#endif

			ResetThreading();
			ResetBootRom();
			ResetProcessor();
			ResetTiming();
			ResetTimer();
			ResetInterrupt();
			ResetMemory();
			ResetRom();
			ResetAudio();
			ResetVideo();
			ResetSuperGameBoy();
			ResetJoypad();
			ResetPorts();
			ResetRendering();
			ResetDebug();
			ResetSnapshot();

#if WITH_THREADING
			ResumeEmulation();
#endif
		}
        float AvgTemp(Computer computer, HardwareType type)
        {
            var gpus = computer.Hardware.Where(x => x.HardwareType == type).ToArray();
            if (gpus.Any())
            {
            int n = 0;
            float t = 0;
            foreach (var gpu in gpus)
            {
                var temps = gpu.Sensors.Where(x => x.SensorType == SensorType.Temperature).ToArray();
                if (temps.Any())
                {
                    var temp = temps.Average(x => x.Value.Value);
                    t += temp;
                    n++;
                }

                foreach (var sh in gpu.SubHardware)
                {
                    temps = sh.Sensors.Where(x => x.SensorType == SensorType.Temperature).ToArray();
                    if (temps.Any())
                    {
                        var temp = temps.Average(x => x.Value.Value);
                        t += temp;
                        n++;
                    }
                }
            }

            if (n > 0)
                return t / (float)n;
            else
                return 0;
            }
            else return 0;
        }
Exemple #24
0
        public DhcpMessage(byte[] data)
        {
            var offset = 0;
            _mOperation = (DhcpOperation) data[offset++];
            _mHardware = (HardwareType) data[offset++];
            HardwareAddressLength = data[offset++];
            Hops = data[offset++];

            SessionId = BitConverter.ToInt32(data, offset);
            offset += 4;

            var secondsElapsed = new byte[2];
            Array.Copy(data, offset, secondsElapsed, 0, 2);
            SecondsElapsed = BitConverter.ToUInt16(ReverseByteOrder(secondsElapsed), 0);
            offset += 2;

            Flags = BitConverter.ToUInt16(data, offset);
            offset += 2;

            Array.Copy(data, offset, _mClientAddress, 0, 4);
            offset += 4;
            Array.Copy(data, offset, _mAssignedAddress, 0, 4);
            offset += 4;
            Array.Copy(data, offset, _mNextServerAddress, 0, 4);
            offset += 4;
            Array.Copy(data, offset, _mRelayAgentAddress, 0, 4);
            offset += 4;
            Array.Copy(data, offset, _mClientHardwareAddress, 0, 16);
            offset += 16;
            Array.Copy(data, offset, _mServerHostName, 0, 64);
            offset += 64;
            Array.Copy(data, offset, _mBootFileName, 0, 128);
            offset += 128;
            //Array.Copy(data, offset, this.m_VendorSpecificInformation, 0, 64);
            //offset += 64;
            //offset += 192; // Skip server host name and boot file

            if (offset + 4 < data.Length &&
                (BitConverter.ToUInt32(data, offset) == DhcpOptionsMagicNumber ||
                 BitConverter.ToUInt32(data, offset) == WinDhcpOptionsMagicNumber))
            {
                offset += 4;
                var end = false;

                while (!end && offset < data.Length)
                {
                    var option = (DhcpOption) data[offset];
                    offset++;

                    int optionLen;

                    switch (option)
                    {
                        case DhcpOption.Pad:
                            continue;
                        case DhcpOption.End:
                            end = true;
                            continue;
                        default:
                            optionLen = data[offset];
                            offset++;
                            break;
                    }

                    var optionData = new byte[optionLen];

                    Array.Copy(data, offset, optionData, 0, optionLen);
                    offset += optionLen;

                    _mOptions.Add(option, optionData);
                    _mOptionDataSize += optionLen;
                }
            }
        }
        float MaxTemp(Computer computer, HardwareType type)
        {
            var gpus = computer.Hardware.Where(x => x.HardwareType == type).ToArray();
            if (gpus.Any())
            {
            float t = 0;
            foreach (var gpu in gpus)
            {
                var temps = gpu.Sensors.Where(x => x.SensorType == SensorType.Temperature).ToArray();
                if (temps.Any())
                {
                    var temp = temps.Max(x => x.Value.Value);
                    t = Math.Max(temp, t);
                }

                foreach (var sh in gpu.SubHardware)
                {
                    temps = sh.Sensors.Where(x => x.SensorType == SensorType.Temperature).ToArray();
                    if (temps.Any())
                    {
                        var temp = temps.Max(x => x.Value.Value);
                        t = Math.Max(temp, t);
                    }
                }
            }

            return t;
            }
            else return 0;
        }
Exemple #26
0
 private IHardware[] GetHardware(HardwareType type)
 {
     return this.computer.Hardware.Where(x => x.HardwareType == type).ToArray();
 }
Exemple #27
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="hardwareType"></param>
        /// <param name="changedHardware"></param>
        /// <param name="changedType"></param>
        public void HardwareChanged(HardwareType hardwareType, object changedHardware, HardwareChangedType changedType)
        {
            //HardwareBuilderBase build = CommuniSoftFactory.HardwareBuilder;
            DBHardwareBuilderBase build = CommuniSoftFactory.HardwareBuilder as DBHardwareBuilderBase;
            Debug.Assert(build != null, "CommuniSoftFactory.HardwareBuilder is not DBHardwareBuilderBase");

            if (hardwareType == HardwareType.Station)
            {
                Station station = changedHardware as Station;
                switch (changedType)
                {
                    case HardwareChangedType.Add:
                        build.AddStation(station);
                        break;

                    case HardwareChangedType.Edit :
                        build.EditStation(station);
                        break;

                    case HardwareChangedType.Delete :
                        // TODO: delete station
                        //
                        break;
                }
            }
            else if (hardwareType == HardwareType.Device)
            {
                Device device = changedHardware as Device;
                switch (changedType)
                {
                    case HardwareChangedType.Add:
                        build.AddDevice(device);
                        break;

                    case HardwareChangedType.Edit:
                        build.EditDevice(device);
                        break;

                    case HardwareChangedType.Delete:
                        // TODO: delete device
                        //
                        break;
                }
            }

            HardwareChangedEventArgs e = new HardwareChangedEventArgs();
            e.HardwareType = hardwareType;
            e.ChangedHardware = changedHardware;
            e.ChangedType = changedType;
            OnHardwareChanged(e);
        }
Exemple #28
0
      /// <summary>
      /// PCANLight Read function
      /// This function get the next message or the next error from the Receive Queue of 
      /// the CAN Hardware.  
      /// REMARK:
      ///		- Check always the type of the received Message (MSGTYPE_STANDARD,MSGTYPE_RTR,
      ///		  MSGTYPE_EXTENDED,MSGTYPE_STATUS)
      ///		- The function will return ERR_OK always that you receive a CAN message successfully 
      ///		  although if the messages is a MSGTYPE_STATUS message.  
      ///		- When a MSGTYPE_STATUS mesasge is got, the ID and Length information of the message 
      ///		  will be treated as indefined values. Actually information of the received message
      ///		  should be interpreted using the first 4 data bytes as follow:
      ///			*	Data0	Data1	Data2	Data3	Kind of Error
      ///				0x00	0x00	0x00	0x02	CAN_ERR_OVERRUN		0x0002	CAN Controller was read to late
      ///				0x00	0x00	0x00	0x04	CAN_ERR_BUSLIGHT	0x0004  Bus Error: An error counter limit reached (96)
      ///				0x00	0x00	0x00	0x08	CAN_ERR_BUSHEAVY	0x0008	Bus Error: An error counter limit reached (128)
      ///				0x00	0x00	0x00	0x10	CAN_ERR_BUSOFF		0x0010	Bus Error: Can Controller went "Bus-Off"
      ///		- If a CAN_ERR_BUSOFF status message is received, the CAN Controller must to be 
      ///		  initialized again using the Init() function.  Otherwise, will be not possible 
      ///		  to send/receive more messages.
      /// </summary>
      /// <param name="HWType">From which hardware should be read a CAN Message</param>
      /// <param name="Msg">The TCLightMsg structure to store the CAN message</param>
      /// <returns>A CANResult value - Error/status of the hardware after execute the function</returns>
      public static CANResult Read(HardwareType HWType, out TCLightMsg Msg)
      {
         PCAN_ISA.TPCANMsg MsgIsa;
         PCAN_2ISA.TPCANMsg MsgIsa2;
         PCAN_PCI.TPCANMsg MsgPci;
         PCAN_2PCI.TPCANMsg MsgPci2;
         PCAN_PCC.TPCANMsg MsgPcc;
         PCAN_2PCC.TPCANMsg MsgPcc2;
         PCAN_USB.TPCANMsg MsgUsb;
         PCAN_2USB.TPCANMsg MsgUsb2;
         PCAN_DNP.TPCANMsg MsgDnp;
         PCAN_DNG.TPCANMsg MsgDng;
         CANResult resTemp;

         Msg = null;

         try
         {
            switch (HWType)
            {
               case HardwareType.ISA_1CH:
                  resTemp = (CANResult)PCAN_ISA.Read(out MsgIsa);
                  Msg = new TCLightMsg(MsgIsa);
                  return resTemp;

               case HardwareType.ISA_2CH:
                  resTemp = (CANResult)PCAN_2ISA.Read(out MsgIsa2);
                  Msg = new TCLightMsg(MsgIsa2);
                  return resTemp;

               case HardwareType.PCI_1CH:
                  MsgPci = new PCAN_PCI.TPCANMsg();
                  MsgPci.DATA = new byte[8];
                  resTemp = (CANResult)PCAN_PCI.Read(out MsgPci);
                  Msg = new TCLightMsg(MsgPci);
                  return resTemp;

               case HardwareType.PCI_2CH:
                  resTemp = (CANResult)PCAN_2PCI.Read(out MsgPci2);
                  Msg = new TCLightMsg(MsgPci2);
                  return resTemp;

               case HardwareType.PCC_1CH:
                  resTemp = (CANResult)PCAN_PCC.Read(out MsgPcc);
                  Msg = new TCLightMsg(MsgPcc);
                  return resTemp;

               case HardwareType.PCC_2CH:
                  resTemp = (CANResult)PCAN_2PCC.Read(out MsgPcc2);
                  Msg = new TCLightMsg(MsgPcc2);
                  return resTemp;

               case HardwareType.USB_1CH:
                  resTemp = (CANResult)PCAN_USB.Read(out MsgUsb);
                  Msg = new TCLightMsg(MsgUsb);
                  return resTemp;

               case HardwareType.USB_2CH:
                  resTemp = (CANResult)PCAN_2USB.Read(out MsgUsb2);
                  Msg = new TCLightMsg(MsgUsb2);
                  return resTemp;


               case HardwareType.DNP:
                  resTemp = (CANResult)PCAN_DNP.Read(out MsgDnp);
                  Msg = new TCLightMsg(MsgDnp);
                  return resTemp;

               case HardwareType.DNG:
                  resTemp = (CANResult)PCAN_DNG.Read(out MsgDng);
                  Msg = new TCLightMsg(MsgDng);
                  return resTemp;

               // Hardware is not valid for this function
               //
               default:
                  return CANResult.ERR_ILLHW;
            }
         }
         catch (Exception Ex)
         {
            // Error: Dll does not exists or the function is not available
            //			
            Tracer.WriteError(TraceGroup.CANBUS, null, "Read {0}", Ex.Message + "\"");
            return CANResult.ERR_NO_DLL;
         }
      }
Exemple #29
0
 /// <summary>
 /// Refresh sensors of a hardware device
 /// </summary>
 /// <param name="hardwareType">The HardwareType of the desired device</param>
 /// <param name="hardwareInstance">The instance number of the desired device</param>
 public static void RefreshSensors(HardwareType hardwareType, int hardwareInstance)
 {
     // First make sure HDD checking is enabled
     if (hardwareType == HardwareType.HDD && !ComputerSensors.HDDEnabled)
     {
         ComputerSensors.HDDEnabled = true;
     }
     foreach (IHardware hardwareElement in ComputerSensors.Hardware)
     {
         if (hardwareElement.HardwareType == hardwareType)
         {
             if (hardwareElement.Identifier.ToString().EndsWith(hardwareInstance.ToString()))
             {
                 hardwareElement.Update();
             }
         }
     }
 }
Exemple #30
0
      /// <summary>
      /// PCANLight DllVersionInfo function
      /// This function get the Version information of the used PCAN-Light DLL. (max. 255 characters)
      /// </summary>
      /// <param name="HWType">Which DLL (Hardware implementation) should be asked for its 
      /// Version information</param>
      /// <param name="strInfo">String buffer to return the DLL information</param>
      /// <returns>A CANResult value generated after execute the function</returns>
      public static CANResult DllVersionInfo(HardwareType HWType, out string strInfo)
      {
         StringBuilder stbTemp;
         CANResult resTemp;

         strInfo = "";

         try
         {
            stbTemp = new StringBuilder(256);
            switch (HWType)
            {
               case HardwareType.ISA_1CH:
                  resTemp = (CANResult)PCAN_ISA.DLLVersionInfo(stbTemp);
                  break;

               case HardwareType.ISA_2CH:
                  resTemp = (CANResult)PCAN_2ISA.DLLVersionInfo(stbTemp);
                  break;

               case HardwareType.PCI_1CH:
                  resTemp = (CANResult)PCAN_PCI.DLLVersionInfo(stbTemp);
                  break;

               case HardwareType.PCI_2CH:
                  resTemp = (CANResult)PCAN_2PCI.DLLVersionInfo(stbTemp);
                  break;

               case HardwareType.PCC_1CH:
                  resTemp = (CANResult)PCAN_PCC.DLLVersionInfo(stbTemp);
                  break;

               case HardwareType.PCC_2CH:
                  resTemp = (CANResult)PCAN_2PCC.DLLVersionInfo(stbTemp);
                  break;

               case HardwareType.USB_1CH:
                  resTemp = (CANResult)PCAN_USB.DLLVersionInfo(stbTemp);
                  break;

               case HardwareType.USB_2CH:
                  resTemp = (CANResult)PCAN_2USB.DLLVersionInfo(stbTemp);
                  break;

               case HardwareType.DNP:
                  resTemp = (CANResult)PCAN_DNP.DLLVersionInfo(stbTemp);
                  break;

               case HardwareType.DNG:
                  resTemp = (CANResult)PCAN_DNG.DLLVersionInfo(stbTemp);
                  break;

               // Hardware is not valid for this function
               //
               default:
                  stbTemp = new StringBuilder("");
                  resTemp = CANResult.ERR_ILLHW;
                  break;
            }
            strInfo = stbTemp.ToString();
            return resTemp;
         }
         catch (EntryPointNotFoundException Ex)
         {
            // Function is not available in the loaded Dll
            //
            Tracer.WriteError(TraceGroup.CANBUS, null, "DllVersionInfo wrong version {0}", Ex.Message + "\"");
            return CANResult.ERR_NO_DLL;
         }
         catch (Exception Ex)
         {
            // Error: Dll does not exists or the function is not available
            //
            Tracer.WriteError(TraceGroup.CANBUS, null, "DllVersionInfo {0}", Ex.Message + "\"");
            return CANResult.ERR_NO_DLL;
         }
      }
Exemple #31
0
        private void btnInit_Click(object sender, System.EventArgs e)
        {
            CANResult Res;
            int majorVersion = 0;

            // Check version 2.x Dll is available
            //
            Res = DllMajorVersion((HardwareType)cbbHws.SelectedIndex, out majorVersion);
            if (Res == CANResult.ERR_OK)
            {
                // Sample must ONLY work if a 2.x or later version of the
                // PCAN-Light is installed
                //
                if (majorVersion < 2)
                {
                    MessageBox.Show("DLL 2.x or later are required to run this program" +
                        "\r\nPlease, download lastest DLL version on http://www.peak-system.com or refer to the documentation for more information.",
                        "DLL Version", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    // According with the active parameters/hardware, we
                    // use one of the two possible "Init" PCANLight functions.
                    // One is for Plug And Play hardware, and the other for
                    // Not P&P.
                    //
                    if (cbbIO.Enabled)
                        // Not P&P Hardware
                        //
                        Res = PCANLight.Init((HardwareType)cbbHws.SelectedIndex,
                            (Baudrates)cbbBaudrates.Tag,
                            (FramesType)cbbMsgType.SelectedIndex,
                            Convert.ToUInt32(cbbIO.Text, 16),
                            Convert.ToByte(cbbInterrupt.Text));
                    else
                        // P&P Hardware
                        //
                        Res = PCANLight.Init((HardwareType)cbbHws.SelectedIndex,
                            (Baudrates)cbbBaudrates.Tag,
                            (FramesType)cbbMsgType.SelectedIndex);

                    // The Hardware was successfully initiated
                    //
                    if (Res == CANResult.ERR_OK)
                    {
                        // We save the hardware type which is currently
                        // initiated
                        //
                        ActiveHardware = (HardwareType)cbbHws.SelectedIndex;

                        // We start to read from the CAN Queue
                        //
                        tmrRead.Enabled = true;

                        // Set UI enable
                        btnInit.Enabled = !(btnWrite.Enabled = btnSetFilter.Enabled = btnResetFilter.Enabled = btnRelease.Enabled = btnInfo.Enabled = btnDllInfo.Enabled = true);
                        rdbTimer.Enabled = true;
                        rdbEvent.Enabled = true;
                        chbTimeStamp.Enabled = true;
                        cbbHws_SelectedIndexChanged(this, new EventArgs());

                        // We show the information of the configured
                        // and initiated hardware
                        //
                        txtInfo.Text = "Active Hardware: " + cbbHws.Text;
                        txtInfo.Text += "\r\nBaud Rate: " + cbbBaudrates.Text;
                        txtInfo.Text += "\r\nFrame Type: " + cbbMsgType.Text;
                        // If was a no P&P Hardware, we show additional information
                        //
                        if (cbbIO.Enabled)
                        {
                            txtInfo.Text += "\r\nI/O Addr.: " + cbbIO.Text + "h";
                            txtInfo.Text += "\r\nInterrupt: " + cbbInterrupt.Text;
                        }
                    }
                    // An error occurred.  We show the error.
                    //
                    else
                        txtInfo.Text = "Error: " + Res.ToString();
                }
            }
            else
                txtInfo.Text = "Error: " + Res.ToString();
        }
Exemple #32
0
      /// <summary>
      /// PCANLight ReadEx function
      /// This function get the next message or the next error from the Receive Queue of 
      /// the CAN Hardware and the time when the message arrived.  
      /// REMARK:
      ///		- Check always the type of the received Message (MSGTYPE_STANDARD,MSGTYPE_RTR,
      ///		  MSGTYPE_EXTENDED,MSGTYPE_STATUS)
      ///		- The function will return ERR_OK always that you receive a CAN message successfully 
      ///		  although if the messages is a MSGTYPE_STATUS message.  
      ///		- When a MSGTYPE_STATUS mesasge is got, the ID and Length information of the message 
      ///		  will be treated as indefined values. Actually information of the received message
      ///		  should be interpreted using the first 4 data bytes as follow:
      ///			*	Data0	Data1	Data2	Data3	Kind of Error
      ///				0x00	0x00	0x00	0x02	CAN_ERR_OVERRUN		0x0002	CAN Controller was read to late
      ///				0x00	0x00	0x00	0x04	CAN_ERR_BUSLIGHT	0x0004  Bus Error: An error counter limit reached (96)
      ///				0x00	0x00	0x00	0x08	CAN_ERR_BUSHEAVY	0x0008	Bus Error: An error counter limit reached (128)
      ///				0x00	0x00	0x00	0x10	CAN_ERR_BUSOFF		0x0010	Bus Error: Can Controller went "Bus-Off"
      ///		- If a CAN_ERR_BUSOFF status message is received, the CAN Controller must to be 
      ///		  initialized again using the Init() function.  Otherwise, will be not possible 
      ///		  to send/receive more messages.
      /// </summary>
      /// <param name="HWType">From which hardware should be read a CAN Message</param>
      /// <param name="Msg">The TCLightMsg structure to store the CAN message</param>
      /// <param name="RcvTime">The TCLightTimestamp structure to store the timestamp of the CAN message</param>
      /// <returns>A CANResult value - Error/status of the hardware after execute the function</returns>
      public static CANResult ReadEx(HardwareType HWType, out TCLightMsg Msg, out TCLightTimestamp RcvTime)
      {
         PCAN_ISA.TPCANMsg MsgIsa;
         PCAN_2ISA.TPCANMsg MsgIsa2;
         PCAN_PCI.TPCANMsg MsgPci;
         PCAN_2PCI.TPCANMsg MsgPci2;
         PCAN_PCC.TPCANMsg MsgPcc;
         PCAN_2PCC.TPCANMsg MsgPcc2;
         PCAN_USB.TPCANMsg MsgUsb;
         PCAN_2USB.TPCANMsg MsgUsb2;
         PCAN_DNP.TPCANMsg MsgDnp;
         PCAN_DNG.TPCANMsg MsgDng;

         PCAN_ISA.TPCANTimestamp RcvTimeIsa;
         PCAN_2ISA.TPCANTimestamp RcvTimeIsa2;
         PCAN_PCI.TPCANTimestamp RcvTimePci;
         PCAN_2PCI.TPCANTimestamp RcvTimePci2;
         PCAN_PCC.TPCANTimestamp RcvTimePcc;
         PCAN_2PCC.TPCANTimestamp RcvTimePcc2;
         PCAN_USB.TPCANTimestamp RcvTimeUsb;
         PCAN_2USB.TPCANTimestamp RcvTimeUsb2;
         PCAN_DNP.TPCANTimestamp RcvTimeDnp;
         PCAN_DNG.TPCANTimestamp RcvTimeDng;

         CANResult resTemp;

         Msg = null;
         RcvTime = null;

         try
         {
            switch (HWType)
            {
               case HardwareType.ISA_1CH:
                  resTemp = (CANResult)PCAN_ISA.ReadEx(out MsgIsa, out RcvTimeIsa);
                  Msg = new TCLightMsg(MsgIsa);
                  RcvTime = new TCLightTimestamp(RcvTimeIsa);
                  return resTemp;

               case HardwareType.ISA_2CH:
                  resTemp = (CANResult)PCAN_2ISA.ReadEx(out MsgIsa2, out RcvTimeIsa2);
                  Msg = new TCLightMsg(MsgIsa2);
                  RcvTime = new TCLightTimestamp(RcvTimeIsa2);
                  return resTemp;

               case HardwareType.PCI_1CH:
                  resTemp = (CANResult)PCAN_PCI.ReadEx(out MsgPci, out RcvTimePci);
                  Msg = new TCLightMsg(MsgPci);
                  RcvTime = new TCLightTimestamp(RcvTimePci);
                  return resTemp;

               case HardwareType.PCI_2CH:
                  resTemp = (CANResult)PCAN_2PCI.ReadEx(out MsgPci2, out RcvTimePci2);
                  Msg = new TCLightMsg(MsgPci2);
                  RcvTime = new TCLightTimestamp(RcvTimePci2);
                  return resTemp;

               case HardwareType.PCC_1CH:
                  resTemp = (CANResult)PCAN_PCC.ReadEx(out MsgPcc, out RcvTimePcc);
                  Msg = new TCLightMsg(MsgPcc);
                  RcvTime = new TCLightTimestamp(RcvTimePcc);
                  return resTemp;

               case HardwareType.PCC_2CH:
                  resTemp = (CANResult)PCAN_2PCC.ReadEx(out MsgPcc2, out RcvTimePcc2);
                  Msg = new TCLightMsg(MsgPcc2);
                  RcvTime = new TCLightTimestamp(RcvTimePcc2);
                  return resTemp;

               case HardwareType.USB_1CH:
                  resTemp = (CANResult)PCAN_USB.ReadEx(out MsgUsb, out RcvTimeUsb);
                  Msg = new TCLightMsg(MsgUsb);
                  RcvTime = new TCLightTimestamp(RcvTimeUsb);
                  return resTemp;

               case HardwareType.USB_2CH:
                  resTemp = (CANResult)PCAN_2USB.ReadEx(out MsgUsb2, out RcvTimeUsb2);
                  Msg = new TCLightMsg(MsgUsb2);
                  RcvTime = new TCLightTimestamp(RcvTimeUsb2);
                  return resTemp;

               case HardwareType.DNP:
                  resTemp = (CANResult)PCAN_DNP.ReadEx(out MsgDnp, out RcvTimeDnp);
                  Msg = new TCLightMsg(MsgDnp);
                  RcvTime = new TCLightTimestamp(RcvTimeDnp);
                  return resTemp;

               case HardwareType.DNG:
                  resTemp = (CANResult)PCAN_DNG.ReadEx(out MsgDng, out RcvTimeDng);
                  Msg = new TCLightMsg(MsgDng);
                  RcvTime = new TCLightTimestamp(RcvTimeDng);
                  return resTemp;

               // Hardware is not valid for this function
               //
               default:
                  return CANResult.ERR_ILLHW;
            }
         }
         catch (EntryPointNotFoundException Ex)
         {
            // Function is not available in the loaded Dll
            //
            Tracer.WriteError(TraceGroup.CANBUS, null, "ReadEx wrong version {0}", Ex.Message + "\"");
            return CANResult.ERR_NO_DLL;
         }
         catch (Exception Ex)
         {
            // Error: Dll does not exists or the function is not available
            //
            Tracer.WriteError(TraceGroup.CANBUS, null, "ReadEx {0}", Ex.Message + "\"");
            return CANResult.ERR_NO_DLL;
         }
      }
Exemple #33
0
      /// <summary>
      /// PCANLight SetRcvEvent function
      /// This function read the device number of a USB CAN Hardware
      /// </summary>
      /// <param name="HWType">Hardware that will set the Event</param>
      /// <param name="EventHandle">The handle (ID) of the event to be set</param>
      /// <returns>A CANResult value - Error/status of the hardware after execute the function</returns>
      public static CANResult SetRcvEvent(HardwareType HWType, System.Threading.EventWaitHandle EventHandle)
      {
         IntPtr hHandle;

         try
         {
            // If the Event parameter is null, a value of IntPtr.Zero is set in order to clear the 
            // Event on the driver. Otherwise we get the internal Handle value representing 
            // the Receive-Event
            //
            hHandle = (EventHandle == null) ? IntPtr.Zero : EventHandle.SafeWaitHandle.DangerousGetHandle();

            switch (HWType)
            {
               case HardwareType.ISA_1CH:
                  return (CANResult)PCAN_ISA.SetRcvEvent(hHandle);

               case HardwareType.ISA_2CH:
                  return (CANResult)PCAN_2ISA.SetRcvEvent(hHandle);

               case HardwareType.PCI_1CH:
                  return (CANResult)PCAN_PCI.SetRcvEvent(hHandle);

               case HardwareType.PCI_2CH:
                  return (CANResult)PCAN_2PCI.SetRcvEvent(hHandle);

               case HardwareType.PCC_1CH:
                  return (CANResult)PCAN_PCC.SetRcvEvent(hHandle);

               case HardwareType.PCC_2CH:
                  return (CANResult)PCAN_2PCC.SetRcvEvent(hHandle);

               case HardwareType.USB_1CH:
                  return (CANResult)PCAN_USB.SetRcvEvent(hHandle);

               case HardwareType.USB_2CH:
                  return (CANResult)PCAN_2USB.SetRcvEvent(hHandle);

               case HardwareType.DNP:
                  return (CANResult)PCAN_DNP.SetRcvEvent(hHandle);

               case HardwareType.DNG:
                  return (CANResult)PCAN_DNG.SetRcvEvent(hHandle);

               // Hardware is not valid for this function
               //
               default:
                  return CANResult.ERR_ILLHW;
            }
         }
         catch (EntryPointNotFoundException Ex)
         {
            // Function is not available in the loaded Dll
            //
            Tracer.WriteError(TraceGroup.CANBUS, null, "SetRcvEvent wrong version {0}", Ex.Message + "\"");
            return CANResult.ERR_NO_DLL;
         }
         catch (Exception Ex)
         {
            // Error: Dll does not exists or the function is not available
            //
            Tracer.WriteError(TraceGroup.CANBUS, null, "SetRcvEvent {0}", Ex.Message + "\"");
            return CANResult.ERR_NO_DLL;
         }
      }
Exemple #34
0
      /// <summary>
      /// PCANLight GetUSBDeviceNr function
      /// This function read the device number of a USB CAN Hardware
      /// </summary>
      /// <param name="HWType">Hardware to get the Device Number</param>
      /// <param name="DeviceNumber">Variable to return the Device Number value</param>
      /// <returns>A CANResult value - Error/status of the hardware after execute the function</returns>
      public static CANResult GetUSBDeviceNr(HardwareType HWType, out uint DeviceNumber)
      {
         DeviceNumber = uint.MaxValue;

         try
         {
            switch (HWType)
            {
               case HardwareType.USB_1CH:
                  return (CANResult)PCAN_USB.GetUSBDeviceNr(out DeviceNumber);

               case HardwareType.USB_2CH:
                  return (CANResult)PCAN_2USB.GetUSBDeviceNr(out DeviceNumber);

               // Hardware is not valid for this function
               //
               default:
                  return CANResult.ERR_ILLHW;
            }
         }
         catch (Exception Ex)
         {
            // Error: Dll does not exists or the function is not available
            //
            Tracer.WriteError(TraceGroup.CANBUS, null, "GetUSBDeviceNr {0}", Ex.Message + "\"");
            return CANResult.ERR_NO_DLL;
         }
      }
Exemple #35
0
      /// <summary>
      /// PCANLight Init function for Plug and Play Hardware.
      /// This function make the following:
      ///		- Activate a Hardware
      ///		- Make a Register Test of 82C200/SJA1000
      ///		- Allocate a Send buffer and a Hardware handle
      ///		- Programs the configuration of the transmit/receive driver
      ///		- Set the Baudrate register
      ///		- Set the Controller in RESET condition
      /// </summary>
      /// <param name="HWType">Which hardware should be initialized</param>
      /// <param name="BTR0BTR1">BTR0-BTR1 baudrate register</param>
      /// <param name="MsgType">f the frame type is standard or extended</param>
      /// <returns>A CANResult value - Error/status of the hardware after execute the function</returns>
      public static CANResult Init(HardwareType HWType, Baudrates BTR0BTR1, FramesType MsgType)
      {
         try
         {
            switch (HWType)
            {
               case HardwareType.PCI_1CH:
                  return (CANResult)PCAN_PCI.Init((ushort)BTR0BTR1, (int)MsgType);

               case HardwareType.PCI_2CH:
                  return (CANResult)PCAN_2PCI.Init((ushort)BTR0BTR1, (int)MsgType);

               case HardwareType.PCC_1CH:
                  return (CANResult)PCAN_PCC.Init((ushort)BTR0BTR1, (int)MsgType);

               case HardwareType.PCC_2CH:
                  return (CANResult)PCAN_2PCC.Init((ushort)BTR0BTR1, (int)MsgType);

               case HardwareType.USB_1CH:
                  return (CANResult)PCAN_USB.Init((ushort)BTR0BTR1, (int)MsgType);

               case HardwareType.USB_2CH:
                  return (CANResult)PCAN_2USB.Init((ushort)BTR0BTR1, (int)MsgType);

               // Hardware is not valid for this function
               //
               default:
                  return CANResult.ERR_ILLHW;
            }
         }
         catch (Exception Ex)
         {
            // Error: Dll does not exists or the function is not available
            //
            Tracer.WriteError(TraceGroup.CANBUS, null, "Init {0}", Ex.Message + "\"");
            return CANResult.ERR_NO_DLL;
         }
      }
Exemple #36
0
      /// <summary>
      /// PCANLight Init function for non Plug and Play Hardware.  
      /// This function make the following:
      ///		- Activate a Hardware
      ///		- Make a Register Test of 82C200/SJA1000
      ///		- Allocate a Send buffer and a Hardware handle
      ///		- Programs the configuration of the transmit/receive driver
      ///		- Set the Baudrate register
      ///		- Set the Controller in RESET condition
      /// </summary>
      /// <param name="HWType">Which hardware should be initialized</param>
      /// <param name="BTR0BTR1">BTR0-BTR1 baudrate register</param>
      /// <param name="MsgType">If the frame type is standard or extended</param>
      /// <param name="IO_Port">Input/output Port Address of the hardware</param>
      /// <param name="Interrupt">Interrupt number</param>
      /// <returns>A CANResult value - Error/status of the hardware after execute the function</returns>
      public static CANResult Init(HardwareType HWType, Baudrates BTR0BTR1, FramesType MsgType, uint IO_Port, ushort Interrupt)
      {
         try
         {
            switch (HWType)
            {
               case HardwareType.ISA_1CH:
                  return (CANResult)PCAN_ISA.Init((ushort)BTR0BTR1, (int)MsgType, (int)Hardware.HW_ISA_SJA, IO_Port, Interrupt);

               case HardwareType.ISA_2CH:
                  return (CANResult)PCAN_2ISA.Init((ushort)BTR0BTR1, (int)MsgType, (int)Hardware.HW_ISA_SJA, IO_Port, Interrupt);

               case HardwareType.DNG:
                  return (CANResult)PCAN_DNG.Init((ushort)BTR0BTR1, (int)MsgType, (int)Hardware.HW_DONGLE_SJA, IO_Port, Interrupt);

               case HardwareType.DNP:
                  return (CANResult)PCAN_DNP.Init((ushort)BTR0BTR1, (int)MsgType, (int)Hardware.HW_DONGLE_PRO, IO_Port, Interrupt);

               // Hardware is not valid for this function
               //
               default:
                  return CANResult.ERR_ILLHW;
            }
         }
         catch (Exception Ex)
         {
            // Error: Dll does not exists or the function is not available
            //
            Tracer.WriteError(TraceGroup.CANBUS, null, "ppInit {0}", Ex.Message + "\"");
            return CANResult.ERR_NO_DLL;
         }
      }
		/// <summary>Tries to load the specified bootsrap ROM from assembly resources.</summary>
		/// <remarks>
		/// The various known bootstrap ROMs can be embedded in the executable image during compilation.
		/// By default, the emulator will look for resources with these names:
		/// <list type="table">
		/// <listheader>
		/// <term>Hardware</term>
		/// <description>Bootstrap ROM file name</description>
		/// </listheader>
		/// <item>
		/// <term>Game Boy</term>
		/// <description>dmg.rom</description>
		/// </item>
		/// <item>
		/// <term>Super Game Boy</term>
		/// <description>sgb.rom</description>
		/// </item>
		/// <item>
		/// <term>Game Boy Color</term>
		/// <description>cgb.rom</description>
		/// </item>
		/// </list>
		/// Embedding these ROMs post-build should be possible with the help of an external tool,
		/// but the easiest solution is probably to rebuild everything after having put the ROMs in the correct place.
		/// </remarks>
		/// <param name="hardwareType">Hardware whose bootstrap ROM should be loaded.</param>
		/// <param name="resourceName">Name of the resource which contain the ROM data.</param>
		private void TryLoadingRom(HardwareType hardwareType, string resourceName)
		{
			var stream = typeof(GameBoyMemoryBus).Assembly.GetManifestResourceStream(typeof(GameBoyMemoryBus), resourceName);

			if (stream == null) return;

			try
			{
				byte[] buffer = new byte[stream.Length];

				if (stream.Read(buffer, 0, buffer.Length) == buffer.Length)
					LoadBootRom(hardwareType, buffer);
			}
			finally { stream.Close(); }
		}
Exemple #38
0
      /// <summary>
      /// PCANLight Close function.
      /// This function terminate and release all resources and the configured hardware:
      /// </summary>
      /// <param name="HWType">Which hardware should be finished</param>
      /// <returns>A CANResult value - Error/status of the hardware after execute the function</returns>
      public static CANResult Close(HardwareType HWType)
      {
         try
         {
            switch (HWType)
            {
               case HardwareType.ISA_1CH:
                  return (CANResult)PCAN_ISA.Close();

               case HardwareType.ISA_2CH:
                  return (CANResult)PCAN_2ISA.Close();

               case HardwareType.PCI_1CH:
                  return (CANResult)PCAN_PCI.Close();

               case HardwareType.PCI_2CH:
                  return (CANResult)PCAN_2PCI.Close();

               case HardwareType.PCC_1CH:
                  return (CANResult)PCAN_PCC.Close();

               case HardwareType.PCC_2CH:
                  return (CANResult)PCAN_2PCC.Close();

               case HardwareType.USB_1CH:
                  return (CANResult)PCAN_USB.Close();

               case HardwareType.USB_2CH:
                  return (CANResult)PCAN_2USB.Close();

               case HardwareType.DNP:
                  return (CANResult)PCAN_DNP.Close();

               case HardwareType.DNG:
                  return (CANResult)PCAN_DNG.Close();

               // Hardware is not valid for this function
               //
               default:
                  return CANResult.ERR_ILLHW;
            }
         }
         catch (Exception Ex)
         {
            // Error: Dll does not exists or the function is not available
            //
            Tracer.WriteError(TraceGroup.CANBUS, null, "Close {0}", Ex.Message + "\"");
            return CANResult.ERR_NO_DLL;
         }
      }
		/// <summary>Loads a bootstrap ROM with the specified data.</summary>
		/// <remarks>Data integrity will be checked to ensure a correct bootstrap ROM gets loaded.</remarks>
		/// <param name="hardwareType">Hardware whose bootstrap ROM should be loaded.</param>
		/// <param name="data">Data of the specified bootstrap ROM.</param>
		/// <exception cref="ArgumentOutOfRangeException">The value provided for harware type is not a valid one.</exception>
		/// <exception cref="NotSupportedException">Loading the bootstrap ROM the specified hardware is not supported.</exception>
		/// <exception cref="InvalidDataException">Data integrity check failed.</exception>
		public unsafe void LoadBootRom(HardwareType hardwareType, byte[] data)
		{
			if (data == null) throw new ArgumentNullException();
			if (!Enum.IsDefined(typeof(HardwareType), hardwareType)) throw new ArgumentOutOfRangeException();

			byte[] referenceHash;
			int requestedLength;
			byte* destination;
			// I finally found a use for C# undocumented keywords… Yeah !
			// (There are other ways to do this if really needed, but in fact it feels kinda cleaner to use this rather than another switch statement here…)
			TypedReference romLoadedField;

			switch (hardwareType)
			{
				case HardwareType.GameBoy:
					requestedLength = 0x100;
					referenceHash = dmgRomHash;
					destination = dmgBootMemory;
					romLoadedField = __makeref(dmgBootRomLoaded);
					break;
				case HardwareType.SuperGameBoy:
					requestedLength = 0x100;
					referenceHash = sgbRomHash;
					destination = sgbBootMemory;
					romLoadedField = __makeref(sgbBootRomLoaded);
					break;
				case HardwareType.GameBoyColor:
					// Trim the GBC rom if needed (we don't need the "decorative" empty sapce)
					if (data.Length == 0x900)
					{
						byte[] tempData = new byte[0x800];

						Buffer.BlockCopy(data, 0, tempData, 0, 0x100);
						Buffer.BlockCopy(data, 0x200, tempData, 0x100, 0x700);

						data = tempData;
					}
					requestedLength = 0x800;
					referenceHash = cgbRomHash;
					destination = cgbBootMemory;
					romLoadedField = __makeref(cgbBootRomLoaded);
					break;
				default:
					throw new NotSupportedException();
			}

			var md5 = MD5.Create();

			if (data.Length != requestedLength || !Equals(md5.ComputeHash(data), referenceHash))
				throw new InvalidDataException();

			fixed (byte* dataPointer = data)
				MemoryBlock.Copy((void*)destination, (void*)dataPointer, requestedLength);

			__refvalue(romLoadedField, bool) = true;
		}
 private void cboHardwareType_SelectedIndexChanged(object sender, EventArgs e)
 {
     _HardwareType = (HardwareType)cboHardwareType.SelectedItem;
 }
		/// <summary>Determines whether the bootstrap ROM for the specified hardware has been loaded.</summary>
		/// <param name="hardwareType">Type of hardware.</param>
		/// <returns><c>true</c> if the bootstrap ROM for the specified hardware has been loaded; otherwise, <c>false</c>.</returns>
		public bool IsBootRomLoaded(HardwareType hardwareType)
		{
			switch (hardwareType)
			{
				case HardwareType.GameBoy: return dmgBootRomLoaded;
				case HardwareType.SuperGameBoy: return sgbBootRomLoaded;
				case HardwareType.GameBoyColor: return cgbBootRomLoaded;
				default: return false;
			}
		}
Exemple #42
0
        private void btnRelease_Click(object sender, System.EventArgs e)
        {
            CANResult Res;

            // We choose Timer method by default
            //
            rdbTimer.Checked = true;

            // We stopt to read from tehe CAN Queue
            //
            tmrRead.Enabled = false;

            // We close the active hardware using the
            // "Close" function of the PCANLight using
            // as parameter the Hardware type.
            //
            Res = PCANLight.Close(ActiveHardware);

            // The Hardware was successfully closed
            //
            if(Res == CANResult.ERR_OK)
                txtInfo.Text = "Hardware was successfully Released.\r\n";
                // An error occurred.  We show the error.
                //
            else
                txtInfo.Text = "Error: " + Res.ToString();

            // We set the varibale of active hardware to None
            // and activate/deactivate the corresponding buttons
            //
            ActiveHardware = (HardwareType)(-1);
            btnInit.Enabled = !(btnWrite.Enabled = btnSetFilter.Enabled = btnResetFilter.Enabled = btnRelease.Enabled = btnInfo.Enabled = btnDllInfo.Enabled = false);
            rdbTimer.Enabled = false;
            rdbEvent.Enabled = false;
            chbTimeStamp.Enabled = false;
            cbbHws_SelectedIndexChanged(this, new EventArgs());
        }
Exemple #43
0
		private void SwitchHardware(HardwareType hardwareType)
		{
			if (!emulatedGameBoy.RomLoaded || MessageBox.Show(this, Resources.EmulationResetMessage, Resources.GenericMessageTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
				emulatedGameBoy.Reset(Settings.Default.HardwareType = hardwareType);
		}
Exemple #44
0
        // This helper function retrieve active Dll Major version number
        //
        private CANResult DllMajorVersion(HardwareType hType, out int majorVersion)
        {
            CANResult Res;
            String dllVersionStr = "";

            // We execute the "DllVersionInfo" function of the PCANLight
            // using as parameter the Hardware type and a string
            // variable to get the info like "x.xx"
            //
            Res = PCANLight.DllVersionInfo(hType, out dllVersionStr);

            // We retrieve major version number
            // spliting versionNumberStr based on "." decimal symbol
            //
            String[] versionTabInfo = dllVersionStr.Split('.');
            if (versionTabInfo.Length > 0)
                Int32.TryParse(versionTabInfo[0].ToString(), out majorVersion);
            else
                majorVersion = 0;
            return Res;
        }
Exemple #45
0
 /// <summary>
 /// Method for obtaining sensor information using OpenHardwareMonitorLib
 /// Courtesy of http://openhardwaremonitor.org/
 /// </summary>
 /// <param name="hardwareType">The HardwareType of the desired device</param>
 /// <param name="hardwareInstance">The instance number of the desired device</param>
 /// <param name="sensorType">The SensorType of the desired sensor</param>
 /// <param name="sensorInstance">The instance number of the desired sensor</param>
 /// <returns>The value of the sensor</returns>
 public static float GetSensorValue(HardwareType hardwareType, int hardwareInstance, SensorType sensorType, int sensorInstance)
 {
     float result = 0;
     try
     {
         // Loop through hardware to find the one required
         foreach (IHardware hardwareElement in ComputerSensors.Hardware)
         {
             // If the hardware element's type is what we're looking for
             if (hardwareElement.HardwareType == hardwareType)
             {
                 // And the instance is the same (/intelcpu/0 <= Check this number)
                 if (hardwareElement.Identifier.ToString().EndsWith(hardwareInstance.ToString()))
                 {
                     // Then start looping the sensors
                     foreach (ISensor sensor in hardwareElement.Sensors)
                     {
                         // If the sensor's type is what we're looking for
                         if (sensor.SensorType == sensorType)
                         {
                             // And the instance is the same (/intelcpu/0/temperature/0 <= Check this number)
                             if (sensor.Identifier.ToString().EndsWith(sensorInstance.ToString()))
                             {
                                 // Get value and return it, skipping all the other elements
                                 result = (float)sensor.Value;
                                 return result;
                             }
                         }
                     }
                 }
             }
         }
     }
     catch (Exception)
     {
     }
     return result;
 }