Ejemplo n.º 1
0
        public bool StaticDO_Set(int channel, bool open)
        {
            try
            {
                instantDoCtrl.SelectedDevice = new DeviceInformation(deviceNumber);

                if (open)
                {
                    errorCode = instantDoCtrl.WriteBit(ChannelToPort(channel), ChannelToBit(channel), 1);
                }
                else
                {
                    errorCode = instantDoCtrl.WriteBit(ChannelToPort(channel), ChannelToBit(channel), 0);
                }

                /************************************************************************/
                //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();
                }
                // 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 errorForReadingDO = new byte();
                errorCode = instantDoCtrl.ReadBit(ChannelToPort(channel), ChannelToBit(channel), out errorForReadingDO);
                //if (errorForReadingDO != Convert.ToByte(open))
                //{
                //    throw new Exception();
                //}
                if (BioFailed(errorCode))
                {
                    throw new Exception();
                }
                return(true);
            }
            catch (Exception e)
            {
                // Something is wrong
                string errStr = BioFailed(errorCode) ? " Some error occurred. And the last error code is " + errorCode.ToString()
                                                           : e.Message;
                return(false);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Set a digital output
        /// </summary>
        /// <param name="boolOutput"></param>
        /// <param name="value"></param>
        public override void Set(BoolOutput boolOutput, bool value)
        {
            ErrorCode errorCode = ErrorCode.Success;

            errorCode        = instantDoCtrl.WriteBit(0, boolOutput.Channel, (byte)(value ? 0xff : 0x00));
            boolOutput.Value = value;
        }
Ejemplo n.º 3
0
        public bool SetDoModeBit(int bit, byte data)
        {
            ErrorCode err = instantDoCtrlUsb4704.WriteBit(0, bit, data);

            if (err != ErrorCode.Success)
            {
                ActiveEventError("初始化数字输出失败:" + err.ToString());
                return(false);
            }
            return(true);
        }
Ejemplo n.º 4
0
 public override void Write(Int32 PORTx, Int32 Pin, Boolean isHigh)
 {
     lock (syscWriteObject)
     {
         if (!isDoInitialized)
         {
             return;
         }
         m_do.WriteBit(PORTx, Pin, Convert.ToByte(isHigh));
         byte data = 0;
         m_do.Read(0, out data);
     }
 }
Ejemplo n.º 5
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}");
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Makes the DAC Write Bit high or low
        /// </summary>
        /// <param name="makeHigh">True to make it high, True if data wants to be written </param>
        /// <returns></returns>
        public bool WriteToDataWriteBit(bool makeBitHigh)
        {
            int       val = (makeBitHigh) ? 1 : 0;
            ErrorCode err = outputDIOControl.WriteBit(this.DIOConfig.OutputConfig.DataWriteBit.Port, this.DIOConfig.OutputConfig.DataWriteBit.OutputPin1, Convert.ToByte(val));

            if (err == ErrorCode.Success)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 7
0
        public static ErrorCode DoWriteBit(int port, int bit, byte data)

        {
            return(instantDoCtrl.WriteBit(port, bit, data));
        }