//释放相关资源 /// <summary> /// 释放相关资源 /// </summary> public void Dispose() { try { if (NeedFormControlFlag == true) { TargetPCI1750OutCard.Dispose(); TargetPCI1750OutCard = null; } if (UpdateInputSignal != null) { UpdateInputSignal.Abort(); UpdateInputSignal = null; } TargetDIOCard = null; TargetDevice.Close(); TargetDevice.Dispose(); } catch (Exception)// ex) { //ErrorMessage = ex.Message;; } }
public void Dispose() { if (Interlocked.Exchange(ref _disposed, 1) == default(int)) { _di?.Dispose(); _do?.Dispose(); } }
/// <summary> /// 关闭驱动 /// </summary> public void CloseDevice() { timerAi.Enabled = false; timerDi.Enabled = false; timerCnt.Enabled = false; waveformAiCtrlUsb4704.Dispose(); instantDiCtrlUsb4704.Dispose(); instantDoCtrlUsb4704.Dispose(); eventCounterCtrlUsb4704.Dispose(); instantAoCtrlUsb4704.Dispose(); }
static void Main(string[] args) { string deviceDescription = "USB-4704,BID#0"; string profilePath = @"C:\Advantech\Profile\p2.xml"; tcClient = new TcAdsClient(); dataStream = new AdsStream(1); instantDoCtrl = new InstantDoCtrl(); binReader = new BinaryReader(dataStream, System.Text.Encoding.ASCII); tcClient.Connect(851); try { instantDoCtrl.SelectedDevice = new DeviceInformation(deviceDescription); errorCode = instantDoCtrl.LoadProfile(profilePath);//Loads a profile to initialize the device. if (BioFailed(errorCode)) { throw new Exception(); } hDigOutP0 = tcClient.AddDeviceNotification("A4704.byDigOutP0", dataStream, 0, 1, AdsTransMode.OnChange, 10, 0, huValHandle); hEndA4704Program = tcClient.AddDeviceNotification("A4704.bEndA4704Program", dataStream, 0, 1, AdsTransMode.OnChange, 10, 0, huValHandle); tcClient.AdsNotification += new AdsNotificationEventHandler(OnNotification); HeartbeatThread heartbeat = new HeartbeatThread(tcClient); heartbeatThread = new Thread(new ThreadStart(heartbeat.beat)); heartbeatThread.Start(); manualResetEvent = new ManualResetEvent(false); manualResetEvent.WaitOne(); //Console.ReadKey(false); } 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 { instantDoCtrl.Dispose(); heartbeatThread.Abort(); heartbeatThread.Join(); tcClient.DeleteDeviceNotification(hDigOutP0); tcClient.Dispose(); } }
public void Dispose() { if (!disposed) { disposed = true; if (_di != null) { _di.Dispose(); } if (_do != null) { _do.Dispose(); } } }
//释放相关资源 /// <summary> /// 释放相关资源 /// </summary> public void Dispose() { try { if (NeedFormControlFlag == true) { TargetPCI1752Card.Dispose(); TargetPCI1752Card = null; } TargetDOCard = null; TargetDevice.Close(); TargetDevice.Dispose(); } catch (Exception)// ex) { //ErrorMessage = ex.Message;; } }
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; } }
/// <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; } }
/// <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; }
private void Work_Form_FormClosed(object sender, FormClosedEventArgs e) { PCI_1751.Write(5, 0xFF); //SW-POW (PC14) off PCI_1751.Dispose(); if ((RS422_Port != null) && (RS422_Port.IsOpen)) { RS422_Port.DataReceived -= DataReceivedHandler; RS422_Port.Close(); } timer1.Stop(); if (BinPath != null && File.Exists(BinPath)) { File.Delete(BinPath); } if (!BackToMainMenu) { Application.Exit(); } }
public void DIDO_Release() { instantDiCtrl.Dispose(); instantDoCtrl.Dispose(); }
/// <summary> /// Destroy /// </summary> public override void Destroy() { instantDoCtrl.Dispose(); instantDiCtrl.Dispose(); base.Destroy(); }
public override void Release() { m_do.Dispose(); m_di.Dispose(); }
public void UpdateStaticDO_manual() { //----------------------------------------------------------------------------------- // 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; ErrorCode errorCode = ErrorCode.Success; // Step 1: Create a 'InstantDoCtrl' for DO function. InstantDoCtrl instantDoCtrl = new InstantDoCtrl(); 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. instantDoCtrl.SelectedDevice = new DeviceInformation(deviceDescription); errorCode = instantDoCtrl.LoadProfile(profilePath);//Loads a profile to initialize the device. if (BioFailed(errorCode)) { throw new Exception(); } // Step 3: Write DO ports byte[] bufferForWriting = new byte[64]; //byte dataForWriteBit = 0;//data is used to the 'WriteBit'. //int bit = 1;//the bit is used to the 'WriteBit'. for (int i = 0; i < portCount; ++i) { Console.WriteLine("Input a hexadecimal number for DO port {0} to output(for example, 0x11): ", startPort + i); string data = Console.ReadLine(); bufferForWriting[i] = byte.Parse(data.Contains("0x") ? data.Remove(0, 2) : data, System.Globalization.NumberStyles.HexNumber); /* * //for WriteBit * Console.WriteLine(" Input a hexadecimal number for DO port {0} to output(for example, 0x1 or 0x00): ", startPort + i); * string data = Console.ReadLine(); * dataForWriteBit = byte.Parse(data.Contains("0x") ? data.Remove(0, 2) : data, System.Globalization.NumberStyles.HexNumber); */ } errorCode = instantDoCtrl.Write(startPort, portCount, bufferForWriting); /************************************************************************/ //errorCode = instantDoCtrl.WriteBit(startPort, bit, dataForWriteBit); //NOTE: //Every channel has 8 bits, which be used to control 0--7 bit of anyone channel. //argument1:which port you want to contrl? For example, startPort is 0. //argument2:which bit you want to control? You can write 0--7, any number you want. //argument3:What status you want, open or close? 1 menas open, 0 means close.*/ /************************************************************************/ if (BioFailed(errorCode)) { throw new Exception(); } Console.WriteLine("DO output completed !"); // Read back the DO status. // Note: // For relay output, the read back must be deferred until the relay is stable. // The delay time is decided by the HW SPEC. // byte[] bufferForReading = new byte[64]; // instantDoCtrl.DoRead(startPort, portCount, bufferForReading); // if (BioFailed(errorCode)) // { // throw new Exception(); // } // Show DO ports' status // for (int i = startPort; i < portCount + startPort; ++i) // { // Console.WriteLine("Now, DO port {0} status is: 0x{1:x}", i, bufferForReading[i - startPort]); // } } 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. instantDoCtrl.Dispose(); //Console.ReadKey(false); } }