Esempio n. 1
0
    // This subroutine opens and initializes the Comm Port (overloaded
    //   to support parameters).

    public void Open(int Port, int BaudRate, int DataBit,
                     DataParity Parity, DataStopBit StopBit, int BufferSize)
    {
        this.Port       = Port;
        this.BaudRate   = BaudRate;
        this.DataBit    = DataBit;
        this.Parity     = Parity;
        this.StopBit    = StopBit;
        this.BufferSize = BufferSize;
        Open();
    }
Esempio n. 2
0
        public void Open(string Port, int BaudRate, int DataBit, DataParity Parity, DataStopBit StopBit, int BufferSize)
        {
            myserial.PortName      = Port;
            myserial.BaudRate      = BaudRate;
            myserial.DataBits      = DataBit;
            myserial.ParityReplace = 0;
            switch (Parity)
            {
            case DataParity.Pariti_Odd:
                myserial.Parity = RJCP.IO.Ports.Parity.Odd;
                break;

            case DataParity.Parity_Even:
                myserial.Parity = RJCP.IO.Ports.Parity.Even;
                break;

            case DataParity.Parity_Mark:
                myserial.Parity = RJCP.IO.Ports.Parity.Mark;
                break;

            case DataParity.Parity_None:
                myserial.Parity = RJCP.IO.Ports.Parity.None;
                break;

            default:
                myserial.Parity = RJCP.IO.Ports.Parity.None;
                break;
            }
            switch (StopBit)
            {
            case DataStopBit.StopBit_1:
                myserial.StopBits = StopBits.One;
                break;

            case DataStopBit.StopBit_2:
                myserial.StopBits = StopBits.Two;
                break;

            default:
                myserial.StopBits = StopBits.One;
                break;
            }
            myserial.ReadTimeout     = 75;
            myserial.WriteTimeout    = 75;
            myserial.ReadBufferSize  = BufferSize;
            myserial.WriteBufferSize = BufferSize;
            readbuffer = new byte[checked (BufferSize + 1)];
            myserial.Open();
            myserial.DiscardInBuffer();
            myserial.DiscardOutBuffer();
            //Thread.Sleep(100);
        }