Subversion Repositories Programming Utils

Compare Revisions

Ignore whitespace Rev 53 → Rev 54

/trunk/JavaSerial/NativeCode/SerialPortImpl.c
40,6 → 40,20
#endif
 
/**
* TODO actually make this an inline function
*/
#define GET_PORT_DESCRIPTOR( array_pos, desc, env, obj ) array_pos = get_handle( env, obj ); \
if( array_pos < 0 || array_pos > port_list_size ){ \
throw_io_exception_message( env, "Unable to get handle" );\
return 0; \
} \
desc = port_list[ array_pos ]; \
if( desc == NULL ){ \
throw_io_exception_message( env, "Unable to get descriptor" ); \
return 0; \
}
 
#include <stdlib.h>
#include <errno.h>
#include <string.h>
415,7 → 429,7
}
}
{
{
//Let's check to see if this is a serial port
DCB io_name = {0};
io_name.DCBlength = sizeof( io_name );
691,32 → 705,8
jint array_pos;
struct port_descriptor* desc;
 
array_pos = get_handle( env, obj );
GET_PORT_DESCRIPTOR( array_pos, desc, env, obj );
 
if( array_pos < 0 ){
//throw new exception
int errNum;
#ifdef _WIN32
errNum = GetLastError();
#else
errNum = errno;
#endif /* _WIN32 */
throw_io_exception( env, errNum );
return 0;
}
 
desc = port_list[ array_pos ];
 
if( desc == NULL ){
//throw new exception
jclass exception_class;
(*env)->ExceptionDescribe( env );
(*env)->ExceptionClear( env );
exception_class = (*env)->FindClass(env, "java/io/IOException");
(*env)->ThrowNew(env, exception_class, "Given bad positon in array. Internal SerialPort error." );
return 0;
}
 
return set_baud_rate( desc, baud_rate );
}
 
730,30 → 720,8
jint array_pos;
struct port_descriptor* desc;
 
array_pos = get_handle( env, obj );
GET_PORT_DESCRIPTOR( array_pos, desc, env, obj );
 
if( array_pos < 0 ){
//throw new exception
jclass exception_class;
(*env)->ExceptionDescribe( env );
(*env)->ExceptionClear( env );
exception_class = (*env)->FindClass(env, "java/io/IOException");
(*env)->ThrowNew(env, exception_class, strerror( errno ) );
return 0;
}
 
desc = port_list[ array_pos ];
 
if( desc == NULL ){
//throw new exception
jclass exception_class;
(*env)->ExceptionDescribe( env );
(*env)->ExceptionClear( env );
exception_class = (*env)->FindClass(env, "java/io/IOException");
(*env)->ThrowNew(env, exception_class, strerror( errno ) );
return 0;
}
 
//Now, let's get the baud rate information
{
GET_SERIAL_PORT_STRUCT( desc->port, newio );
802,9 → 770,17
struct port_descriptor* desc;
 
array_pos = get_handle( env, obj );
if( array_pos < 0 ){
//throw new exception
throw_io_exception_message( env, "Unable to get handle" );
return 0;
}
 
desc = port_list[ array_pos ];
 
if( desc == NULL ){
//throw new exception
throw_io_exception_message( env, "Unable to get descriptor" );
return 0;
}
822,14 → 798,9
struct port_descriptor* desc;
 
array_pos = get_handle( env, obj );
 
if( array_pos < 0 ){
//throw new exception
jclass exception_class;
(*env)->ExceptionDescribe( env );
(*env)->ExceptionClear( env );
exception_class = (*env)->FindClass(env, "java/io/IOException");
(*env)->ThrowNew(env, exception_class, strerror( errno ) );
throw_io_exception_message( env, "Unable to get handle" );
return 0;
}
 
837,11 → 808,7
 
if( desc == NULL ){
//throw new exception
jclass exception_class;
(*env)->ExceptionDescribe( env );
(*env)->ExceptionClear( env );
exception_class = (*env)->FindClass(env, "java/io/IOException");
(*env)->ThrowNew(env, exception_class, strerror( errno ) );
throw_io_exception_message( env, "Unable to get descriptor" );
return 0;
}
 
875,9 → 842,17
struct port_descriptor* desc;
 
array_pos = get_handle( env, obj );
if( array_pos < 0 ){
//throw new exception
throw_io_exception_message( env, "Unable to get handle" );
return 0;
}
 
desc = port_list[ array_pos ];
 
if( desc == NULL ){
//throw new exception
throw_io_exception_message( env, "Unable to get descriptor" );
return 0;
}
895,14 → 870,9
struct port_descriptor* desc;
 
array_pos = get_handle( env, obj );
 
if( array_pos < 0 ){
//throw new exception
jclass exception_class;
(*env)->ExceptionDescribe( env );
(*env)->ExceptionClear( env );
exception_class = (*env)->FindClass(env, "java/io/IOException");
(*env)->ThrowNew(env, exception_class, strerror( errno ) );
throw_io_exception_message( env, "Unable to get handle" );
return 0;
}
 
910,11 → 880,7
 
if( desc == NULL ){
//throw new exception
jclass exception_class;
(*env)->ExceptionDescribe( env );
(*env)->ExceptionClear( env );
exception_class = (*env)->FindClass(env, "java/io/IOException");
(*env)->ThrowNew(env, exception_class, strerror( errno ) );
throw_io_exception_message( env, "Unable to get descriptor" );
return 0;
}
 
951,15 → 917,10
jint array_pos;
struct port_descriptor* desc;
 
array_pos = get_handle( env, obj );
array_pos = get_handle( env, obj );
if( array_pos < 0 ){
//throw new exception
jclass exception_class;
(*env)->ExceptionDescribe( env );
(*env)->ExceptionClear( env );
exception_class = (*env)->FindClass(env, "java/io/IOException");
(*env)->ThrowNew(env, exception_class, strerror( errno ) );
throw_io_exception_message( env, "Unable to get handle" );
return 0;
}
 
967,11 → 928,7
 
if( desc == NULL ){
//throw new exception
jclass exception_class;
(*env)->ExceptionDescribe( env );
(*env)->ExceptionClear( env );
exception_class = (*env)->FindClass(env, "java/io/IOException");
(*env)->ThrowNew(env, exception_class, strerror( errno ) );
throw_io_exception_message( env, "Unable to get descriptor" );
return 0;
}
989,14 → 946,9
struct port_descriptor* desc;
 
array_pos = get_handle( env, obj );
 
if( array_pos < 0 ){
//throw new exception
jclass exception_class;
(*env)->ExceptionDescribe( env );
(*env)->ExceptionClear( env );
exception_class = (*env)->FindClass(env, "java/io/IOException");
(*env)->ThrowNew(env, exception_class, strerror( errno ) );
throw_io_exception_message( env, "Unable to get handle" );
return 0;
}
 
1004,11 → 956,7
 
if( desc == NULL ){
//throw new exception
jclass exception_class;
(*env)->ExceptionDescribe( env );
(*env)->ExceptionClear( env );
exception_class = (*env)->FindClass(env, "java/io/IOException");
(*env)->ThrowNew(env, exception_class, strerror( errno ) );
throw_io_exception_message( env, "Unable to get descriptor" );
return 0;
}
 
1053,14 → 1001,9
struct port_descriptor* desc;
array_pos = get_handle( env, obj );
if( array_pos < 0 ){
//throw new exception
jclass exception_class;
(*env)->ExceptionDescribe( env );
(*env)->ExceptionClear( env );
exception_class = (*env)->FindClass(env, "java/io/IOException");
(*env)->ThrowNew(env, exception_class, strerror( errno ) );
throw_io_exception_message( env, "Unable to get handle" );
return 0;
}
 
1068,11 → 1011,7
 
if( desc == NULL ){
//throw new exception
jclass exception_class;
(*env)->ExceptionDescribe( env );
(*env)->ExceptionClear( env );
exception_class = (*env)->FindClass(env, "java/io/IOException");
(*env)->ThrowNew(env, exception_class, strerror( errno ) );
throw_io_exception_message( env, "Unable to get descriptor" );
return 0;
}
1090,14 → 1029,9
struct port_descriptor* desc;
 
array_pos = get_handle( env, obj );
if( array_pos < 0 ){
//throw new exception
jclass exception_class;
(*env)->ExceptionDescribe( env );
(*env)->ExceptionClear( env );
exception_class = (*env)->FindClass(env, "java/io/IOException");
(*env)->ThrowNew(env, exception_class, strerror( errno ) );
throw_io_exception_message( env, "Unable to get handle" );
return 0;
}
 
1105,11 → 1039,7
 
if( desc == NULL ){
//throw new exception
jclass exception_class;
(*env)->ExceptionDescribe( env );
(*env)->ExceptionClear( env );
exception_class = (*env)->FindClass(env, "java/io/IOException");
(*env)->ThrowNew(env, exception_class, strerror( errno ) );
throw_io_exception_message( env, "Unable to get descriptor" );
return 0;
}
1153,14 → 1083,9
jint ret_val;
 
array_pos = get_handle( env, obj );
if( array_pos < 0 ){
//throw new exception
jclass exception_class;
(*env)->ExceptionDescribe( env );
(*env)->ExceptionClear( env );
exception_class = (*env)->FindClass(env, "java/io/IOException");
(*env)->ThrowNew(env, exception_class, strerror( errno ) );
throw_io_exception_message( env, "Unable to get handle" );
return 0;
}
 
1168,11 → 1093,7
 
if( desc == NULL ){
//throw new exception
jclass exception_class;
(*env)->ExceptionDescribe( env );
(*env)->ExceptionClear( env );
exception_class = (*env)->FindClass(env, "java/io/IOException");
(*env)->ThrowNew(env, exception_class, strerror( errno ) );
throw_io_exception_message( env, "Unable to get descriptor" );
return 0;
}
 
1254,14 → 1175,9
jint ret_val;
 
array_pos = get_handle( env, obj );
if( array_pos < 0 ){
//throw new exception
jclass exception_class;
(*env)->ExceptionDescribe( env );
(*env)->ExceptionClear( env );
exception_class = (*env)->FindClass(env, "java/io/IOException");
(*env)->ThrowNew(env, exception_class, strerror( errno ) );
throw_io_exception_message( env, "Unable to get handle" );
return 0;
}
 
1269,11 → 1185,7
 
if( desc == NULL ){
//throw new exception
jclass exception_class;
(*env)->ExceptionDescribe( env );
(*env)->ExceptionClear( env );
exception_class = (*env)->FindClass(env, "java/io/IOException");
(*env)->ThrowNew(env, exception_class, strerror( errno ) );
throw_io_exception_message( env, "Unable to get descriptor" );
return 0;
}
 
1427,11 → 1339,7
array_pos = get_handle( env, obj );
if( array_pos < 0 ){
//throw new exception
jclass exception_class;
(*env)->ExceptionDescribe( env );
(*env)->ExceptionClear( env );
exception_class = (*env)->FindClass(env, "java/io/IOException");
(*env)->ThrowNew(env, exception_class, strerror( errno ) );
throw_io_exception_message( env, "Unable to get handle" );
return -1;
}
 
1439,11 → 1347,7
 
if( desc == NULL ){
//throw new exception
jclass exception_class;
(*env)->ExceptionDescribe( env );
(*env)->ExceptionClear( env );
exception_class = (*env)->FindClass(env, "java/io/IOException");
(*env)->ThrowNew(env, exception_class, strerror( errno ) );
throw_io_exception_message( env, "Unable to get descriptor" );
return -1;
}
1588,11 → 1492,7
array_pos = get_handle( env, obj );
if( array_pos < 0 ){
//throw new exception
jclass exception_class;
(*env)->ExceptionDescribe( env );
(*env)->ExceptionClear( env );
exception_class = (*env)->FindClass(env, "java/io/IOException");
(*env)->ThrowNew(env, exception_class, strerror( errno ) );
throw_io_exception_message( env, "Unable to get handle" );
return -1;
}
 
1600,11 → 1500,7
 
if( desc == NULL ){
//throw new exception
jclass exception_class;
(*env)->ExceptionDescribe( env );
(*env)->ExceptionClear( env );
exception_class = (*env)->FindClass(env, "java/io/IOException");
(*env)->ThrowNew(env, exception_class, strerror( errno ) );
throw_io_exception_message( env, "Unable to get descriptor" );
return -1;
}
 
1652,11 → 1548,7
array_pos = get_handle( env, obj );
if( array_pos < 0 ){
//throw new exception
jclass exception_class;
(*env)->ExceptionDescribe( env );
(*env)->ExceptionClear( env );
exception_class = (*env)->FindClass(env, "java/io/IOException");
(*env)->ThrowNew(env, exception_class, strerror( errno ) );
throw_io_exception_message( env, "Unable to get handle" );
return;
}
 
1664,11 → 1556,7
 
if( desc == NULL ){
//throw new exception
jclass exception_class;
(*env)->ExceptionDescribe( env );
(*env)->ExceptionClear( env );
exception_class = (*env)->FindClass(env, "java/io/IOException");
(*env)->ThrowNew(env, exception_class, strerror( errno ) );
throw_io_exception_message( env, "Unable to get descriptor" );
return;
}
 
1718,11 → 1606,7
array_pos = get_handle( env, obj );
if( array_pos < 0 ){
//throw new exception
jclass exception_class;
(*env)->ExceptionDescribe( env );
(*env)->ExceptionClear( env );
exception_class = (*env)->FindClass(env, "java/io/IOException");
(*env)->ThrowNew(env, exception_class, strerror( errno ) );
throw_io_exception_message( env, "Unable to get handle" );
return;
}
 
1730,11 → 1614,7
 
if( desc == NULL ){
//throw new exception
jclass exception_class;
(*env)->ExceptionDescribe( env );
(*env)->ExceptionClear( env );
exception_class = (*env)->FindClass(env, "java/io/IOException");
(*env)->ThrowNew(env, exception_class, strerror( errno ) );
throw_io_exception_message( env, "Unable to get descriptor" );
return;
}
 
1767,13 → 1647,3
}
}
 
//BOOL EscapeCommFunction(HANDLE, DWORD).
/*
1. CLRDTR
2. SETDTR
3. SETRTS
4. CLRRTS
5. SETBREAK
6. CLRBREAK
*/