0

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!

Andremoniy
  • 34,031
  • 20
  • 135
  • 241
GreenDroid
  • 337
  • 1
  • 6
  • 16

2 Answers2

1

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.

Costis Aivalis
  • 13,680
  • 3
  • 46
  • 47
0

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.

TheWhiteRabbit
  • 15,480
  • 4
  • 33
  • 57
  • That is exactly what I am not able to figure out... This is my first time programming with serial communication... – GreenDroid Jan 28 '13 at 21:15