Esempio n. 1
0
        public override void Init()
        {
            //初始化窗体
            FilePath = Assembly.GetExecutingAssembly().Location;
            String path = Path.GetDirectoryName(FilePath);

            DeviceDescription = xlIni.INIGetStringValue(FilePath + ".ini", "PCI1762", "DeviceDescription", null);
            if (DeviceDescription == null)
            {
                DeviceDescription = "DemoDevice,BID#0";
                xlIni.INIWriteValue(FilePath + ".ini", "PCI1762", "DeviceDescription", DeviceDescription);
            }
            isDiInitialized = true;
            isDoInitialized = true;
            m_do            = new InstantDoCtrl();
            m_di            = new InstantDiCtrl();
            try
            {
                m_do.SelectedDevice = new DeviceInformation(DeviceDescription);
                m_di.SelectedDevice = new DeviceInformation(DeviceDescription);

                m_do.Write(0, 0);
                m_do.Write(1, 0);
            }
            catch (Exception)
            {
                throw;
            }

            isDoInitialized = m_do.Initialized;
            isDiInitialized = m_di.Initialized;
        }
Esempio n. 2
0
        //释放相关资源
        /// <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;;
            }
        }
Esempio n. 3
0
 //【重载】创建PCI1752更新输出及输出状态回读类的实例
 /// <summary>
 /// 【重载】创建PCI1752更新输出及输出状态回读类的实例
 /// </summary>
 /// <param name="TargetCard">目标PCI1752卡【窗体控件的形式】</param>
 /// <param name="DLLPassword">使用此DLL的密码</param>
 public PCI1752(ref Automation.BDaq.InstantDoCtrl TargetCard, string DLLPassword)
 {
     SuccessBuiltNew   = false;
     PasswordIsCorrect = false;
     try
     {
         TargetPCI1752Card = TargetCard;
         if (TargetPCI1752Card.Initialized == true)
         {
             NeedFormControlFlag = true;
             ReadOnlyFlag        = false;
             SuccessBuiltNew     = true;
         }
         else
         {
             MessageBox.Show("参数'TargetCard'传递的PCI1752控件初始化失败,没有选择设备或者是设备打开失败,请检查具体原因。", "错误");
             SuccessBuiltNew = false;
             return;
         }
     }
     catch (Exception ex)
     {
         SuccessBuiltNew = false;
         MessageBox.Show("创建类的实例时出现错误!\r\n" + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
 }
        public PCIRelayCard()
        {
            DoController = new InstantDoCtrl();
            DiReader     = new InstantDiCtrl();
            string deviceDescription = "DemoDevice,BID#0";

            DoController.SelectedDevice = new DeviceInformation(deviceDescription);
            DiReader.SelectedDevice     = new DeviceInformation(deviceDescription);
Esempio n. 5
0
        public void Init()
        {
            m_do = new InstantDoCtrl();
            m_di = new InstantDiCtrl();

            m_do.SelectedDevice = new DeviceInformation(DeviceDescription);
            m_di.SelectedDevice = new DeviceInformation(DeviceDescription);
        }
Esempio n. 6
0
 public PCIRelayCard(int deviceNumber)
 {
     DoController = new InstantDoCtrl();
     DoController.SelectedDevice = new DeviceInformation(deviceNumber);
     DiReader = new InstantDiCtrl();
     DiReader.SelectedDevice = new DeviceInformation(deviceNumber);
     stateDoToWrite          = ReadDoState(this.IORelayPort);
     ReadDiState(this.IDIPort);
 }
Esempio n. 7
0
 public Board1730(PCIE1730pars _pars, DOnPr _OnPr)
     : base(_pars, _OnPr)
 {
     ctrl_in  = new InstantDiCtrl();
     ctrl_out = new InstantDoCtrl();
     ctrl_in.SelectedDevice  = new DeviceInformation(_pars.Devnum);
     ctrl_out.SelectedDevice = new DeviceInformation(_pars.Devnum);
     buf_in  = new byte[portCount_in];
     buf_out = new byte[portCount_out];
 }
Esempio n. 8
0
 public void Initialize()
 {
     _deviceInformation = new DeviceInformation(DeviceId);
     _di = new InstantDiCtrl();
     _di.SelectedDevice = _deviceInformation;
     InputPortCount     = _di.Features.PortCount;
     InputPortState     = new byte[InputPortCount];
     _do = new InstantDoCtrl();
     _do.SelectedDevice = _deviceInformation;
     OutputPortCount    = _do.Features.PortCount;
 }
Esempio n. 9
0
        public PCIRelayCard()
        {
            DoController = new InstantDoCtrl();
            DiReader     = new InstantDiCtrl();
            string deviceDescription = "DemoDevice,BID#0";

            DoController.SelectedDevice = new DeviceInformation(deviceDescription);
            DiReader.SelectedDevice     = new DeviceInformation(deviceDescription);
            stateDoToWrite = ReadDoState(this.IORelayPort);
            ReadDiState(this.IDIPort);
        }
Esempio n. 10
0
        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();
            }
        }
Esempio n. 11
0
        /// <summary>
        /// 尝试启动
        /// </summary>
        public void Open()
        {
            if (!IsOpen())
            {
                DiInstance = new InstantDiCtrl();
                DiInstance.SelectedDevice = new DeviceInformation(DeviceDiscription);

                DoInstance = new InstantDoCtrl();
                DoInstance.SelectedDevice = new DeviceInformation(DeviceDiscription);

                DeviceDiscriptionOfInstance = DeviceDiscription;
            }
            doBuffer = Read_do();
        }
Esempio n. 12
0
        public LongmenDevice(IPort port, ISerialize serialize) :
            base(port, serialize)
        {
            _device        = new DeviceInformation(((PortBase)port).Port);
            _instantDoCtrl = new InstantDoCtrl();
            _instantDoCtrl.SelectedDevice = _device;
            _instantDiCtrl = new InstantDiCtrl();
            _instantDiCtrl.SelectedDevice = _device;

            byte[] data = new byte[4];
            _instantDoCtrl.Write(0, data.Length, data);
            _option = default(eLongMenOption);
            _instantDiCtrl.Read(0, data.Length, data);
            Status = (eLongMenState)BitConverter.ToUInt32(data, 0);
        }
Esempio n. 13
0
 /// <summary>
 ///
 /// </summary>
 protected DaqPciClass()
 {
     // Step 1:
     // Create a 'InstantAiCtrl' for Instant AI function.
     InstantAiContrl = new InstantAiCtrl();
     // Create a 'InstantAoCtrl' for Instant AO function.
     InstantAoContrl = new InstantAoCtrl();
     // DioCtrlBase class used for digital input(DI),digital input
     // related interrupt,digital output operations(DO);
     _baseDioCtrl = new DioCtrlBase();
     // Create a 'InstantDiCtrl' for DI function.
     InstantDiCtrl = new InstantDiCtrl();
     // Create a 'InstantDoCtrl' for DO function.
     InstantDoCtrl = new InstantDoCtrl();
 }
Esempio n. 14
0
        protected override void SafeMode()
        {
            if (!IsInit)
            {
                return;
            }
            // Задание безопасной конфигурации конфигурации
            var port_dirs = InstantDiCtrl.PortDirection;

            for (var port = 0; port < ChannelCountMax; port++)
            {
                // В регистры выдачи записываются значения, соответствующие 0В
                InstantDoCtrl.Write(port, 0);
                // Все порты настраиваются на ввод
                port_dirs[port].Direction = DioPortDir.Input;
            }
        }
 //private event EventHandler<DiSnapEventArgs> interruptEvent;
 public BoardCardControl(string deviceDescription, string profilePath = "")
 {
     this.deviceDescription            = deviceDescription;
     this.profilePath                  = profilePath;
     this.instantDiCtrl                = new InstantDiCtrl();
     this.instantDoCtrl                = new InstantDoCtrl();
     this.instantDiCtrl.SelectedDevice = new DeviceInformation(this.DeviceDescription);
     this.instantDoCtrl.SelectedDevice = new DeviceInformation(this.DeviceDescription);
     //this.instantDiCtrl.Interrupt += new EventHandler<DiSnapEventArgs>(this.instantDiCtrl_Interrupt);
     //Todo::待测
     if (String.IsNullOrEmpty(this.ProfilePath) && this.instantDiCtrl.Device != null &&
         this.instantDoCtrl.Device != null)
     {
         this.instantDiCtrl.LoadProfile(this.ProfilePath);
         this.instantDoCtrl.LoadProfile(this.profilePath);
     }
 }
        protected override void Run()
        {
            ////Insert Step logic here

            //Image img = Image;
            //_numericOutput = NumericInput * img.SizeX * img.SizeY;
            InstantDoCtrl instantDoCtrl1 = new InstantDoCtrl();

            instantDoCtrl1.SelectedDevice = new DeviceInformation(1);
            if (instantDoCtrl1.Initialized)
            {
                DoBitInformation boxInfo = new DoBitInformation();
                boxInfo.BitNum   = 7;
                boxInfo.BitValue = 1;
                boxInfo.PortNum  = 0;
                int state = 0;
                instantDoCtrl1.Write(boxInfo.PortNum, (byte)state);
            }
        }
Esempio n. 17
0
        //释放相关资源
        /// <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;;
            }
        }
