Subversion Repositories Programming Utils

Compare Revisions

Ignore whitespace Rev 68 → Rev 69

/trunk/JavaSerial/NativeCode/SerialPortImpl.c
24,6 → 24,8
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>
#include <unistd.h>
#include <dirent.h>
 
#ifdef CRTSCTS
#define HW_FLOW CRTSCTS
1544,11 → 1546,10
char** port_names;
int port_names_size;
int x;
jsize size;
port_names_size = 0;
port_names = malloc( sizeof( char* ) * 255 ); //max 255 serial ports
#ifdef _WIN32
port_names = malloc( sizeof( char* ) * 255 ); //max 255 serial ports
{
//Brute force, baby!
char* port_to_open = malloc( 11 );
1575,18 → 1576,44
struct dirent *entry;
DIR* dir;
int fd;
char* deviceName;
 
dir = opendir( "/dev" );
deviceName = malloc( 100 );
 
dir = opendir( "/dev/" );
if( dir == NULL ){
throw_io_exception_message( env, "We can't open /dev." );
free( port_names );
free( deviceName );
return NULL;
}
while ( entry = readdir( dir ), entry != NULL) {
fd = open( entry->d_name, O_RDONLY );
if( snprintf( deviceName, 100, "/dev/%s", entry->d_name ) >= 99 ){
fprintf( stderr, "WARNING: Ignoring file %s, filename too long\n", entry->d_name );
continue;
}
fd = open( deviceName, O_RDONLY );
if( fd < 0 ){
fprintf( stderr, "ERROR: This is a very bad thing that should never happen %s:%s\n", __FILE__, __LINE__ );
switch( errno ){
case EACCES:
case ENOMEDIUM:
//For some reason, I get errno 22 on my laptop
//when opening /dev/video0, which prints out
//"No such device or address"
//Not adding it here, because that does seem bad
break;
default:
perror( "open" );
fprintf( stderr, "ERROR: This is a very bad thing that should never happen %s:%d errno:%d\n", __FILE__, __LINE__, errno );
}
close( fd );
continue;
}
if( isatty( fd ) ){
port_names[ port_names_size ] = malloc( strlen( entry->d_name ) + 1 );
memcpy( port_names[ port_names_size ], entry->d_name, strlen( entry->d_name ) + 1 );
port_names[ port_names_size ] = malloc( strlen( entry->d_name ) + 6 );
memcpy( port_names[ port_names_size ], "/dev/", 5 );
memcpy( port_names[ port_names_size ] + 5, entry->d_name, strlen( entry->d_name ) + 1 );
port_names_size++;
}
1593,6 → 1620,7
close( fd );
}
closedir( dir );
free( deviceName );
}
#endif /* _WIN32 */
 
1608,4 → 1636,3
return array;
}
 
/trunk/JavaSerial/NativeCode/Makefile
41,8 → 41,8
########## Default flags (redefine these with a header.mak file if desired)
CPPFLAGS = -DPIC -I$(JNI_INCLUDE_DIR) -I$(JNI_INCLUDE_DIR)/linux
CXXFLAGS =
CFLAGS = -FPIC -Wall
CLIBFLAGS = -lm
CFLAGS = -fPIC -Wall $(ARCH)
CLIBFLAGS = -lm
CCLIBFLAGS =
########## End of default flags
 
63,8 → 63,13
# Main targets
#
linux: SerialPortImpl.o
gcc -o libjavaserial.so -shared -Wl,-soname,libjavaserial.so -I$(JNI_INCLUDE_DIR) -I$(JNI_INCLUDE_DIR)/linux -static -lc $(OBJFILES)
gcc -o libjavaserial.so $(ARCH) -shared -Wl,-soname,libjavaserial.so -I$(JNI_INCLUDE_DIR) -I$(JNI_INCLUDE_DIR)/linux -lc $(OBJFILES)
 
linux-32:
$(MAKE) ARCH="-m32"
linux-64:
$(MAKE) ARCH="-m64"
 
windows:
cl -I"$(JNI_INCLUDE_DIR_WIN)" -I"$(JNI_INCLUDE_DIR_WIN)\win32" -I"." -MT -LD SerialPortImpl.c -Fejavaserial.dll
#
/trunk/JavaSerial/src/com/rm5248/serial/SerialPort.java
929,6 → 929,7
public static native int getMinorNativeVersion();
/**
* <p>
* Get an array of all the serial ports on the system. For example, on
* Windows this will return {@code { "COM1", "COM3", .... } } depending on how
* many serial devices you have plugged in. On Linux, this returns
935,7 → 936,11
* {@code { "/dev/ttyS0", "/dev/ttyUSB0", "/dev/symlink", ... } }
* It will not resolve symlinks, such that if there is a symlink
* from {@code /dev/symlink } to {@code /dev/ttyUSB0 }, they will both show up.
*
* </p>
* <p>
* <b>NOTE:</b> this will only return ports that you have permissions to
* open.
* </p>
*
* @return
*/