private serial_getports ( RJCP.IO.Ports.Native.Unix.SafeSerialHandle handle ) : IntPtr | ||
handle | RJCP.IO.Ports.Native.Unix.SafeSerialHandle | |
Результат | IntPtr |
public PortDescription[] serial_getports(SafeSerialHandle handle) { // The portdesc is an array of two string pointers, where the last element is zero IntPtr portdesc; #if !NETSTANDARD2_0 portdesc = UnsafeNativeMethods.serial_getports(handle); #else try { portdesc = UnsafeNativeMethods.serial_getports(handle); } catch (Exception ex) { // Ugly hack as .NET Standard doesn't have EntryPointNotFoundException, so if we // get any exception, we raise this one instead. To remove if it ever becomes // available. throw new EntryPointNotFoundException(ex.Message, ex); } #endif errno = Marshal.GetLastWin32Error(); if (portdesc.Equals(IntPtr.Zero)) { return(null); } // Get the number of ports in the system. int portNum = 0; IntPtr portName; do { portName = Marshal.ReadIntPtr(portdesc, portNum * 2 * IntPtr.Size); if (portName != IntPtr.Zero) { portNum++; } } while (portName != IntPtr.Zero); // Copy them into our struct PortDescription[] ports = new PortDescription[portNum]; for (int i = 0; i < portNum; i++) { IntPtr portPtr = Marshal.ReadIntPtr(portdesc, i * 2 * IntPtr.Size); string port = Marshal.PtrToStringAnsi(portPtr); IntPtr descPtr = Marshal.ReadIntPtr(portdesc, i * 2 * IntPtr.Size + IntPtr.Size); string desc; if (descPtr.Equals(IntPtr.Zero)) { desc = string.Empty; } else { desc = Marshal.PtrToStringAnsi(descPtr); } ports[i] = new PortDescription(port, desc); } return(ports); }
public PortDescription[] serial_getports(IntPtr handle) { // The portdesc is an array of two string pointers, where the last element is zero IntPtr portdesc = UnsafeNativeMethods.serial_getports(handle); errno = Marshal.GetLastWin32Error(); if (portdesc.Equals(IntPtr.Zero)) { return(null); } // Get the number of ports in the system. int portNum = 0; IntPtr portName; do { portName = Marshal.ReadIntPtr(portdesc, portNum * 2 * IntPtr.Size); if (portName != IntPtr.Zero) { portNum++; } } while (portName != IntPtr.Zero); // Copy them into our struct PortDescription[] ports = new PortDescription[portNum]; for (int i = 0; i < portNum; i++) { IntPtr portPtr = Marshal.ReadIntPtr(portdesc, i * 2 * IntPtr.Size); string port = Marshal.PtrToStringAnsi(portPtr); IntPtr descPtr = Marshal.ReadIntPtr(portdesc, i * 2 * IntPtr.Size + IntPtr.Size); string desc; if (descPtr.Equals(IntPtr.Zero)) { desc = string.Empty; } else { desc = Marshal.PtrToStringAnsi(descPtr); } ports[i] = new PortDescription(port, desc); } return(ports); }