IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Entrée/Sortie Java Discussion :

PortInUseException: Port currently owned by -- avec portId.isCurrentlyOwned()==false


Sujet :

Entrée/Sortie Java

  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Juillet 2013
    Messages
    12
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2013
    Messages : 12
    Points : 5
    Points
    5
    Par défaut PortInUseException: Port currently owned by -- avec portId.isCurrentlyOwned()==false
    Bonjour,
    J'utilise javax.comm pour lire un port COM avec mon appli java (j'ai le meme problème avec RXTX), lorsque j'ai une IOException (sans doute du à une erreur de connexion entre le Lantronix Wi-Port et mon PC où je redirige le flux vers le port COM); je ferme mon port et le reouvre et en general ca remarche. Mais parfois j'obtiens une PortInUseException lors de la réouverture du port alors que le portId.isCurrentlyOwned() renvoi "false".
    Note: parfois le port apparaît miraculeusement comme non occupé et ca remarche.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    Trying to open serial port 'COM20'!
    Successfully opened serial port 'COM20'!
     
    CA MARCHE- Tue Aug 20 16:48:52 CEST 2013
     
    CA MARCHE- Tue Aug 20 16:48:54 CEST 2013
     
    CA MARCHE- Tue Aug 20 16:48:56 CEST 2013
     
    (plus tard)
     
    CA MARCHE- Tue Aug 20 18:55:47 CEST 2013
     
    CA MARCHE- Tue Aug 20 18:55:49 CEST 2013
     
    CA MARCHE- Tue Aug 20 18:55:51 CEST 2013
     
    waiting ...
    waiting ...
    waiting ...
    waiting ...
    waiting ...
    echec ...
     
    java.io.IOException: write error
    	at com.sun.comm.Win32SerialPort.write(Win32SerialPort.java:677)
    	at com.sun.comm.Win32SerialPort.write(Win32SerialPort.java:664)
    	at com.sun.comm.Win32SerialOutputStream.write(Win32SerialOutputStream.java:34)
    	at java.io.DataOutputStream.write(Unknown Source)
    	at projet.RS232.demandecontext1(RS232.java:774)
    	at projet.RS232.readBytes(RS232.java:441)
    	at projet.GUI$Thread1.run(GUI.java:1981)
    	at java.lang.Thread.run(Unknown Source)
    trying to close system
    succes to close system
     
    Trying to to open serial port 'COM20'!
    Failed to open serial port 'COM20'!
    javax.comm.PortInUseException: Port currently owned by Unknown Windows Application
    	at javax.comm.CommPortIdentifier.open(CommPortIdentifier.java:337)
    	at projet.RS232.openConnection(RS232.java:333)
    	at projet.GUI$Thread1.run(GUI.java:1988)
    	at java.lang.Thread.run(Unknown Source)
     
    Trying to to open serial port 'COM20'!
    Failed to open serial port 'COM20'!
    javax.comm.PortInUseException: Port currently owned by Unknown Windows Application
    	at javax.comm.CommPortIdentifier.open(CommPortIdentifier.java:337)
    	at projet.RS232.openConnection(RS232.java:333)
    	at projet.GUI$Thread1.run(GUI.java:1988)
    	at java.lang.Thread.run(Unknown Source)
     
    Trying to to open serial port 'COM20'!
    Failed to open serial port 'COM20'!
    javax.comm.PortInUseException: Port currently owned by Unknown Windows Application
    	at javax.comm.CommPortIdentifier.open(CommPortIdentifier.java:337)
    	at projet.RS232.openConnection(RS232.java:333)
    	at projet.GUI$Thread1.run(GUI.java:1988)
    	at java.lang.Thread.run(Unknown Source)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    		//dans le GUI
    			cmdSTART.addActionListener(new ActionListener(){
    				public void actionPerformed(ActionEvent evt){
    					lancer();
    				}
     
     
    	private void lancer(){
    		if(rs232.openConnection()){
    			animated1=true;
    			t1=new Thread(new Thread1());
    			t1.setPriority(7);
    			t1.start();
    			marche=true;
    		}
    	}
     
    	class Thread1 implements Runnable{
    		public void run(){
    			while(animated1){
    				try{
    					rs232.readBytes();
    				}
    				catch(Exception e){
    					e.printStackTrace();
    					rs232.closeConnection();
    					boolean nbbyte=false;
    					while(nbbyte==false){
    						nbbyte=rs232.openConnection();
    						try{
    							Thread.sleep(5000);
    						}
    						catch(InterruptedException e1){
    							e1.printStackTrace();
    						}
    					}
    				}
    			}
    		}
    	}
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    public void readBytes() throws IOException,InterruptedException{
    		demandecontext1();
    		receptdata();
    		traitementdata();
    		try{
    			Thread.sleep(300);
    		}
    		catch(InterruptedException e){
    			e.printStackTrace();
    		}
    	}
     
    	private void demandecontext1() throws IOException,InterruptedException{
    /*ligne 774*/out1x.write(91);
    		out1x.write(91);
    		Thread.sleep(100);
    		out1x.write(48);
    		Thread.sleep(100);
    		out1x.write(65);
    		Thread.sleep(100);
    		out1x.write(48);
    		Thread.sleep(100);
    		out1x.write(48);
    		Thread.sleep(100);
    		out1x.write(48);
    		Thread.sleep(100);
    		out1x.write(49);
    		Thread.sleep(100);
    		out1x.write(93);
    		Thread.sleep(1000);
    	}
     
    	private void receptdata() throws IOException,InterruptedException{
    		byte bufferByte[]=new byte[1024]
    		int nbbyte=in1x.available();
    		int comp=0;
    		while(nbbyte==0&&comp<5){
    			System.out.println("waiting ...");
    			Thread.sleep(1000);
    			nbbyte=in1x.available();
    			comp++;
    		}
    		if(comp==5){
    			System.out.println("echec ...");
    			return;
    		}
    		nbbyte=in1x.read(bufferByte,0,nbbyte);
    		System.out.println("CA MARCHE- "+new Date());
     
    		//+Gestion des bytes recu
     
    	}
     
     
    	public boolean openConnection(){
    		if(portId1x.isCurrentlyOwned()){
    			System.out.println("Port ouvert par une autre application");
    			System.out.println(portId1x.getCurrentOwner());
    			return false;
    		}
    		else{
    			try{
    				System.out.println("Trying to to open serial port '"+com1x+"'!");
    				boolean flag1=portId1x.isCurrentlyOwned();
    				if(flag1){
    					System.out.println("port ="+!flag1);
    				}
    /*ligne 333*/	serialPort1x=(SerialPort) portId1x.open(appName,openTimeOut);
    				System.out.println("Successfully opened serial port '"+serialPort1x.getName()+"'!");
     
    				// Setting the serial connection as requested...
    				serialPort1x.setSerialPortParams(baudrate1,databits,stopbit,parity);
    				in1x=new DataInputStream(serialPort1x.getInputStream());
    				out1x=new DataOutputStream(serialPort1x.getOutputStream());
    				return true;
    			}
    			catch(Exception e){
    				System.out.println("Failed to open serial port '"+serialPort1x[p].getName()+"'!");
    				e.printStackTrace();
    				return false;
    				// JOptionPane.showMessageDialog(null,"Erreur lors de l'ouverture du port "
    				// + com, "ERREUR", JOptionPane.ERROR_MESSAGE);
    				// System.exit(1); // sortie de l'appli
    			}
    		}
    	}
     
    	public void closeConnection(){
    		try{
    			System.out.println("trying to close system ");
    			in1x.close();
    			out1x.close();
    			serialPort1x.close();
    			System.out.println("succes to close system ");
    		}
    		catch(IOException e){
    			System.out.println("failed to close intrusion system ");
    			System.out.println("Cannot open and / or close serial connection!Details:\n"+e.getMessage());
    			//System.exit(1);
    		}
    	}

  2. #2
    Futur Membre du Club
    Profil pro
    Inscrit en
    Juillet 2013
    Messages
    12
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2013
    Messages : 12
    Points : 5
    Points
    5
    Par défaut
    aucune idée ?

  3. #3
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    J'ai l'impression que tu n'a rien d'autre à faire qu'à attendre que windows se rende compte que le port a été libéré.

  4. #4
    Futur Membre du Club
    Profil pro
    Inscrit en
    Juillet 2013
    Messages
    12
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2013
    Messages : 12
    Points : 5
    Points
    5
    Par défaut
    Citation Envoyé par tchize_ Voir le message
    J'ai l'impression que tu n'a rien d'autre à faire qu'à attendre que windows se rende compte que le port a été libéré.
    et pas d'idée sur pourquoi portId.isCurrentlyOwned() ne marche pas ?

  5. #5
    Modérateur

    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    12 551
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 12 551
    Points : 21 607
    Points
    21 607
    Par défaut
    Probablement que quoi que ce soit qui utilise le port ne le fait pas avec javax.comm ou pas une implémentation compatible.
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  6. #6
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Juillet 2013
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2013
    Messages : 13
    Points : 11
    Points
    11
    Par défaut Ouverture d'un port COM/SERIE Java
    Bonjour,

    Je souhaiterai savoir ou vous avez trouver les librairies javax.comm que vous utilisez.
    J'aimerai ouvrir un port com sur ordinateur. Mais il me manque les librairies.

    Merci d'avance ^^

Discussions similaires

  1. Port 1433 SQL SERVER avec VIRTUAL PC
    Par sdelaunay dans le forum MS SQL Server
    Réponses: 2
    Dernier message: 05/01/2009, 10h10
  2. Emettre sur 1 port UDP et réception avec 2 process
    Par dagosgil dans le forum Développement
    Réponses: 1
    Dernier message: 05/09/2007, 23h20
  3. Gestion de port serie sous Xp avec Visual C++
    Par unluckymannn dans le forum VC++ .NET
    Réponses: 1
    Dernier message: 30/11/2006, 09h40
  4. Portée des constantes déclarées avec define
    Par Anduriel dans le forum Langage
    Réponses: 1
    Dernier message: 10/04/2006, 22h03
  5. Réception sur le port série sous DOS avec Borland V3.0
    Par jackyjacky dans le forum Autres éditeurs
    Réponses: 24
    Dernier message: 19/03/2004, 23h18

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo