Rxtx Rs232: I Can t send to the port

Status
Nicht offen für weitere Antworten.

rimhelaoui

Mitglied
Hi everyone,

I am trying to use the rxtx lib to communicate with some RFID readers through the RS 232 interface. My class seems to receive the right data from the readers, however, these don t seem to recognize the commands sent using

outputStream.write(Mycommand.getBytes()) .

I only need to send a very simple string so that they start reading. Curiously enough, they seem to work properly when I send the that string/command though the hyperteminal..


Could anyone give me a hint? I would be very thankful.


Cheers,
 
T

tuxedo

Gast
Maybe try "flush()" on the output stream ...

Usually there's a tx buffer. If you write less than {buffer size} bytes, then nothing leaves the interface until the buffer gets an overflow.

- Alex
 

rimhelaoui

Mitglied
Thank you for the answer.. I have already used the flush() method.. to no avail.
I am doubting the coding issue about the string command.. May be the coding in java is different from that used by the Hyperterminal?
 
T

tuxedo

Gast
Maybe a new line is needed at the end of you command?

How are you sending commands in hyperterminal? Do you have to press "enter" after each command?

- Alex
 

rimhelaoui

Mitglied
Thank you again Alex.. still in vain :(
There is a very strange thing though.. I have tried to output the bytes that should be sent to the port:

System.out.println(messageString.getBytes().toString());

Surprisingly enough, I get different values like for example:

[B@1270b73
[B@60aeb0


Cheers
 

faetzminator

Gesperrter Benutzer
you have to iterate through all values, in this case with the following code for example:
Java:
byte[] bytes = messageString.getBytes();
for (byte b : bytes) {
    System.out.print(((int) b) + " ");
}
 
Status
Nicht offen für weitere Antworten.

Ähnliche Java Themen

Neue Themen


Oben