[SOLVED]RXTXcomm: can't receive data. - Raspberry Pi Forums


hi!

here thing: made java application use rxtxcomm communicate xbee (connected through adapter, using proper conversion make mcp2200 uart-usb). app works fine when running in windows (xpvista7) system, i.e. send , receive date properly.
but, when try run same app in pi (with raspbian) goes wrong ... can send data no problem when suposed receive, weird happen: nothing arriving until remove xbee, mean, when disconnect it, data arrive.
... made tests using sysout , noticed that, when im reading port looking data, flag used determine end of stream (code below), flag -1 ... well, app stuck in here when im using raspbian , dont know why ...

here code read:

code: select all

      @override     public void serialevent(serialportevent ev){                 stringbuffer bufferleitura = new stringbuffer();          int novodado = 0;         string flag;                  switch (ev.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:                  //novo algoritmo de leitura.                  while(novodado != -1){                      try{                          novodado = entrada.read();                          system.out.println("serial data: "+novodado);                          if(novodado == -1){                             break;                         }                          bufferleitura.append((char)novodado);                                                                 }catch(ioexception ioe){                          system.out.println("erro de leitura serial:"  + ioe);                      }                  }                     setpeso(string.valueof(bufferleitura));                                      setbuffer(getpeso());                                          system.out.println("entrada char:\n" +getpeso());                     system.out.println("entrada ascii:\n" +ferramentas.ascii(getbuffer()));

obs.: novodado means newdata


, output @ windows:

code: select all

[126, 1, 1, 165, 2, 39, 1] fluxo ok! enviando um byte para com5 enviando :126 fluxo ok! enviando um byte para com5 enviando :1 fluxo ok! enviando um byte para com5 enviando :1 fluxo ok! enviando um byte para com5 enviando :165 fluxo ok! enviando um byte para com5 enviando :2 fluxo ok! enviando um byte para com5 enviando :39 fluxo ok! enviando um byte para com5 enviando :1 serial data: 126 serial data: 1 serial data: 1 serial data: 213 serial data: 5 serial data: 128 serial data: 0 serial data: 4 serial data: 222 serial data: 1 serial data: -1 entrada char: ~Õ€ entrada ascii: [126, 1, 1, 213, 5, 128, 0, 4, 222, 1] check sum ok! 
, raspbian:

code: select all

[126, 1, 1, 165, 2, 39, 1] fluxo ok! enviando um byte para /dev/ttys3 enviando :126 fluxo ok! enviando um byte para /dev/ttys3 enviando :1 fluxo ok! enviando um byte para /dev/ttys3 enviando :1 fluxo ok! enviando um byte para /dev/ttys3 enviando :165 fluxo ok! enviando um byte para /dev/ttys3 enviando :2 fluxo ok! enviando um byte para /dev/ttys3 enviando :39 fluxo ok! enviando um byte para /dev/ttys3 enviando :1 serial data: 126 serial data: 1 serial data: 1 serial data: 213 serial data: 5 serial data: 128 serial data: 0 serial data: 4 serial data: 222 serial data: 1  

there no "-1" @ raspbian... app stuck there , nothing happens until disconect xbee.

when remove xbee, have this:

code: select all

[126, 1, 1, 165, 2, 39, 1] fluxo ok! enviando um byte para com5 enviando :126 fluxo ok! enviando um byte para com5 enviando :1 fluxo ok! enviando um byte para com5 enviando :1 fluxo ok! enviando um byte para com5 enviando :165 fluxo ok! enviando um byte para com5 enviando :2 fluxo ok! enviando um byte para com5 enviando :39 fluxo ok! enviando um byte para com5 enviando :1 serial data: 126 serial data: 1 serial data: 1 serial data: 213 serial data: 5 serial data: 128 serial data: 0 serial data: 4 serial data: 222 serial data: 1 serial data: -1 entrada char: ~Õ€ entrada ascii: [126, 1, 1, 213, 5, 128, 0, 4, 222, 1] serial data: -1 entrada char:  entrada ascii: [126, 1, 1, 213, 5, 128, 0, 4, 222, 1] serial data: -1 entrada char:  entrada ascii: [126, 1, 1, 213, 5, 128, 0, 4, 222, 1] serial data: -1 entrada char:  entrada ascii: [126, 1, 1, 213, 5, 128, 0, 4, 222, 1] serial data: -1 entrada char:  entrada ascii: [126, 1, 1, 213, 5, 128, 0, 4, 222, 1] serial data: -1 entrada char:  entrada ascii: [126, 1, 1, 213, 5, 128, 0, 4, 222, 1] serial data: -1 entrada char:  entrada ascii: [126, 1, 1, 213, 5, 128, 0, 4, 222, 1] serial data: -1 entrada char:  entrada ascii: [126, 1, 1, 213, 5, 128, 0, 4, 222, 1] serial data: -1 entrada char:  entrada ascii: [126, 1, 1, 213, 5, 128, 0, 4, 222, 1] serial data: -1 entrada char:  entrada ascii: [126, 1, 1, 213, 5, 128, 0, 4, 222, 1] serial data: -1 entrada char:  entrada ascii: [126, 1, 1, 213, 5, 128, 0, 4, 222, 1] serial data: -1 entrada char:  entrada ascii: [126, 1, 1, 213, 5, 128, 0, 4, 222, 1] check sum ok! 
while block executed several times after removing xbee.

has clue???

so, found solution! well, still don't know why "-1" freezes system... decided find way control serial communication whitout it... , reached in code

code: select all

                   try {                                          disponivel = entrada.available();                                           while(disponivel > 0){                                                  if((disponivel) > 0){                                                          novodado = entrada.read();                                                          bufferleitura.append((char)novodado);                                                      }                                                  disponivel = entrada.available();                     }                                           } catch( ioexception e ) {                                                                         system.out.println("erro de leitura serial:"  +  e);                     }                                      setpeso(string.valueof(bufferleitura));                                      setbuffer(getpeso());                                          //system.out.println("entrada char:\n" +getpeso());                     system.out.println("entrada ascii:\n" +ferramentas.ascii(getbuffer()));  
can see... i'm not using -1 flag anymore, i'm using 0,working rxtxcomm funtcion...in case 1 called "available". 1 checks if there data in serial port, if there is, return value indicating availeble data... if not, return 0. flag, can data , stop reading port when communication finished without freezing. works fine me, windows , raspbian :d !


raspberrypi



Comments

Popular posts from this blog

Joomla site hacked, cant see front and - Joomla! Forum - community, help and support

Christian Home School Programs - Joomla! Forum - community, help and support

Trouble with PF_OutFlag_I_USE_AUDIO and PF_CHECKOUT_LAYER_AUDIO