示例#1
0
        private bool Connect1751()
        {
            try
            {
                //присваивание объектам классов InstantDi(о)Ctrl параметров платы, имеющей ID = DeviceNumber
                PCI_1751.SelectedDevice = new DeviceInformation(Find1751());

                PCI_1751.Write(5, 0xFF);                    //SW-POW (PC14) off

                //настройка портов на выход/вход
                PortDirection[] portDirs = PCI_1751.PortDirection;
                portDirs[5].Direction = DioPortDir.LinHout; //PC10 - input (ZPR), PC14 - output (SW-POW)

                portDirs[0].Direction = DioPortDir.Input;   //Data_0-7
                portDirs[1].Direction = DioPortDir.Input;   //Data_8-15
                portDirs[2].Direction = DioPortDir.LinHout; //PC00 - input (ZPR), PC04 - INIT, PC05 - WA, PC06 - RD, PC07 - WD
            }
            catch (Exception)
            {
                FormConsole.AppendText("Не удалось сконфигурировать PCI-1751! Проверьте подключение!\n");
                FormConsole.ScrollToCaret();
                return(false);
            }

            return(true);
        }
示例#2
0
文件: PCI1762.cs 项目: xllj/xlDriver
        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;
        }
示例#3
0
 /// <summary>
 /// sets 0/1 "level" on port "port"
 /// </summary>
 /// <param name="port">port no</param>
 /// <param name="level">0/1</param>
 private void setPortDO(int port, byte level)
 {
     if (effectorsActive)
     {
         try
         {
             if (level == 1)
             {
                 buffer |= (1 << port);
                 instantDoCtrl.Write(0, (byte)buffer);
             }
             else if (level == 0)
             {
                 buffer &= ~(1 << port);
                 instantDoCtrl.Write(0, (byte)buffer);
             }
             else
             {
                 throw new ArgumentException("wrong level value - it should be 0/1", "level");
             }
         }
         catch (Exception)
         {
             Logger.Log(this, "msg couldn't been send via extentionCardCommunicator - probably because of no connection", 2);
         }
     }
     else
     {
         Logger.Log(this, "analog port was not set, because effectors are no active");
     }
 }
        //研华输出卡PCI1752刷新输出
        /// <summary>
        /// 研华输出卡PCI1752刷新输出
        /// </summary>
        /// <param name="Out">输出的IO数组,长度必须等于64,对应64位输出位</param>
        /// <returns>是否执行成功</returns>
        public bool SetOutput(IO[] Out)
            {
            if (PasswordIsCorrect == false || SuccessBuiltNew == false)
                {
                return false;
                }
            try
                {
                if(Out.Length != 64)
                    {
                    ErrorMessage = "函数SetOutput的参数'Out'数组长度不等于64";
                    return false;
                    }
                //思路:传入的参数数组总计64个,0~7为端口0,依次类推,直到端口7
                for (int Port = 0; Port <= 7; Port++) 
                    {
                    int PortOutputStatus = 0;
                    int TempByte = 0;
                    for (int a = 7; a >= 0; a--) 
                        {
                        if (Out[Port * 8 + a] == IO.On)
                            {
                            TempByte = 1;
                            }
                        else 
                            {
                            TempByte = 0;
                            }
                        PortOutputStatus = (PortOutputStatus << 1) | TempByte & 0x1;                        
                        }

                    //需要从窗体控件传入引用进行实例化
                    if (NeedFormControlFlag == true)
                        {
                        TargetPCI1752Card.Write(Port, (byte)PortOutputStatus);
                        }
                    else
                        {
                        //直接用设备编号进行实例化
                        TargetDOCard.DoWrite(Port, (byte)PortOutputStatus);
                        }
                    }

                return true;
                }
            catch (Exception)// ex)
                {
                //ErrorMessage = ex.Message;
                return false;
                }
            }
