This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Out Stream writer problem

 
Ashkan Ekhtiari
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 618
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic