wood burning stoves 2.0*
The moose likes I/O and Streams and the fly likes Out Stream writer problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Out Stream writer problem" Watch "Out Stream writer problem" New topic
Author

Out Stream writer problem

Ashkan Ekhtiari
Greenhorn

Joined: Jul 24, 2010
Posts: 2
I have an application that writes into serial port frequently , it works on ubuntu perfectly but on XP it doesn't write into output.
Also some where in application I try to commuicate via TCP socket, there also it doesn't send it output.

the code for writing to serial port is :

CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
if (portIdentifier.isCurrentlyOwned()) {
System.out.println("Error: Port is currently in use");
} else {
try {
commPort = portIdentifier.open(this.getClass().getName(), 2000);
if (commPort instanceof SerialPort) {
SerialPort serialPort = (SerialPort) commPort;
serialPort.setSerialPortParams(57600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
out = serialPort.getOutputStream();
in = serialPort.getInputStream();

then I try out.write(bytearray);

but it doesn't send that.



Also I try the following code for socket :

skt = new Socket("10.5.0.1", 2947);
in = new BufferedReader(new InputStreamReader(skt.getInputStream()));
out = new BufferedWriter(new OutputStreamWriter(skt.getOutputStream()));


here also out.write(mystring);

is not sending.

Maybe I need to set some setting for that.

Ashkan Ekhtiari
Greenhorn

Joined: Jul 24, 2010
Posts: 2
some thing that might be important is that I use COM6 as a portname passing to serial port.

the device that I am trying to connect to is a sensor and it gets the string as serial@/dev/USB0:57600 on linux so how it can be on windows?

serial@COM6:57600 doesn't work.

maybe I should set soem other name for port name on XP.

any Idea?
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
It would help if you post all of your code - not just code snippets. Also, please UseCodeTags. Using code tags makes the code much more readable. Have you tested whether out.write(bytearray) is actually being called? I see you haveCould this statement cause the out.write(bytearray) to be skipped? Or maybe an exception that the code is ignoring is being thrown. Are you calling flush() and/or closing the streams? Seeing all the code will show these things.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Out Stream writer problem
 
Similar Threads
Java Telephone API (JTAPI)
Problem with jframe, serial communication, dynamic changing value and displaying it
Tried for hours and hours to work this out, data buffer from one class back to my main class?
Modem/Serial Comm. Problem
Two way communcation with the serial port (modem to modem)