コード例 #1
0
ファイル: I7565DNM.cs プロジェクト: bookorz/SanwaMarco
        //泓格 I7565DNM 讀取模組IO
        public uint I7565DNM_GETIO(string ioNo, bool isForceRefresh)
        {
            clearError();
            int boardNo;
            int io;

            try
            {
                if (ioNo.Length == 3)
                {
                    boardNo = int.Parse(ioNo.Substring(0, 1));
                    io      = int.Parse(ioNo.Substring(1));
                }
                else
                {
                    boardNo = int.Parse(ioNo.Substring(0, 2));
                    io      = int.Parse(ioNo.Substring(2));
                }
                io = io + 1;//IO定義表從0開始
                if (deviceNetCtrlMap.Count < boardNo)
                {
                    //logger.Error("boardNo:" + boardNo + "< deviceNetCtrlMap.Count:" + deviceNetCtrlMap.Count);
                    setError("20001");
                    return(20001);//unkonw
                }
                DeviceNetCtrl dnm = deviceNetCtrlMap[boardNo.ToString()];
                //Byte[] IODATA = new Byte[512];
                byte cPort = Byte.Parse(portNo);//covert port id to byte
                if (isForceRefresh)
                {
                    UInt32 Ret = dnm.Refresh(cPort);
                    if (Ret != 0)
                    {
                        errorCode = Ret.ToString();
                        return(Ret);
                    }
                }
                uint temp = io > 8 ? dnm.IODATA[1] : dnm.IODATA[0];
                int  bit  = io > 8 ? io - 8 - 1 : io - 1;
                return((temp >> bit) & 1);//向右移動N-1位後, 與 00000001 做 AND 運算
            }
            catch (Exception e)
            {
                logger.Error(e.StackTrace);
                setError("DNM90001");
                return(90001);
            }
        }