Пример #1
0
        //释放相关资源
        /// <summary>
        /// 释放相关资源
        /// </summary>
        public void Dispose()
        {
            try
            {
                if (NeedFormControlFlag == true)
                {
                    TargetPCI1754Card.Dispose();
                    TargetPCI1754Card = null;
                }

                if (UpdateInputSignal != null)
                {
                    UpdateInputSignal.Abort();
                    UpdateInputSignal = null;
                }

                TargetDICard = null;
                TargetDevice.Close();
                TargetDevice.Dispose();
            }
            catch (Exception)// ex)
            {
                //ErrorMessage = ex.Message;;
            }
        }
Пример #2
0
 public void Dispose()
 {
     if (Interlocked.Exchange(ref _disposed, 1) == default(int))
     {
         _di?.Dispose();
         _do?.Dispose();
     }
 }
Пример #3
0
 /// <summary>
 /// 关闭驱动
 /// </summary>
 public void CloseDevice()
 {
     timerAi.Enabled  = false;
     timerDi.Enabled  = false;
     timerCnt.Enabled = false;
     waveformAiCtrlUsb4704.Dispose();
     instantDiCtrlUsb4704.Dispose();
     instantDoCtrlUsb4704.Dispose();
     eventCounterCtrlUsb4704.Dispose();
     instantAoCtrlUsb4704.Dispose();
 }
Пример #4
0
 public void Dispose()
 {
     if (!disposed)
     {
         disposed = true;
         if (_di != null)
         {
             _di.Dispose();
         }
         if (_do != null)
         {
             _do.Dispose();
         }
     }
 }
Пример #5
0
        public void forceRefresh()
        {
            try
            {
                instantDiCtrl1.Dispose();
                instantDoCtrl1.Dispose();
            }
            catch
            {
                Console.WriteLine("Timer not started");
            }

            try
            {
                //Kreiranje objekata za upravljanje I/O uređajem
                instantDoCtrl1.SelectedDevice = new DeviceInformation(1);
                instantDiCtrl1.SelectedDevice = new DeviceInformation(1);

                //Učitavanja profila I/O Modula
                IOprofile = "D:/N046_17 DOKUMENTACIJA I PROGRAM/Res/ioProfile.xml";

                //Provjera učitavanja profila
                ErrorCode errProfile = ErrorCode.Success;
                errProfile = instantDiCtrl1.LoadProfile(IOprofile);
                if (errProfile != ErrorCode.Success)
                {
                    HandleError(errProfile);
                }
                else
                {
                    // Globals.pCol.writeLog(0, "I/O card profile loaded", "");
                }
            }

            catch (Exception ex)
            {
                //Globals.pCol.writeLog(2, "I/O card not ready", "");
                refreshDeviceTimer.Stop();
                MessageBox.Show("Device not ready: " + ex.ToString());
                return;
            }
        }
Пример #6
0
        /// <summary>
        /// 尝试释放资源
        /// </summary>
        public void Close()
        {
            DeviceDiscriptionOfInstance = "";

            if (DoInstance != null)
            {
                if (DoInstance.Initialized)
                {
                    DoInstance.Dispose();
                }
                DoInstance = null;
            }
            if (DiInstance != null)
            {
                if (DiInstance.Initialized)
                {
                    DiInstance.Dispose();
                }
                DiInstance = null;
            }
        }
Пример #7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="disposing"></param>
 /// <remarks>
 /// Dispose(bool disposing) executes in two distinct scenarios.
 /// If disposing equals true, the method has been called directly
 /// or indirectly by a user's code. Managed and unmanaged resources
 /// can be disposed.
 /// If disposing equals false, the method has been called by the
 /// runtime from inside the finalizer and you should not reference
 /// other objects. Only unmanaged resources can be disposed.
 /// </remarks>
 private void Dispose(bool disposing)
 {
     // Check to see if Dispose has already been called.
     if (_disposed)
     {
         return;
     }
     // If disposing equals true, dispose all managed and unmanaged resources.
     if (disposing)
     {
         // Dispose managed resources.
         // Step 4: Close device and release any allocated resource.
         InstantAiContrl.Dispose();
         InstantAoContrl.Dispose();
         InstantDiCtrl.Dispose();
         InstantDoCtrl.Dispose();
         _baseDioCtrl.Dispose();
     }
     // Dispose native ( unmanaged ) resources, if exits
     // Note disposing has been done.
     _disposed = true;
 }
