Beispiel #1
0
        public override bool start(uint index)
        {
            Monitor.Enter(mLock);
            try
            {
                uint i        = 0;
                uint devCount = SiUSBController.count();
                for (uint j = 0; j < devCount; j++)
                {
                    var vidSB = new StringBuilder();
                    var pidSB = new StringBuilder();
                    if (SiUSBController.getVID(j, vidSB) > 0 && SiUSBController.getPID(j, pidSB) > 0)
                    {
                        string vidString = vidSB.ToString();
                        string pidString = pidSB.ToString();

                        var vidHex = Util.getHexBytes(vidString);
                        var pidHex = Util.getHexBytes(pidString);
                        Array.Reverse(vidHex);
                        Array.Reverse(pidHex);

                        ushort vID = BitConverter.ToUInt16(vidHex, 0);
                        ushort pID = BitConverter.ToUInt16(pidHex, 0);

                        if (vID == (ushort)VendorID && pID == (ushort)ProductID)
                        {
                            if (i == index)
                            {
                                if (SiUSBController.open(j, ref mDeviceHandle) == false)
                                {
                                    Console.WriteLine("SiUSBController.start() : Failed open (SiUSB index : {0})", j);
                                    Monitor.Exit(mLock);
                                    this.stop();
                                    return(false);
                                }

                                Console.WriteLine("SiUSBController.start() : Success open (SiUSB index : {0})", j);

                                mThreadState = true;
                                mThread      = new Thread(threadFunc);
                                mThread.Start();
                                Monitor.Exit(mLock);
                                return(true);
                            }
                            i++;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("SiUSBController.start() : Failed catch({0})", e.Message);
            }
            Monitor.Exit(mLock);
            this.stop();
            return(false);
        }
Beispiel #2
0
 private static bool open(uint index, ref IntPtr deviceHandle)
 {
     try
     {
         if (index >= SiUSBController.count())
         {
             return(false);
         }
         var status = SIUSBXP.SI_Open(index, ref deviceHandle);
         return(status == SIUSBXP.SI_SUCCESS);
     }
     catch { }
     return(false);
 }
Beispiel #3
0
 private static int getPID(uint index, StringBuilder builder)
 {
     try
     {
         if (index >= SiUSBController.count())
         {
             return(-100);
         }
         var status = SIUSBXP.SI_GetProductString(index, builder, SIUSBXP.SI_RETURN_PID);
         return((status == SIUSBXP.SI_SUCCESS) ? 1 : -1);
     }
     catch { }
     return(-200);
 }
Beispiel #4
0
        private void threadFunc()
        {
            var recvArray = new byte[32];

            while (mThreadState == true)
            {
                if (Monitor.TryEnter(mLock) == false)
                {
                    Thread.Sleep(100);
                    continue;
                }
                try
                {
                    while (mSendDataArrayList.Count > 0)
                    {
                        var sendList = mSendDataArrayList[0];
                        mSendDataArrayList.RemoveAt(0);

                        // write
                        for (int i = 0; i < sendList.Count; i++)
                        {
                            Console.WriteLine("SiUSBController.threadFunc() : write()-----------------------------------------");
                            Util.printHex(sendList[i]);

                            int ret = SiUSBController.write(mDeviceHandle, sendList[i], (uint)sendList[i].Length, 500);
                            if (ret < 0)
                            {
                                Console.WriteLine(String.Format("SiUSBController.threadFunc() : Failed send({0})", ret));
                            }
                        }

                        // read
                        int ret2 = SiUSBController.read(mDeviceHandle, recvArray, (uint)recvArray.Length, 500);
                        if (ret2 <= 0)
                        {
                            Console.WriteLine(String.Format("SiUSBController.threadFunc() : Failed recv({0})", ret2));
                            Monitor.Exit(mLock);
                            Thread.Sleep(100);
                            continue;
                        }

                        this.onReport(recvArray, ret2);
                    }
                }
                catch { }
                Monitor.Exit(mLock);
                Thread.Sleep(100);
            }
        }
Beispiel #5
0
        public override void stop()
        {
            Monitor.Enter(mLock);
            mThreadState = false;
            if (mThread != null)
            {
                mThread.Join();
                mThread = null;
            }

            try
            {
                SiUSBController.close(mDeviceHandle);
            }
            catch { }
            Monitor.Exit(mLock);
        }
Beispiel #6
0
        public bool start(bool isSiUSB, uint clcIndex, uint usbIndex)
        {
            Monitor.Enter(mLock);

            if (clcIndex == 0)
            {
                mFileName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\" + "CLC.json";
            }
            else
            {
                mFileName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\" + string.Format("CLC{0}.json", clcIndex + 1);
            }

            if (isSiUSB == true)
            {
                // SiUSBController
                mUSBController = new SiUSBController(USBVendorID.ASETEK, USBProductID.CLC);
            }
            else
            {
                // WinUSBController
                mUSBController = new WinUSBController(USBVendorID.ASETEK, USBProductID.CLC, ENDPOINT_IN, ENDPOINT_OUT);
            }

            mUSBController.onRecvHandler += onRecv;
            if (mUSBController.start(usbIndex) == false)
            {
                Monitor.Exit(mLock);
                this.stop();
                return(false);
            }

            if (this.readFile() == true)
            {
                mIsSendCustomData = (mCustomDataList.Count > 0);
            }

            mTimer.Interval = 500;
            mTimer.Elapsed += onTimer;
            mTimer.Start();

            Monitor.Exit(mLock);
            return(true);
        }
Beispiel #7
0
        public static uint getDeviceCount(USBVendorID vendorID, USBProductID productID)
        {
            uint count = 0;

            try
            {
                uint devCount = SiUSBController.count();
                for (uint i = 0; i < devCount; i++)
                {
                    var vidSB = new StringBuilder();
                    var pidSB = new StringBuilder();
                    if (SiUSBController.getVID(i, vidSB) > 0 && SiUSBController.getPID(i, pidSB) > 0)
                    {
                        string vidString = vidSB.ToString();
                        string pidString = pidSB.ToString();

                        Console.WriteLine("SiUSBController.getDeviceCount() : SiUSB index({0}), VendorID(0x{1:X4}), ProductID(0x{2:X4})", i, vidString, pidString);

                        var vidHex = Util.getHexBytes(vidString);
                        var pidHex = Util.getHexBytes(pidString);
                        Array.Reverse(vidHex);
                        Array.Reverse(pidHex);

                        ushort vID = BitConverter.ToUInt16(vidHex, 0);
                        ushort pID = BitConverter.ToUInt16(pidHex, 0);

                        if (vID == (ushort)vendorID && pID == (ushort)productID)
                        {
                            count++;
                        }
                    }
                }
            }
            catch { }
            return(count);
        }
Beispiel #8
0
        public void start()
        {
            Monitor.Enter(mLock);
            if (mIsStart == true)
            {
                Monitor.Exit(mLock);
                return;
            }
            mIsStart = true;

            string mutexName = "Global\\Access_ISABUS.HTP.Method";

            this.createBusMutex(mutexName, ref mISABusMutex);

            mutexName = "Global\\Access_SMBUS.HTP.Method";
            this.createBusMutex(mutexName, ref mSMBusMutex);

            mutexName = "Global\\Access_PCI";
            this.createBusMutex(mutexName, ref mPCIMutex);

            // Gigabyte
            if (OptionManager.getInstance().IsGigabyte == true)
            {
                mGigabyte = new Gigabyte();
                mGigabyte.AddChangeValue += addChangeValue;
                mGigabyte.LockBus        += lockBus;
                mGigabyte.UnlockBus      += unlockBus;

                mIsGigabyte = mGigabyte.start();
            }
            else
            {
                mIsGigabyte = false;
                Gigabyte.stopService();
            }

            if (mIsGigabyte == false)
            {
                mGigabyte = null;

                // LibreHardwareMonitor
                if (OptionManager.getInstance().LibraryType == LibraryType.LibreHardwareMonitor)
                {
                    mLHM = new LHM();
                    mLHM.start();
                }

                // OpenHardwareMonitor
                else
                {
                    mOHM = new OHM();
                    mOHM.start();
                }
            }

            // NvAPIWrapper
            if (OptionManager.getInstance().IsNvAPIWrapper == true)
            {
                NVIDIA.Initialize();
            }

            this.createTemp();
            this.createFan();
            this.createControl();

            // NZXT Kraken
            if (OptionManager.getInstance().IsKraken == true)
            {
                try
                {
                    uint num = 1;

                    // X2
                    uint devCount = HidUSBController.getDeviceCount(USBVendorID.NZXT, USBProductID.KrakenX2);
                    for (uint i = 0; i < devCount; i++)
                    {
                        var kraken = new Kraken();
                        if (kraken.start(i, USBProductID.KrakenX2) == true)
                        {
                            mKrakenList.Add(kraken);

                            var sensor = new KrakenLiquidTemp(kraken, num);
                            mSensorList.Add(sensor);

                            var fan = new KrakenFanSpeed(kraken, num);
                            mFanList.Add(fan);

                            var pump = new KrakenPumpSpeed(kraken, num);
                            mFanList.Add(pump);

                            var fanControl = new KrakenFanControl(kraken, num);
                            mControlList.Add(fanControl);
                            this.addChangeValue(30, fanControl);

                            var pumpControl = new KrakenPumpControl(kraken, num);
                            mControlList.Add(pumpControl);
                            this.addChangeValue(50, pumpControl);

                            num++;
                        }
                    }

                    // X3
                    devCount = HidUSBController.getDeviceCount(USBVendorID.NZXT, USBProductID.KrakenX3);
                    for (uint i = 0; i < devCount; i++)
                    {
                        var kraken = new Kraken();
                        if (kraken.start(i, USBProductID.KrakenX3) == true)
                        {
                            mKrakenList.Add(kraken);

                            var sensor = new KrakenLiquidTemp(kraken, num);
                            mSensorList.Add(sensor);

                            var pump = new KrakenPumpSpeed(kraken, num);
                            mFanList.Add(pump);

                            var pumpControl = new KrakenPumpControl(kraken, num);
                            mControlList.Add(pumpControl);
                            this.addChangeValue(50, pumpControl);

                            num++;
                        }
                    }
                }
                catch { }
            }

            // EVGA CLC
            if (OptionManager.getInstance().IsCLC == true)
            {
                try
                {
                    uint num      = 1;
                    uint clcIndex = 0;

                    // SiUSBController
                    uint devCount = SiUSBController.getDeviceCount(USBVendorID.ASETEK, USBProductID.CLC);
                    for (uint i = 0; i < devCount; i++)
                    {
                        var clc = new CLC();
                        if (clc.start(true, clcIndex, i) == true)
                        {
                            mCLCList.Add(clc);

                            var sensor = new CLCLiquidTemp(clc, num);
                            mSensorList.Add(sensor);

                            var fan = new CLCFanSpeed(clc, num);
                            mFanList.Add(fan);

                            var pump = new CLCPumpSpeed(clc, num);
                            mFanList.Add(pump);

                            var fanControl = new CLCFanControl(clc, num);
                            mControlList.Add(fanControl);
                            this.addChangeValue(25, fanControl);

                            var pumpControl = new CLCPumpControl(clc, num);
                            mControlList.Add(pumpControl);
                            this.addChangeValue(50, pumpControl);

                            clcIndex++;
                            num++;
                        }
                    }

                    if (WinUSBController.initUSB() == true)
                    {
                        // WinUSBController
                        devCount = WinUSBController.getDeviceCount(USBVendorID.ASETEK, USBProductID.CLC);
                        for (uint i = 0; i < devCount; i++)
                        {
                            var clc = new CLC();
                            if (clc.start(false, clcIndex, i) == true)
                            {
                                mCLCList.Add(clc);

                                var sensor = new CLCLiquidTemp(clc, num);
                                mSensorList.Add(sensor);

                                var fan = new CLCFanSpeed(clc, num);
                                mFanList.Add(fan);

                                var pump = new CLCPumpSpeed(clc, num);
                                mFanList.Add(pump);

                                var fanControl = new CLCFanControl(clc, num);
                                mControlList.Add(fanControl);
                                this.addChangeValue(25, fanControl);

                                var pumpControl = new CLCPumpControl(clc, num);
                                mControlList.Add(pumpControl);
                                this.addChangeValue(50, pumpControl);

                                clcIndex++;
                                num++;
                            }
                        }
                    }
                }
                catch { }
            }

            if (OptionManager.getInstance().IsRGBnFC == true)
            {
                try
                {
                    uint num      = 1;
                    uint devCount = HidUSBController.getDeviceCount(USBVendorID.NZXT, USBProductID.RGBAndFanController);
                    for (uint i = 0; i < devCount; i++)
                    {
                        var rgb = new RGBnFC();
                        if (rgb.start(i) == true)
                        {
                            mRGBnFCList.Add(rgb);

                            for (int j = 0; j < RGBnFC.MAX_FAN_COUNT; j++)
                            {
                                var fan = new RGBnFCFanSpeed(rgb, j, num);
                                mFanList.Add(fan);

                                var control = new RGBnFCControl(rgb, j, num);
                                mControlList.Add(control);
                                this.addChangeValue(control.getMinSpeed(), control);

                                num++;
                            }
                        }
                    }
                }
                catch { }
            }

            // DIMM thermal sensor
            if (OptionManager.getInstance().IsDimm == true)
            {
                this.lockSMBus(0);
                if (SMBusController.open(false) == true)
                {
                    int num      = 1;
                    int busCount = SMBusController.getCount();

                    for (int i = 0; i < busCount; i++)
                    {
                        var detectBytes = SMBusController.i2cDetect(i);
                        if (detectBytes != null)
                        {
                            // 0x18 ~ 0x20
                            for (int j = 0; j < detectBytes.Length; j++)
                            {
                                if (j < 24)
                                {
                                    continue;
                                }
                                else if (j > 32)
                                {
                                    break;
                                }

                                if (detectBytes[j] == (byte)j)
                                {
                                    var sensor = new DimmTemp("DIMM #" + num++, i, detectBytes[j]);
                                    sensor.onSetDimmTemperature += onSetDimmTemperature;
                                    mSensorList.Add(sensor);
                                }
                            }
                        }
                    }
                }
                this.unlockSMBus();
            }

            // Motherboard temperature
            this.createMotherBoardTemp();

            // GPU
            this.createGPUTemp();
            this.createGPUFan();
            this.createGPUControl();

            // osd sensor
            this.createOSDSensor();

            Monitor.Exit(mLock);
        }
Beispiel #9
0
        public override bool start()
        {
            Monitor.Enter(mLock);
            try
            {
                uint count = SiUSBController.count();
                if (count == 0)
                {
                    Console.WriteLine("SiUSBController.start() : USB device is zero");
                    Monitor.Exit(mLock);
                    this.stop();
                    return(false);
                }

                Console.WriteLine("SiUSBController.start() : USB device count({0})", count);

                bool isDeviceOpen = false;
                for (uint i = 0; i < count; i++)
                {
                    var vidSB = new StringBuilder();
                    var pidSB = new StringBuilder();
                    if (SiUSBController.getVID(i, vidSB) > 0 && SiUSBController.getPID(i, pidSB) > 0)
                    {
                        string vidString = vidSB.ToString();
                        string pidString = pidSB.ToString();

                        Console.WriteLine("SiUSBController.start() : Device index({0}), VendorID(0x{1:X4}), ProductID(0x{2:X4})", i, vidString, pidString);

                        var vidHex = Util.getHexBytes(vidString);
                        var pidHex = Util.getHexBytes(pidString);
                        Array.Reverse(vidHex);
                        Array.Reverse(pidHex);

                        ushort vID = BitConverter.ToUInt16(vidHex, 0);
                        ushort pID = BitConverter.ToUInt16(pidHex, 0);

                        if (vID == (ushort)VendorID && pID == (ushort)ProductID)
                        {
                            if (SiUSBController.open(i, ref mDeviceHandle) == true)
                            {
                                Console.WriteLine("SiUSBController.start() : Success open({0})", i);
                                isDeviceOpen = true;
                                break;
                            }
                            else
                            {
                                Console.WriteLine("SiUSBController.start() : Failed open({0})", i);
                            }
                        }
                    }
                }

                if (isDeviceOpen == false)
                {
                    Console.WriteLine("SiUSBController.start() : Failed device open");
                    Monitor.Exit(mLock);
                    this.stop();
                    return(false);
                }

                mThreadState = true;
                mThread      = new Thread(threadFunc);
                mThread.Start();
                Monitor.Exit(mLock);
                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine("SiUSBController.start() : Failed catch({0})", e.Message);
                Monitor.Exit(mLock);
                this.stop();
                return(false);
            }
        }