Ejemplo n.º 1
0
        //****************************************************************************
        //メソッド名:OutBit(指定ポートにビット単位での出力)
        //引数:引数�@ ポート名("P00"、"P01"・・・"P07")引数�A出力値(H:0/ L: 1)
        //戻り値:正常0、異常1
        //****************************************************************************
        public int OutBit(PortName pName, BitName bName, OutData data)
        {
            //ポートの特定
            byte PortOutData = 0;

            switch (pName)
            {
            case PortName.P0:
                this.Port   = EPX64R_PORT0;
                PortOutData = this.p0Outdata;
                break;

            case PortName.P1:
                this.Port   = EPX64R_PORT1;
                PortOutData = this.p1Outdata;
                break;

            case PortName.P2:
                this.Port   = EPX64R_PORT2;
                PortOutData = this.p2Outdata;
                break;

            case PortName.P3:
                this.Port   = EPX64R_PORT3;
                PortOutData = this.p3Outdata;
                break;

            case PortName.P4:
                this.Port   = EPX64R_PORT4;
                PortOutData = this.p4Outdata;
                break;

            case PortName.P5:
                this.Port   = EPX64R_PORT5;
                PortOutData = this.p5Outdata;
                break;

            case PortName.P6:
                this.Port   = EPX64R_PORT6;
                PortOutData = this.p6Outdata;
                break;

            case PortName.P7:
                this.Port   = EPX64R_PORT7;
                PortOutData = this.p7Outdata;
                break;

            default:
                return(1);
            }

            //ビットの特定
            byte Temp = 0;
            int  Num  = 0;

            switch (bName)
            {
            case BitName.b0:
                Num = 0; Temp = 0xFE;
                break;

            case BitName.b1:
                Num = 1; Temp = 0xFD;
                break;

            case BitName.b2:
                Num = 2; Temp = 0xFB;
                break;

            case BitName.b3:
                Num = 3; Temp = 0xF7;
                break;

            case BitName.b4:
                Num = 4; Temp = 0xEF;
                break;

            case BitName.b5:
                Num = 5; Temp = 0xDF;
                break;

            case BitName.b6:
                Num = 6; Temp = 0xBF;
                break;

            case BitName.b7:
                Num = 7; Temp = 0x7F;
                break;
            }


            //データの出力
            byte Data = 0;

            switch (data)
            {
            case OutData.H:
                Data = 1;
                break;

            case OutData.L:
                Data = 0;
                break;
            }


            byte OutputValue = (byte)((PortOutData & Temp) | (Data << Num));//byteでキャストしないと怒られる
            int  flag        = EPX64R.EPX64R_OutputPort(this.hDevice, Port, OutputValue);

            if (flag != EPX64R.EPX64R_OK)
            {
                EPX64R.EPX64R_Close(this.hDevice);   // Device Close
                //MessageBox.Show("EPX64R_OutputPort() Error");
                return(1);
            }

            switch (pName)
            {
            case PortName.P0:
                this.p0Outdata = OutputValue;
                break;

            case PortName.P1:
                this.p1Outdata = OutputValue;
                break;

            case PortName.P2:
                this.p2Outdata = OutputValue;
                break;

            case PortName.P3:
                this.p3Outdata = OutputValue;
                break;

            case PortName.P4:
                this.p4Outdata = OutputValue;
                break;

            case PortName.P5:
                this.p5Outdata = OutputValue;
                break;

            case PortName.P6:
                this.p6Outdata = OutputValue;
                break;

            case PortName.P7:
                this.p7Outdata = OutputValue;
                break;
            }
            return(0);
        }
Ejemplo n.º 2
0
        //****************************************************************************
        //メソッド名:OutByte(指定ポートにバイト単位での出力)
        //引数:引数�@ ポート名("P0"、"P1"・・・"P7")引数�A出力値(0x00〜0xFF)
        //戻り値:正常0、異常1
        //****************************************************************************
        public int OutByte(PortName pName, byte Data)
        {
            int flag = 0;

            //ポートの特定と出力データバッファの更新
            switch (pName)
            {
            case PortName.P0:
                this.Port      = EPX64R_PORT0;
                this.p0Outdata = Data;
                break;

            case PortName.P1:
                this.Port      = EPX64R_PORT1;
                this.p1Outdata = Data;
                break;

            case PortName.P2:
                this.Port      = EPX64R_PORT2;
                this.p2Outdata = Data;
                break;

            case PortName.P3:
                this.Port      = EPX64R_PORT3;
                this.p3Outdata = Data;
                break;

            case PortName.P4:
                this.Port      = EPX64R_PORT4;
                this.p4Outdata = Data;
                break;

            case PortName.P5:
                this.Port      = EPX64R_PORT5;
                this.p5Outdata = Data;
                break;

            case PortName.P6:
                this.Port      = EPX64R_PORT6;
                this.p6Outdata = Data;
                break;

            case PortName.P7:
                this.Port      = EPX64R_PORT7;
                this.p7Outdata = Data;
                break;

            default:
                return(1);   //ポート名間違えたら異常とする
            }

            //データの出力
            flag = EPX64R.EPX64R_OutputPort(this.hDevice, this.Port, Data);
            if (flag != EPX64R.EPX64R_OK)
            {
                EPX64R.EPX64R_Close(this.hDevice);   // Device Close
                //MessageBox.Show("EPX64R_OutputPort() Error");
                return(1);
            }

            return(0);
        }