Пример #8
0
 public void DIDO_Release()
 {
     instantDiCtrl.Dispose();
     instantDoCtrl.Dispose();
 }
Пример #9
0
 /// <summary>
 /// Destroy
 /// </summary>
 public override void Destroy()
 {
     instantDoCtrl.Dispose();
     instantDiCtrl.Dispose();
     base.Destroy();
 }
Пример #10
0
 public void Dispose()
 {
     advantechDIControl?.Dispose();
 }
Пример #11
0
 public override void Release()
 {
     m_do.Dispose();
     m_di.Dispose();
 }
        public void UpdateStaticDI()
        {
            //-----------------------------------------------------------------------------------
            // Configure the following parameters before running the demo
            //-----------------------------------------------------------------------------------
            //The default device of project is demo device, users can choose other devices according to their needs.
            string deviceDescription = "PCI-1750,BID#0";
            string profilePath       = "../../profile/PCI-1750.xml";
            int    startPort         = 0;
            int    portCount         = 2;
            short  fullResponse      = 0;

            StaticIO_firstTime = true;
            ErrorCode errorCode = ErrorCode.Success;

            // Step 1: Create a 'InstantDiCtrl' for DI function.
            InstantDiCtrl instantDiCtrl = new InstantDiCtrl();

            try
            {
                // Step 2: Select a device by device number or device description and specify the access mode.
                // in this example we use ModeWrite mode so that we can fully control the device, including configuring, sampling, etc.
                instantDiCtrl.SelectedDevice = new DeviceInformation(deviceDescription);
                errorCode = instantDiCtrl.LoadProfile(profilePath);//Loads a profile to initialize the device.
                if (BioFailed(errorCode))
                {
                    throw new Exception();
                }
                // read DI ports' status and show.
                //Console.WriteLine("Reading ports' status is in progress..., any key to quit!\n");
                byte[] buffer = new byte[64];
                //byte data = 0;//data is used to the API ReadBit.
                //int  bit = 0;//bit is used to the API ReadBit.

                // Step 3: Read DI ports' status and show.
                errorCode = instantDiCtrl.Read(startPort, portCount, buffer);
                //errorCode = instantDiCtrl.ReadBit(startPort, bit, out data);
                if (BioFailed(errorCode))
                {
                    throw new Exception();
                }
                //Show ports' status
                for (int i = 0; i < portCount; ++i)
                {
                    if (_showVerboseMessage)
                    {
                        Console.WriteLine(" DI port {0} status : 0x{1:x}\n", startPort + i, buffer[i]);
                    }


                    /************************************************************************/
                    //Console.WriteLine(" DI port {0} status : 0x{1:x}\n", startPort + i, data);
                    //NOTE:
                    //argument1:which port you want to control? For example, startPort is 0.
                    //argument2:which bit you want to control? You can write 0--7, any number you want.
                    //argument3:data is used to save the result.
                    /************************************************************************/
                }
                fullResponse = (short)(buffer[0] | buffer[1] << 8);
                extractAndsetNum(fullResponse);

                //Thread.Sleep(100);
            }
            catch (Exception e)
            {
                // Something is wrong
                string errStr = BioFailed(errorCode) ? " Some error occurred. And the last error code is " + errorCode.ToString()
                                                          : e.Message;
                Console.WriteLine(errStr);
            }
            finally
            {
                // Step 4: Close device and release any allocated resource.
                instantDiCtrl.Dispose();
                //Console.ReadKey(false);
            }
        }