Пример #1
0
 public void shutDown() {
   for (Port port : m_OpenPorts.values()) {
     try {
       log = log && log(1, "shutDown() closing port %d\n", port.m_FD);
       port.close();
     } catch (Exception e) {
       // should never happen
       e.printStackTrace();
     }
   }
 }
Пример #2
0
  public int open(String filename, int flags) {
    Port port = new Port();
    port.m_OpenFlags = flags;
    try {
      if (!filename.startsWith("\\\\")) filename = "\\\\.\\" + filename;

      port.m_Comm =
          CreateFileW(
              new WString(filename),
              GENERIC_READ | GENERIC_WRITE,
              0,
              null,
              OPEN_EXISTING,
              FILE_FLAG_OVERLAPPED,
              null);

      if (INVALID_HANDLE_VALUE == port.m_Comm) {
        if (GetLastError() == ERROR_FILE_NOT_FOUND) m_ErrNo = ENOENT;
        else m_ErrNo = EBUSY;
        port.fail();
      }

      if (!SetupComm(port.m_Comm, (int) port.m_RdBuffer.size(), (int) port.m_WrBuffer.size()))
        port.fail(); // FIXME what would be appropriate error code here

      cfmakeraw(port.m_Termios);
      cfsetispeed(port.m_Termios, B9600);
      cfsetospeed(port.m_Termios, B9600);
      port.m_Termios.c_cc[VTIME] = 0;
      port.m_Termios.c_cc[VMIN] = 0;
      updateFromTermios(port);

      port.m_RdOVL.writeField("hEvent", CreateEventA(null, true, false, null));
      if (port.m_RdOVL.hEvent == INVALID_HANDLE_VALUE) port.fail();

      port.m_WrOVL.writeField("hEvent", CreateEventA(null, true, false, null));
      if (port.m_WrOVL.hEvent == INVALID_HANDLE_VALUE) port.fail();

      port.m_SelOVL.writeField("hEvent", CreateEventA(null, true, false, null));
      if (port.m_SelOVL.hEvent == INVALID_HANDLE_VALUE) port.fail();

      return port.m_FD;
    } catch (Exception f) {
      if (port != null) port.close();
      return -1;
    }
  }
Пример #3
0
 public int close(int fd) {
   Port port = getPort(fd);
   if (port == null) return -1;
   port.close();
   return 0;
 }