Вопрос

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!

Это было полезно?

Решение

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.

Другие советы

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top