Forums Register Login

Out Stream writer problem

+Pie Number of slices to send: Send
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.

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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 have gone to look for myself. If I should return before I get back, keep me here with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1263 times.
Similar Threads
Java Telephone API (JTAPI)
Problem with jframe, serial communication, dynamic changing value and displaying it
Two way communcation with the serial port (modem to modem)
Tried for hours and hours to work this out, data buffer from one class back to my main class?
Modem/Serial Comm. Problem
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 09:48:45.