0

i am trying to send AT commands on a GSM modem.
this is my code..

import java.io.*;
import java.util.*;
import javax.comm.*;
public class SimpleWrite 
{
	static Enumeration portList;
	static CommPortIdentifier portId;
	static String commands[] ={"AT+CMGS=1","AT+CMGS=\"+919007413343\","Hello there"};
	static byte[] newline[]={(byte)13,(byte)10};
	static SerialPort serialPort;
	static OutputStream outputStream;
public static void main(String[] args) 
{
	portList = CommPortIdentifier.getPortIdentifiers();
	while (portList.hasMoreElements()) 
	{
	portId = (CommPortIdentifier) portList.nextElement();
		if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL)

		{
			if (portId.getName().equals("COM13")) //your comm port
			{
				try 
				{
				serialPort = (SerialPort)
				portId.open("SimpleWriteApp", 2000);
				} 	
				catch (PortInUseException e) {}

				try 
				{
					//get the output stream
					outputStream = serialPort.getOutputStream();
					//write the commands string to the output stream
					for(int i=0;i<commands.length;i++)
					{ 
						outputstream.write(commands[i]); // write command
						outputstream.write(newline); //write new line
					}
					outputStream.write(messageString.getBytes());
				} 
				catch (IOException e) {}
			}
		}
	}
}
}

while compiling i am getting following error..

SimpleWrite.java:8: '}' expected
        static String commands[] ={"AT+CMGS=1","AT+CMGS=\"+919007413343\","Hello
 there"};
                                                                           ^
SimpleWrite.java:8: unclosed string literal
        static String commands[] ={"AT+CMGS=1","AT+CMGS=\"+919007413343\","Hello
 there"};

      ^
2 errors

please help...

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by JamesCherrill
0

Count and match your quotes - there are 7 on that line = 1 unmatched. The colour coding (blue = string literal) in your posted code is a good clue.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.