GreenDroid
GreenDroid

Reputation: 347

Java Serial Communication PortInUseException

I have an SMS-based Java application using CommV3 drivers for Serial communication to a GSM Modem. I have two separate codes, one for sending messages and one for receiving messages. Each code works perfectly when executed individually.

Now, when I want to integrate both these codes, I get a PortInUseException, which might be obvious. But, I am not sure where to start from.

Could I get pointers/ links/ tutorials where I could start resolving my issue. I do not have a clue where I should start from.

Thanks in advance!

Upvotes: 0

Views: 392

Answers (2)

Costis Aivalis
Costis Aivalis

Reputation: 13728

Make sure that your code uses one SerialPort and not two. Then there is no problem reading or writing to this port.

SerialPort serialPort;
InputStream inStream;
OutputStream outStream;

serialPort = (SerialPort) portId.open(...);
serialPort.setFlowControlMode(...);
serialPort.setSerialPortParams(...);

inStream = serialPort.getInputStream ();
outStream = serialPort.getOutputStream ();

PS: SMSLib is an excellent Java library (ported to .NET Framework as well) which allows you to send/receive SMS messages via a compatible GSM modem or GSM phone. SMSLib also supports some bulk SMS operators. It is free and very stable.

Upvotes: 1

TheWhiteRabbit
TheWhiteRabbit

Reputation: 15758

Probably you can separate out the listener code (which binds to a port) from 2 codes . and dedicate to the appropriate code segment based on send / recieve.

Upvotes: 0

Related Questions