示例#5
0
        public bool SetDoMode(byte[] arrPortData)
        {
            byte byteData = 0x00;

            for (int i = 0; i < arrPortData.Length; i++)
            {
                byteData |= Convert.ToByte(arrPortData[i] << i);
            }
            ErrorCode err = instantDoCtrlUsb4704.Write(0, byteData);

            if (err != ErrorCode.Success)
            {
                ActiveEventError("初始化数字输出失败:" + err.ToString());
                return(false);
            }
            return(true);
        }
示例#6
0
 public void WriteDoState(int port)
 {
     err = DoController.Write(port, StateDoToWrite);
     if (err != ErrorCode.Success)
     {
         throw new Exception("Sorry ! Some errors happened, the error code is: " + err.ToString());
     }
 }
示例#7
0
文件: PCI1762.cs 项目: xllj/xlDriver
 public override void Write(Int32 PORTx, Int32 portValue)
 {
     lock (syscWriteObject)
     {
         if (!isDoInitialized)
         {
             return;
         }
         m_do.Write(PORTx, (Byte)portValue);
     }
 }
示例#8
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);
        }
示例#9
0
        public override void Write(int _values_out)
        {
            if (disposed)
            {
                return;
            }
            values_out = _values_out;
            buf_out    = BitConverter.GetBytes(values_out);
            ErrorCode ret = ctrl_out.Write(portStart, portCount_out, buf_out);

            if (ret != ErrorCode.Success)
            {
                throw new Exception("Board1730.Write: Ошибка: " + ret.ToString());
            }
        }
示例#10
0
 private static void OnNotification(object sender, AdsNotificationEventArgs e)
 {
     if (e.NotificationHandle == hDigOutP0)
     {
         portValue = binReader.ReadByte();
         errorCode = instantDoCtrl.Write(port, portValue);
     }
     else if (e.NotificationHandle == hEndA4704Program)
     {
         bEndProgram = binReader.ReadBoolean();
         if (bEndProgram)
         {
             manualResetEvent.Set();
         }
     }
 }
示例#11
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;
            }
        }
 public bool Write(int port, int pin, bool value)
 {
     lock (_writeLock)
     {
         if (_do.Read(port, out var portValue) != ErrorCode.Success)
         {
             return(false);
         }
         if (value)
         {
             portValue = (byte)(portValue | 0x1 << pin);
         }
         else
         {
             portValue = (byte)(portValue & ~(0x1 << pin));
         }
         return(_do.Write(portValue, portValue) == ErrorCode.Success);
     }
 }
        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);
            }
        }
示例#14
0
        public void setOutput(int portNum, int state)
        {
            //private static object locker = new Object();

            //lock (locker)
            //{
            try
            {
                ErrorCode err = ErrorCode.Success;
                err = instantDoCtrl1.Write(portNum, (byte)state);
                if (err != ErrorCode.Success)
                {
                    HandleError(err);
                }
                Globals.pCol.writeLog(0, "Output set to: " + state.ToString(), "");
            }
            catch (Exception ex)
            {
                Globals.pCol.writeLog(0, "Error while setting output: " + ex.ToString(), "");
                //locker = null;
            }
            //}
        }
示例#15
0
        /// <summary>
        /// Подпрограмма записи данных в порт
        /// </summary>
        /// <param name="port">Имя порта</param>
        /// <param name="value">Данные</param>
        /// <returns></returns>
        public void WritePort(int port, 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.Write(port, value);

            if (error_code != ErrorCode.Success)
            {
                // Возникла ошибка
                throw new Exception <Pci1753ExceptionArgs>(new Pci1753ExceptionArgs(0),
                                                           $"Ошибка записи байта данных в порт {port:D} интерфейсной платы PCI-1753 - {error_code}");
            }
        }
示例#16
0
 /// <summary>
 /// 写入整个8位数据
 /// </summary>
 /// <param name="data"></param>
 public virtual void WriteByte(byte data)
 {
     DoInstance.Write(0, data);
     doBuffer = data;
 }
        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);
            }
        }
示例#18
0
 public static ErrorCode DoWrite(int port, byte data)
 {
     return(instantDoCtrl.Write(port, data));
 }