954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

write to serial port

Hiii all
I am using java 1.6 and RXTXComm package (Javax.comm) package.
I can read data from a electronic weighing machine. Now I have to set the weight as zero. I can tare this weight by sending T command to serial port. I had tried several times but no response from device. Somebody please help me.

this is my code snippet

public class WriteToSerialPort {
    CommPortIdentifier pid;
    SerialPort serial;
    java.io.OutputStream outstream;
    public void writeToPort() throws Exception
    {
        CommPortIdentifier pid=CommPortIdentifier.getPortIdentifier("COM1");
        serial=(SerialPort)pid.open("test app",1000);
        serial.setSerialPortParams(9600,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
        serial.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
        outstream=serial.getOutputStream();
        char tare=(char)84;
        outstream.write(tare);

    }

    public static void main(String args[])throws Exception
    {
        WriteToSerialPort ob=new WriteToSerialPort();
        ob.writeToPort();
    }
}


thanks in advance

azibhai4u
Newbie Poster
1 post since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

Hi,
I think you should flush the outputstream after you have written data to it.

outstream.flush();
Clawsy
Posting Whiz in Training
225 posts since Feb 2008
Reputation Points: 11
Solved Threads: 7
 

Hello azibhai4u
I am using java 1.6 and RXTXComm package (Javax.comm) package.
HOW can I read data from a electronic weighing machine?
Please help give source code................

qwerty_jakarta
Newbie Poster
2 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

hey, Javax.comm package isn't supported for windows :(
how can I get this? how can I program my serial port - a very simple code just to open a port and see its working?

ferdousKhanom
Newbie Poster
2 posts since Mar 2011
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: