Exemplo n.º 1
0
        //**************************************************************************
        //EPX64の初期化
        //引数:なし
        //戻値:なし
        //**************************************************************************
        public bool InitEpx64R(byte DirectionData)
        {
            try
            {
                // Device Number
                this.Status = EPX64R.EPX64R_GetNumberOfDevices(ref this.Number);
                if (this.Status != EPX64R.EPX64R_OK)
                {
                    return(false);
                }
                if (this.Number == 0)
                {
                    return(false);
                }

                // Device Open
                this.Status = EPX64R.EPX64R_Open(ref this.hDevice);
                if (this.Status != EPX64R.EPX64R_OK)
                {
                    return(false);
                }

                // Direction 0=入力 1=出力
                this.Direction = DirectionData;//0x37; // P7:0 P6:0 P5:1 P4:1 P3:0 P2:1 P1:1 P0:1
                this.Status    = EPX64R.EPX64R_SetDirection(this.hDevice, this.Direction);
                if (this.Status != EPX64R.EPX64R_OK)
                {
                    EPX64R.EPX64R_Close(this.hDevice);   // Device Close
                    return(false);
                }
                return(true);
            }
            catch
            {
                EPX64R.EPX64R_Close(this.hDevice);   // Device Close
                return(false);
            }
        }
Exemplo n.º 2
0
        //****************************************************************************
        //メソッド名:OutBit(指定ポートにビット単位での出力)
        //引数:引数�@ ポート名("P00"、"P01"・・・"P07")引数�A出力値(H:0/ L: 1)
        //戻り値:正常0、異常1
        //****************************************************************************
        public int OutBit(PORT pName, BIT bName, OUT data)
        {
            //ポートの特定
            byte PortOutData = 0;

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

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

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

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

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

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

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

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

            default:
                return(1);
            }

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

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

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

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

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

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

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

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

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


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

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

            case OUT.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 PORT.P0:
                this.p0Outdata = OutputValue;
                break;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            case PORT.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);
        }
Exemplo n.º 4
0
        //****************************************************************************
        //メソッド名:ReadInputData(指定ポートのデータを取り込む)
        //引数:ポート名("P0"、"P1"・・・"P7")
        //戻り値:取り込んだデータ正常0、異常1
        //****************************************************************************
        public bool ReadInputData(PORT pName)
        {
            try
            {
                switch (pName)
                {
                case PORT.P0:
                    this.Port = EPX64R.EPX64R_PORT0;     // PORT0
                    break;

                case PORT.P1:
                    this.Port = EPX64R.EPX64R_PORT1;     // PORT1
                    break;

                case PORT.P2:
                    this.Port = EPX64R.EPX64R_PORT2;     // PORT2
                    break;

                case PORT.P3:
                    this.Port = EPX64R.EPX64R_PORT3;     // PORT3
                    break;

                case PORT.P4:
                    this.Port = EPX64R.EPX64R_PORT4;     // PORT4
                    break;

                case PORT.P5:
                    this.Port = EPX64R.EPX64R_PORT5;     // PORT5
                    break;

                case PORT.P6:
                    this.Port = EPX64R.EPX64R_PORT6;     // PORT6
                    break;

                case PORT.P7:
                    this.Port = EPX64R.EPX64R_PORT7;     // PORT7
                    break;

                default:
                    break;
                }

                // Input
                this.Status = EPX64R.EPX64R_InputPort(this.hDevice, this.Port, ref this.InputValue);
                if (Status != EPX64R.EPX64R_OK)
                {
                    //MessageBox.Show("EPX64R_InputPort() Error");
                    EPX64R.EPX64R_Close(hDevice);   // Device Close
                    return(false);
                }

                switch (pName)
                {
                case PORT.P0:
                    this.P0InputData = this.InputValue;
                    break;

                case PORT.P1:
                    this.P1InputData = this.InputValue;
                    break;

                case PORT.P2:
                    this.P2InputData = this.InputValue;
                    break;

                case PORT.P3:
                    this.P3InputData = this.InputValue;
                    break;

                case PORT.P4:
                    this.P4InputData = this.InputValue;
                    break;

                case PORT.P5:
                    this.P5InputData = this.InputValue;
                    break;

                case PORT.P6:
                    this.P6InputData = this.InputValue;
                    break;

                case PORT.P7:
                    this.P7InputData = this.InputValue;
                    break;
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }