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
| public void portEvent(PortEvent evt) {
switch (evt.getEventType()) {
//Des données sont disponibles depuis le port
case PortEvent.DATA_AVAILABLE:
//System.out.println("DataManager : Receive PORTEVENT.DATA_AVAILABLE");
InputStream input = null;
try {
input = this.myPort.getInputStream();
int maxpixel = this.mySensorManager.getCurrentSensor().getCapacity(); //height*weight
//Construction d'une image du capteur
int i = 0;
while ((input.available() > 0) && (i<maxpixel)) {
System.out.println("DataManager : Reste "+input.available()+" octets a lire");
//System.out.println("DataManager : Lecture de données");
int grey = input.read();
if(grey != -1)
{
System.out.println("Datamanager : Couleur pixel n°"+i+" == "+grey); //Si cette ligne est supprimer aucune lecture est faire. J'ai pas compris pourquoi
this.setPixel(i, grey); //On delegue la responsabilite de la gestion des données d'une image au gestionnaire de données
if(i == maxpixel-1)
{
System.out.println("DataManager : Demande d'envoi de données d'une nouvelle image");
try {
Thread.sleep(5000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
this.myPort.getOutputStream().write(1);
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
else
{
System.out.println("DataManager : Plus aucune données a lire");
}
i++;
}
} catch (IOException e) {
e.printStackTrace();
}
break;
default:
break;
}
} |
Partager