Function CreateSerPort(PortName as String) as Integer ' Return 'handle' to port. ' Where PortName is like "Com1", "Com2", ... Declare Function CreateFile LIB "kernel32" Alias "CreateFileA" _ (FName as CString, DesAccs as Integer, Share as Integer, _ SecAttr as INTEGER, CreateDisp as Integer, Flags as Integer, _ Template as Integer) as Integer Dim LocHandle as Integer Dim GEN_READ as INTEGER = &h80000000 DIM GEN_WRITE as INTEGER = &h40000000 DIM EXISTING as INTEGER = 3 DIM OVERLAPPED AS INTEGER = &h40000000 DIM INVALID_HANDLE as INTEGER = -1 DIM RetVal as INTEGER LocHandle = CreateFile(PortName, GEN_READ + GEN_WRITE, _ 0, 0, EXISTING, OVERLAPPED, 0) 'Note it auto-converts 'String' to CString on the fly IF LocHandle = INVALID_HANDLE THEN ' Is bad port, abort. RETURN INVALID_HANDLE END IF Return LocHandle END FUNCTION Sub ClearDTR(PortHandle as INTEGER) ChangePort(PortHandle, 6) END SUB Sub ChangePort(PortHandle as INTEGER, Cmd as INTEGER) Declare Function EscapeCommFunction LIB "kernel32" _ ( SerHandle as INTEGER, SerFunc as Integer) as INTEGER ' Function command values... ' SETXOFF==1, SETXON==2, SETRTS==3, CLRRTS==4, SETDTR==5, CLRDTR==6 ' RESETDEV==7, SETBREAK==8, CLRBREAK==9 ' ' Set RTS HIGH, wait, then Set it LOW Dim RetVal as INTEGER RetVal = EscapeCommFunction(PortHandle, Cmd) END SUB