/*private void Init()
     * {
     *  if (Network == null)
     *  {
     *      Debug.LogError("Network is null");
     *      return;
     *  }
     *
     *
     *
     *
     *  if (_library == null)
     *  {
     *      Debug.LogError("Failed to create hardware extension interface library");
     *      return;
     *  }
     * }*/

    public Example()
    {
        Console.WriteLine("Example hi");
        _adnLibrary = Antilatency.DeviceNetwork.Library.load();
        _library    = Antilatency.HardwareExtensionInterface.Library.load();

        _nodeHandle        = WaitForNode();
        _cotaskConstructor = _library.getCotaskConstructor();
        _deviceNetwork     = _adnLibrary.createNetwork(new[] { new UsbDeviceType {
                                                                   vid = UsbVendorId.Antilatency, pid = 0x0000
                                                               } });
        _cotask = _cotaskConstructor.startTask(_deviceNetwork, _nodeHandle);



        outputPin1 = _cotask.createOutputPin(Pins.IO1, PinState.Low);
        outputPin2 = _cotask.createOutputPin(Pins.IO2, PinState.Low);
        outputPin5 = _cotask.createOutputPin(Pins.IO5, PinState.Low);
        outputPin6 = _cotask.createOutputPin(Pins.IO6, PinState.Low);


        _cotask.run();

        Update();

        void Update()
        {
            if (Input.GetKey(KeyCode.UpArrow))
            {
                outputPin2.setState(PinState.High);
                outputPin6.setState(PinState.High);
            }
            if (Input.GetKey(KeyCode.DownArrow))
            {
                outputPin1.setState(PinState.High);
                outputPin5.setState(PinState.High);
            }
            if (Input.GetKey(KeyCode.LeftArrow))
            {
                outputPin2.setState(PinState.High);
                outputPin5.setState(PinState.High);
            }
            if (Input.GetKey(KeyCode.RightArrow))
            {
                outputPin6.setState(PinState.High);
                outputPin1.setState(PinState.High);
            }
        }
    }
        private void init()
        {
            //node = new NodeHandle();

            if (Network == null)
            {
                Debug.LogError("Network is null, from Init");
                return;
            }
            dLibrary = Antilatency.DeviceNetwork.Library.load();
            library  = Antilatency.HardwareExtensionInterface.Library.load();

            if (library == null)
            {
                Debug.LogError("HW Lib is null");
            }
            if (dLibrary == null)
            {
                Debug.LogError("DN Lib is null");
            }
            dLibrary.setLogLevel(LogLevel.Info);

            cotaskConstructor = library.getCotaskConstructor();


            var nw = GetNativeNetwork();

            node   = GetFirstIdleHardwareExtensionInterfaceNode();
            cotask = cotaskConstructor.startTask(nw, node);
            if (cotask != null)
            {
                outputPin1 = cotask.createOutputPin(Antilatency.HardwareExtensionInterface.Interop.Pins.IO1, Antilatency.HardwareExtensionInterface.Interop.PinState.High);
                outputPin2 = cotask.createOutputPin(Antilatency.HardwareExtensionInterface.Interop.Pins.IO2, Antilatency.HardwareExtensionInterface.Interop.PinState.High);
                outputPin5 = cotask.createOutputPin(Antilatency.HardwareExtensionInterface.Interop.Pins.IO5, Antilatency.HardwareExtensionInterface.Interop.PinState.High);
                outputPin6 = cotask.createOutputPin(Antilatency.HardwareExtensionInterface.Interop.Pins.IO6, Antilatency.HardwareExtensionInterface.Interop.PinState.High);
                outputPin3 = cotask.createOutputPin(Antilatency.HardwareExtensionInterface.Interop.Pins.IOA3, Antilatency.HardwareExtensionInterface.Interop.PinState.High);
                outputPin4 = cotask.createOutputPin(Antilatency.HardwareExtensionInterface.Interop.Pins.IOA4, Antilatency.HardwareExtensionInterface.Interop.PinState.High);
                outputPin7 = cotask.createOutputPin(Antilatency.HardwareExtensionInterface.Interop.Pins.IO7, Antilatency.HardwareExtensionInterface.Interop.PinState.High);
                outputPin8 = cotask.createOutputPin(Antilatency.HardwareExtensionInterface.Interop.Pins.IO8, Antilatency.HardwareExtensionInterface.Interop.PinState.High);

                cotask.run();
            }
        }