Ejemplo n.º 1
0
        bool SetLinuxCustomBaudRate(string port, int baud)
        {
            // based on code from https://gist.github.com/lategoodbye/f2d76134aa6c404cd92c

            int fd = Linux.open(port, 0 /*O_RDONLY*/);

            if (fd < 0)
            {
                return(false);
            }

            try
            {
                Linux.Termios2 t2 = new Linux.Termios2();

                int e = Linux.ioctl(fd, 2150388778 /*TCGETS2*/, ref t2);
                if (e < 0)
                {
                    return(false);
                }

                t2.c_cflag &= ~(uint)4111 /*CBAUD*/;
                t2.c_cflag |= 4096 /*BOTHER*/;
                t2.c_ispeed = baud;
                t2.c_ospeed = baud;

                e = Linux.ioctl(fd, 1076646955 /*TCSETS2*/, ref t2);
                if (e < 0)
                {
                    return(false);
                }

                e = Linux.ioctl(fd, 2150388778 /*TCGETS2*/, ref t2);
                if (e < 0)
                {
                    return(false);
                }

                return(true);
            }
            finally
            {
                Linux.close(fd);
            }
        }
Ejemplo n.º 2
0
        private void CloseAfterUsbCableUnplugged()
        {
                #if LINUX
            if (Linux.close(_handle) == -1)
            {
                throw new Exception();
            }
                #elif UNITY_ANDROID
            throw new NotImplementedException();
                #else
            // Assume compiling on WIN32 or UNITY_STANDALONE_WIN.

            if (!Win32.CloseHandle(_handle))
            {
                throw new Exception();
            }
                #endif

            IsOpen = false;
        }