示例#1
0
        /// <summary>
        /// Подрограмма считывания данных из порта
        /// </summary>
        /// <param name="port">Имя порта</param>
        /// <param name="bit"></param>
        /// <returns></returns>
        public byte ReadBit(int port, int bit)
        {
            byte value;

            if (!IsInit)
            {
                // Модуль не инициализирован
                throw new Exception <Pci1753ExceptionArgs>(new Pci1753ExceptionArgs(0),
                                                           "The object of card Pci1753 is not initialized");
            }
            if (0 > port || ChannelCountMax <= port)
            {
                // Номер канала задан неверно
                throw new Exception <Pci1753ExceptionArgs>(new Pci1753ExceptionArgs(0),
                                                           $"The port {port} of card Pci1753 is not valid");
            }
            var error_code = InstantDiCtrl.ReadBit(port, bit, out value);

            if (error_code != ErrorCode.Success)
            {
                // Возникла ошибка
                throw new Exception <Pci1753ExceptionArgs>(new Pci1753ExceptionArgs(0),
                                                           $"Ошибка чтения бита данных из порта {port:D} интерфейсной платы PCI-1753 - {error_code}");
            }
            return(value);
        }
示例#2
0
        public bool GetDiModeBit(int bit, byte portData)
        {
            portData = new byte();
            ErrorCode err = instantDiCtrlUsb4704.ReadBit(0, bit, out byte data);

            if (err != ErrorCode.Success)
            {
                ActiveEventError("获取数字输入失败:" + err.ToString());
                return(false);
            }
            portData = data;
            return(true);
        }
示例#3
0
文件: PCI1762.cs 项目: xllj/xlDriver
 public override Boolean Read(Int32 PORTx, Int32 Pin)
 {
     lock (syscReadObject)
     {
         if (!isDoInitialized)
         {
             return(false);
         }
         try
         {
             Byte data = 0;
             m_di.ReadBit(PORTx, Pin, out data);
             return(data == 1);
         }
         catch
         {
             return(false);
         }
     }
 }
示例#4
0
        private int StaticDI_Get(int channel)
        {
            try
            {
                instantDiCtrl.SelectedDevice = new DeviceInformation(deviceNumber);

                byte data = new byte();

                errorCode = instantDiCtrl.ReadBit(ChannelToPort(channel), ChannelToBit(channel), out data);
                if (BioFailed(errorCode))
                {
                    throw new Exception();
                }
                return(data);
            }
            catch (Exception e)
            {
                // Something is wrong
                string errStr = BioFailed(errorCode) ? " Some error occurred. And the last error code is " + errorCode.ToString()
                                                          : e.Message;
                return(-1);
            }
        }