質問

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