Example #1
0
        public bool GetDoModeBit(int bit, out byte bitData)
        {
            ErrorCode err = instantDoCtrlUsb4704.ReadBit(0, bit, out bitData);

            if (err != ErrorCode.Success)
            {
                ActiveEventError("获取数字输出失败:" + err.ToString());
                return(false);
            }
            return(true);
        }
        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);
            }
        }