Example #1
0
        public unsafe bool Init(uint BaudRate, byte ByteSize, byte Parity, byte StopBits)
        {
            if (handle.ToInt32() == -1)
            {
                return(false);
            }

            // Init the com state
            DCB dcb = new DCB();

            if (!GetCommState(handle, ref dcb))
            {
                return(false);
            }

            dcb.BaudRate = BaudRate;
            dcb.ByteSize = ByteSize;
            dcb.Parity   = Parity;
            dcb.StopBits = StopBits;

            if (!SetCommState(handle, ref dcb))
            {
                return(false);
            }

            // Init the com timeouts
            COMMTIMEOUTS Commtimeouts = new COMMTIMEOUTS();

            if (!GetCommTimeouts(handle, ref Commtimeouts))
            {
                return(false);
            }

            Commtimeouts.ReadIntervalTimeout = 600;
            if (!SetCommTimeouts(handle, ref Commtimeouts))
            {
                return(false);
            }

            return(true);
        }
Example #2
0
 static extern unsafe bool GetCommTimeouts(
     IntPtr hFile,
     ref COMMTIMEOUTS lpCommTimeouts);