[JAVA] modem connexion
ghilen06
Messages postés
10
Statut
Membre
-
ghilen06 Messages postés 10 Statut Membre -
ghilen06 Messages postés 10 Statut Membre -
plz aidez moi pour ce programme qui essaie d'envoyer des commandes hayes au modem à vaine,
la fonction pour le parametrage me semble non executée par le pg car meme si j'entre une valeur tres grande du debit, il ne retourne aucune exception!!!
import javax.comm.*;
import com.sun.comm.Win32Driver;
import java.io.*;
import java.lang.Object.*;
public class UtilisationFlux {
private BufferedReader bufRead; //flux de lecture du port
public OutputStream outStream; //flux d'écriture du port
private CommPortIdentifier portId; //identifiant du port
private SerialPort sPort; //le port série
public OutputStreamWriter out = null;
/**
* Constructeur
*/
public UtilisationFlux(String port) {
//initialisation du driver
Win32Driver w32Driver = new Win32Driver();
w32Driver.initialize();
//récupération de l'identifiant du port
try {
portId = CommPortIdentifier.getPortIdentifier(port);
if(portId == null) System.out.println("erreur1 portId");
} catch (NoSuchPortException e) {System.out.println("erreur2 portId");}
//ouverture du port
try {
sPort = (SerialPort) portId.open("UtilisationFlux", 30000);
if(sPort == null) System.out.println("erreur1 sPort");
} catch (PortInUseException e) {System.out.println("erreur2 sPort");}
//règle les paramètres de la connexion
try {
System.out.println("boucle param");
sPort.setDTR(true);
sPort.setRTS(true);
sPort.setSerialPortParams(
9600000,
SerialPort.DATABITS_6,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {}
//récupération du flux de lecture et écriture du port
try {
outStream = sPort.getOutputStream();
bufRead =
new BufferedReader(
new InputStreamReader(sPort.getInputStream()));
} catch (IOException e) {}
}
/**
* Méthode de communication.
*/
public String communique(char envoie) {
String comm ="ATD3453";
String poids = null;
try {
sPort.notifyOnDataAvailable(true);
//demande de poids
out = new OutputStreamWriter(sPort.getOutputStream(), "UTF8");
if (out!=null) System.out.println("out est bon");
sPort.setDTR(true);
sPort.setRTS(true);
if((sPort.isDTR())&&(sPort.isRTS())&&(sPort.isCTS())&&(sPort.isDSR())){ //outStream.write((int) envoie);
out.write(comm, 0, comm.length());
out.flush();
sPort.setDTR(false);
System.out.println("fini");
}
//lecture du poids
//poids = bufRead.readLine().trim();
} catch (IOException e) {}
return poids;
}
/**
* Méthode de fermeture des flux et port.
*/
public void close(){
try {
bufRead.close();
outStream.close();
} catch (IOException e) {}
sPort.close();
}
/**
* Méthode principale de l'exemple.
*/
public static void main(String[] args) {
//Récupération du port en argument
String port = new String("COM3");
//Construction de l'interface à la balance
UtilisationFlux utilFlux = new UtilisationFlux(port);
//"interface utilisateur"
System.out.println("taper q pour quitter, ou ENTER un mot");
//construction flux lecture
BufferedReader clavier = new BufferedReader(new InputStreamReader(System.in));
//lecture sur le flux entrée.
try {
String lu = clavier.readLine();
while (!lu.equals("q")||(lu==null)) {
//if (!lu.equals("q")||(lu==null)) {
System.out.println(utilFlux.communique('$'));
lu = clavier.readLine();
}
} catch (IOException e) {}
utilFlux.close();
}//fermeture main
la fonction pour le parametrage me semble non executée par le pg car meme si j'entre une valeur tres grande du debit, il ne retourne aucune exception!!!
import javax.comm.*;
import com.sun.comm.Win32Driver;
import java.io.*;
import java.lang.Object.*;
public class UtilisationFlux {
private BufferedReader bufRead; //flux de lecture du port
public OutputStream outStream; //flux d'écriture du port
private CommPortIdentifier portId; //identifiant du port
private SerialPort sPort; //le port série
public OutputStreamWriter out = null;
/**
* Constructeur
*/
public UtilisationFlux(String port) {
//initialisation du driver
Win32Driver w32Driver = new Win32Driver();
w32Driver.initialize();
//récupération de l'identifiant du port
try {
portId = CommPortIdentifier.getPortIdentifier(port);
if(portId == null) System.out.println("erreur1 portId");
} catch (NoSuchPortException e) {System.out.println("erreur2 portId");}
//ouverture du port
try {
sPort = (SerialPort) portId.open("UtilisationFlux", 30000);
if(sPort == null) System.out.println("erreur1 sPort");
} catch (PortInUseException e) {System.out.println("erreur2 sPort");}
//règle les paramètres de la connexion
try {
System.out.println("boucle param");
sPort.setDTR(true);
sPort.setRTS(true);
sPort.setSerialPortParams(
9600000,
SerialPort.DATABITS_6,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {}
//récupération du flux de lecture et écriture du port
try {
outStream = sPort.getOutputStream();
bufRead =
new BufferedReader(
new InputStreamReader(sPort.getInputStream()));
} catch (IOException e) {}
}
/**
* Méthode de communication.
*/
public String communique(char envoie) {
String comm ="ATD3453";
String poids = null;
try {
sPort.notifyOnDataAvailable(true);
//demande de poids
out = new OutputStreamWriter(sPort.getOutputStream(), "UTF8");
if (out!=null) System.out.println("out est bon");
sPort.setDTR(true);
sPort.setRTS(true);
if((sPort.isDTR())&&(sPort.isRTS())&&(sPort.isCTS())&&(sPort.isDSR())){ //outStream.write((int) envoie);
out.write(comm, 0, comm.length());
out.flush();
sPort.setDTR(false);
System.out.println("fini");
}
//lecture du poids
//poids = bufRead.readLine().trim();
} catch (IOException e) {}
return poids;
}
/**
* Méthode de fermeture des flux et port.
*/
public void close(){
try {
bufRead.close();
outStream.close();
} catch (IOException e) {}
sPort.close();
}
/**
* Méthode principale de l'exemple.
*/
public static void main(String[] args) {
//Récupération du port en argument
String port = new String("COM3");
//Construction de l'interface à la balance
UtilisationFlux utilFlux = new UtilisationFlux(port);
//"interface utilisateur"
System.out.println("taper q pour quitter, ou ENTER un mot");
//construction flux lecture
BufferedReader clavier = new BufferedReader(new InputStreamReader(System.in));
//lecture sur le flux entrée.
try {
String lu = clavier.readLine();
while (!lu.equals("q")||(lu==null)) {
//if (!lu.equals("q")||(lu==null)) {
System.out.println(utilFlux.communique('$'));
lu = clavier.readLine();
}
} catch (IOException e) {}
utilFlux.close();
}//fermeture main
A voir également:
- [JAVA] modem connexion
- Gmail connexion - Guide
- Jeux java itel - Télécharger - Jeux vidéo
- Waptrick java football - Télécharger - Jeux vidéo
- Waptrick java voiture - Télécharger - Jeux vidéo
- Java apk - Télécharger - Langages
2 réponses
Salut!
Je n'ai jamais travaillé avec javax.comm, mais j'ai trouvé un lien qui pourrait t'intéresser:
https://www.infoworld.com/article/2076664/java-gets-serial-support-with-the-new-javax-comm-package.html
Il y a un paragraphe "What is not provided" qui parle de ce qui n'est pas possible avec les modems.
Hope it helps...
;-)
HackTrack
Je n'ai jamais travaillé avec javax.comm, mais j'ai trouvé un lien qui pourrait t'intéresser:
https://www.infoworld.com/article/2076664/java-gets-serial-support-with-the-new-javax-comm-package.html
Il y a un paragraphe "What is not provided" qui parle de ce qui n'est pas possible avec les modems.
Hope it helps...
;-)
HackTrack
j'ai resolu le pb,
quoiqu'il reste un autre defi à soulever,
je peux entendre mon correspondant quand je lui compose son num via mon pg java mais le pb c'est qu'il n'arrive pas à m'entendre,
la conversation n'est pas full duplex c un simplex
ya t-il des commandes hayes qu'il faut envoyer au modem pour regler ce pb???
quoiqu'il reste un autre defi à soulever,
je peux entendre mon correspondant quand je lui compose son num via mon pg java mais le pb c'est qu'il n'arrive pas à m'entendre,
la conversation n'est pas full duplex c un simplex
ya t-il des commandes hayes qu'il faut envoyer au modem pour regler ce pb???