Esempio n. 18
0
 public void Initialize()
 {
     try
     {
         _deviceInformation = new DeviceInformation(DeviceId);
         _di = new InstantDiCtrl {
             SelectedDevice = _deviceInformation
         };
         InputPortCount = _di.Features.PortCount;
         InputPortState = new byte[InputPortCount];
         _do            = new InstantDoCtrl {
             SelectedDevice = _deviceInformation
         };
         OutputPortCount = _do.Features.PortCount;
     }
     catch (Exception e)
     {
         Logger.Error(e);
     }
 }
Esempio n. 19
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;
            }
        }
 //【重载】创建PCI1752更新输出及输出状态回读类的实例
 /// <summary>
 /// 【重载】创建PCI1752更新输出及输出状态回读类的实例
 /// </summary>
 /// <param name="TargetCard">目标PCI1752卡【窗体控件的形式】</param>
 /// <param name="DLLPassword">使用此DLL的密码</param>
 public PCI1752(ref Automation.BDaq.InstantDoCtrl TargetCard, string DLLPassword)
     {
     SuccessBuiltNew = false;
     PasswordIsCorrect = false;
     try
         {
         if (DLLPassword == "ThomasPeng" || (DLLPassword == "pengdongnan")
             || (DLLPassword == "彭东南"))
             {
             PasswordIsCorrect = true;
             TargetPCI1752Card = TargetCard;
             if (TargetPCI1752Card.Initialized == true)
                 {
                 NeedFormControlFlag = true;
                 ReadOnlyFlag = false;
                 SuccessBuiltNew = true;
                 }
             else
                 {
                 MessageBox.Show("参数'TargetCard'传递的PCI1752控件初始化失败,没有选择设备或者是设备打开失败,请检查具体原因。","错误");
                 SuccessBuiltNew = false;
                 return;
                 }
             }
         else
             {
             PasswordIsCorrect = false;
             SuccessBuiltNew = false;
             MessageBox.Show("Right Prohibited.\return\n     You don't have the given right to use this DLL library, please contact with ThomasPeng.\r\n你未得到授权的密码,无法使用此DLL进行软件开发!请与作者彭东南联系:[email protected]\r\n                                                                版权所有: 彭东南", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             return;
             }
         }
     catch (Exception ex)
         {
         SuccessBuiltNew = false;
         MessageBox.Show("创建类的实例时出现错误!\r\n" + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
         }
     }
Esempio n. 21
0
        /// <summary>
        /// Подпрограмма записи данных в порт
        /// </summary>
        /// <param name="port">Имя порта</param>
        /// <param name="bit"></param>
        /// <param name="value">Данные</param>
        /// <returns></returns>
        public void WriteBit(int port, int bit, byte value)
        {
            if (!IsInit)
            {
                // Модуль не инициализирован
                throw new Exception <Pci1753ExceptionArgs>(new Pci1753ExceptionArgs(0),
                                                           "The object of card Pci1753 is not initialized");
            }
            if (port < 0 || port >= ChannelCountMax)
            {
                // Номер канала задан неверно
                throw new Exception <Pci1753ExceptionArgs>(new Pci1753ExceptionArgs(0),
                                                           $"The port {port} of card Pci1753 is not valid");
            }
            var error_code = InstantDoCtrl.WriteBit(port, bit, value);

            if (error_code != ErrorCode.Success)
            {
                // Возникла ошибка
                throw new Exception <Pci1753ExceptionArgs>(new Pci1753ExceptionArgs(0),
                                                           $"Ошибка записи бита данных в порт {port:D} интерфейсной платы PCI-1753 - {error_code}");
            }
        }
Esempio n. 22
0
        public IOControl()
        {
            Console.WriteLine("New IOcontrol object created");

            instantDiCtrl1 = new InstantDiCtrl();
            instantDoCtrl1 = new InstantDoCtrl();

            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", "");
                MessageBox.Show("Device not ready: " + ex.ToString());
                return;
            }

            //Provjera inicijalizacije Digitalnih outputa
            if (!instantDoCtrl1.Initialized)
            {
                Globals.pCol.writeLog(2, "No device selected or device open failed!", "");
                MessageBox.Show("No device selected or device open failed!", "StaticDO");
                return;
            }

            //Provjera inicijalizacije Digitalnih inputa
            if (!instantDiCtrl1.Initialized)
            {
                Globals.pCol.writeLog(2, "No device selected or device open failed!", "");
                MessageBox.Show("No device selected or device open failed!", "StaticDI");
                return;
            }

            /*
             * Kreiranje i pokretanje update timera
             * 50 ms
             * stopTimerInterval - parametar kojim se definira vrijeme vrtnje motora nakon što se ugasi separator 1.
             */
            timerChStats          = new System.Windows.Forms.Timer();
            updateTick            = 50;
            timerChStats.Interval = updateTick;
            timerChStats.Start();
            timerChStats.Tick += new EventHandler(updateStatus);
            rotationDirection  = "0";
            stopTimerInterval  = Int32.Parse(Globals.stopTimerInt);

            /*
             * refreshDeviceTimer = new Timer();
             * refreshDeviceTimer.Interval = 400;
             * refreshDeviceTimer.Tick += new EventHandler(refreshIODevice);
             * refreshDeviceTimer.Start();
             */
            Belt_counter     = 0;
            Belt_counterOld  = 0;
            tickCount        = 0;
            TotalStop_ACTIVE = false;
            //resetOutputs();
        }
        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);
            }
        }