Visualizzazione dei risultati da 1 a 4 su 4
  1. #1

    JMF e JavaComm

    Ciao a tutti....sto cercando di realizzare una applicazionie di Streaming implementata utilizzando le JMF e che utilizza come canale di comunicazione la porta seriale RS232......
    Come posso realizzare una lettura ed una scrittura con priorità utilizzando le java comm oppure come posso modificare le dimensioni del buffer della porta seriale??

    :master:
    Grazie

  2. #2

    Lettura su porta seriale

    salve a tutti...
    Sono settimane che non riesco a risolvere questo problema...
    Sto cercando di realizzare un' applicazione di streaming che usi la porta seriale....lato server, e quindi in scrittura sembra che non ci siano problemi, lato client però, le cose non vanno,non riesco a leggere in maniera corretta, la classe che implementa il thread di lettura della porta seriale è la seguente:

    class SerialInputStream extends Thread implements PushSourceStream ,SerialPortEventListener{

    boolean done = false;
    boolean dataRead = false;
    Serial port;
    InputStream inStream;
    int offset, length;
    byte[] buffer;
    int num;
    SourceTransferHandler sth= null;
    ObjectOutputStream dout;
    int ByteRead;
    int off;

    public SerialInputStream (Serial port) {
    this.port = port;
    try {
    FileOutputStream file =new FileOutputStream("testWrite.txt");
    dout = new ObjectOutputStream(file); } catch (Exception e) {}
    ByteRead=0;
    off=0;
    }

    public int read(byte readBuffer[], int offset, int length) {

    port.open();
    //System.err.println("Try to read\n");
    try {


    port.serialPort.addEventListener(this);
    } catch (TooManyListenersException e) {}
    int numBytes;

    try {
    //port.serialPort.getInputStream();
    port.serialPort.notifyOnDataAvailable(true);

    if ( port.inputStream.available() > 0) {


    //System.err.println("Dati disponibili\n");
    numBytes = port.inputStream.read(readBuffer, offset,length);
    ByteRead = ByteRead+numBytes;
    System.err.println("Totale byte letti :"+ ByteRead+"\n");
    // off= off+length;
    // dout.write(readBuffer, off ,length);
    //dout.close();

    }


    else

    {
    System.out.println("Non ci sono dati disponibili\n");
    //port.close();

    return -1;
    }
    synchronized (this) {
    dataRead = true;
    notifyAll();
    }



    }
    catch (IOException e) {
    //port.close();
    return -1;}

    //port.close();
    return numBytes;
    }

    public synchronized void start() {

    super.start();
    if (sth != null) {
    dataRead = true;
    notifyAll();
    }
    }

    public synchronized void kill() {
    done = true;
    port.close();
    notifyAll();
    }

    public int getMinimumTransferSize() {
    return 2*1024; // twice the MTU size, just to be safe.
    }

    public synchronized void setTransferHandler(SourceTransferHandler sth) {
    this.sth = sth;
    //sth = setTransferHandler( new SerialTransferHandler(this));
    dataRead= true;
    }

    // Not applicable.
    public ContentDescriptor getContentDescriptor() {
    return null;
    }

    // Not applicable.
    public long getContentLength() {
    //return LENGTH_UNKNOWN;
    return -1;
    }

    // Not applicable.
    public boolean endOfStream() {
    return false;
    }

    // Not applicable.
    public Object[] getControls() {
    return new Object[0];
    }

    // Not applicable.
    public Object getControl(String type) {
    return null;
    }


    /**
    * Loop and notify the transfer handler of new data.
    */
    public void run() {

    while (!done) {

    synchronized (this) {
    while (!dataRead && !done) {

    try {

    wait();
    System.err.println("Waiting\n");

    }
    catch (InterruptedException e) { }
    }
    dataRead = false;
    }

    if (sth != null && !done) {
    sth.transferData(this);
    //Questo punta a null e quindi non trasmette niente
    }
    }
    }





    public void serialEvent(SerialPortEvent event) {

    switch(event.getEventType()) {


    case SerialPortEvent.BI:
    case SerialPortEvent.OE:
    case SerialPortEvent.FE:
    case SerialPortEvent.PE:
    case SerialPortEvent.CD:
    case SerialPortEvent.CTS:
    case SerialPortEvent.DSR:
    case SerialPortEvent.RI:
    case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
    break;
    case SerialPortEvent.DATA_AVAILABLE:


    break;
    }
    }


    }//end class SerialInputStream

    L'apertura della porta seriale viene anche fatta nel costruttore della mia classe che estende serialPort....ora perchè se tolgo la open() all'interno della read , il player del Client non legge più alcun dato da seriale???
    Lasciando la open mi legge dei dati ma la riproduzione del file è pessima...
    HELP ME PLEASE!!!!!!!

  3. #3
    Moderatore di Programmazione L'avatar di alka
    Registrato dal
    Oct 2001
    residenza
    Reggio Emilia
    Messaggi
    24,463

    Moderazione

    Ho unito le discussioni che hai aperto sul problema delle porte seriali.

    Ciao!
    MARCO BREVEGLIERI
    Software and Web Developer, Teacher and Consultant

    Home | Blog | Delphi Podcast | Twitch | Altro...

  4. #4
    Grazie..spero tanto che possa darmi una mano qualcuno...sono un sacco di giorni che ci sto sbattendo la testa...

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.