Esempio n. 1
0
        public AsyncSerialStream(string port, uint baudrate) : base(port, System.IO.FileShare.None)
        {
            Native.COMMTIMEOUTS cto = new Native.COMMTIMEOUTS(); cto.Initialize();
            Native.DCB          dcb = new Native.DCB(); dcb.Initialize();

            Native.GetCommState(m_handle.DangerousGetHandle(), ref dcb);

            dcb.BaudRate = baudrate;
            dcb.ByteSize = 8;
            dcb.StopBits = 0;

            dcb.__BitField  = 0;
            dcb.__BitField &= ~Native.DCB.mask_fDtrControl;
            dcb.__BitField &= ~Native.DCB.mask_fRtsControl;
            dcb.__BitField |= Native.DCB.mask_fBinary;
            dcb.__BitField &= ~Native.DCB.mask_fParity;
            dcb.__BitField &= ~Native.DCB.mask_fOutX;
            dcb.__BitField &= ~Native.DCB.mask_fInX;
            dcb.__BitField &= ~Native.DCB.mask_fErrorChar;
            dcb.__BitField &= ~Native.DCB.mask_fNull;
            dcb.__BitField |= Native.DCB.mask_fAbortOnError;

            Native.SetCommState(m_handle.DangerousGetHandle(), ref dcb);

            Native.SetCommTimeouts(m_handle.DangerousGetHandle(), ref cto);
        }
Esempio n. 2
0
        public AsyncSerialStream( string port, uint baudrate ) : base( port, System.IO.FileShare.None )
        {
            Native.COMMTIMEOUTS cto = new Native.COMMTIMEOUTS(); cto.Initialize();
            Native.DCB          dcb = new Native.DCB         (); dcb.Initialize();

            Native.GetCommState( m_handle.DangerousGetHandle(), ref dcb );

            dcb.BaudRate = baudrate;
            dcb.ByteSize = 8;
            dcb.StopBits = 0;

            dcb.__BitField = 0;
            dcb.__BitField &= ~Native.DCB.mask_fDtrControl  ;
            dcb.__BitField &= ~Native.DCB.mask_fRtsControl  ;
            dcb.__BitField |=  Native.DCB.mask_fBinary      ;
            dcb.__BitField &= ~Native.DCB.mask_fParity      ;
            dcb.__BitField &= ~Native.DCB.mask_fOutX        ;
            dcb.__BitField &= ~Native.DCB.mask_fInX         ;
            dcb.__BitField &= ~Native.DCB.mask_fErrorChar   ;
            dcb.__BitField &= ~Native.DCB.mask_fNull        ;
            dcb.__BitField |=  Native.DCB.mask_fAbortOnError;

            Native.SetCommState( m_handle.DangerousGetHandle(), ref dcb );

            Native.SetCommTimeouts( m_handle.DangerousGetHandle(), ref cto );
        }