#include #include "testClass.h" #include #include #include #include #include /*============================================================================= Définition de constantes =============================================================================*/ #define RX_SIZE 4096 /* taille tampon d'entrée */ #define TX_SIZE 4096 /* taille tampon de sortie */ #define MAX_WAIT_READ 5000 /* temps max d'attente pour lecture (en ms) */ /*============================================================================= Variables globales. =============================================================================*/ /* Handle du port COM ouvert */ HANDLE g_hCOM = NULL; /* Délais d'attente sur le port COM */ COMMTIMEOUTS g_cto = { MAX_WAIT_READ, /* ReadIntervalTimeOut */ 0, /* ReadTotalTimeOutMultiplier */ MAX_WAIT_READ, /* ReadTotalTimeOutConstant */ 0, /* WriteTotalTimeOutMultiplier */ 0 /* WriteTotalTimeOutConstant */ }; /* Configuration du port COM */ DCB g_dcb = { sizeof(DCB), /* DCBlength */ 921600, /* BaudRate */ TRUE, /* fBinary */ FALSE, /* fParity */ FALSE, /* fOutxCtsFlow */ FALSE, /* fOutxDsrFlow */ DTR_CONTROL_ENABLE, /* fDtrControl */ FALSE, /* fDsrSensitivity */ FALSE, /* fTXContinueOnXoff */ FALSE, /* fOutX */ FALSE, /* fInX */ FALSE, /* fErrorChar */ FALSE, /* fNull */ RTS_CONTROL_ENABLE, /* fRtsControl */ FALSE, /* fAbortOnError */ 0, /* fDummy2 */ 0, /* wReserved */ 0x100, /* XonLim */ 0x100, /* XoffLim */ 8, /* ByteSize */ NOPARITY, /* Parity */ ONESTOPBIT, /* StopBits */ 0x11, /* XonChar */ 0x13, /* XoffChar */ '?', /* ErrorChar */ 0x1A, /* EofChar */ 0x10 /* EvtChar */ }; /*============================================================================= Fonctions du module. =============================================================================*/ /* * Class: ComRS232 * Method: OpenCOM * Signature: (Ljava/lang/String;)I */ JNIEXPORT jint JNICALL Java_testClass_OpenCOM(JNIEnv * env, jobject obj, jstring port); /* * Class: ComRS232 * Method: CloseCom * Signature: ()I */ JNIEXPORT jboolean JNICALL Java_testClass_CloseCom(JNIEnv *env, jobject obj); /*********************************************************** * OpenCOM : Ouverture et configuration du port COM * entrée : port : nom du port COM à ouvrir * retour : 1 si l'opération à réussi, 0 sinon * *****************************************************/ JNIEXPORT jint JNICALL Java_testClass_OpenCOM(JNIEnv * env, jobject obj, jstring port){ //(env)->MonitorEnter(obj); const char * portCOMM=env->GetStringUTFChars(port,0); cout<<"code C : ouverture du port "<ReleaseStringUTFChars(port,portCOMM); //(env)->MonitorExit(obj); return 1; } /************************************************************** * CloseCom : fermeture du port COM * retour : 1 si réussi, 0 sinon */ JNIEXPORT jboolean JNICALL Java_testClass_CloseCom(JNIEnv *env, jobject obj){ (env) -> MonitorEnter(obj); /* fermeture du port COM */ cout<<"\n FERMeTURE DU PORT \n"<MonitorExit(obj); } /* * Class: testClass * Method: readCOM * Signature: ()I */ JNIEXPORT jint JNICALL Java_testClass_readCOM(JNIEnv *env, jobject obj){ (env) -> MonitorEnter(obj); cout<<"1"<MonitorExit(obj); return buffer; } /* * Class: testClass * Method: WriteCOM * Signature: (B)Z */ JNIEXPORT jboolean JNICALL Java_testClass_WriteCOM(JNIEnv *env, jobject obj, jbyte byte){ (env) -> MonitorEnter(obj); int buffer=byte; cout<<"valeur à écrire : "<<(int)byte<<"\n"<MonitorExit(obj); return bol; }