160 Chapter3
Programming Examples
Using Java Programming Over Socket LAN
responseThread = null;
}
}
// Response thread running
public void run() {
String str = ""; // Initialize str to null
// Clear the error queue before starting the thread
// in case if there's any error messages from the previous actions
while ( str.indexOf("No error") == -1 ) {
sck.ScpiWriteLine("syst:err?");
str = sck.ScpiReadLine();
}
// Start receiving response or error messages
while(true) {
str = sck.ScpiReadLine();
if ( str != null ) {
// If response messages is "No error", do no display it,
// replace it with "OK" instead.
if ( str.equals("+0,\"No error\"") ) {
str = "OK";
}
// Display any response messages in the Response panel
scpiResponse.appendText(str+"\n");
}
}
}
// Set up and open the SCPI sockets
private void SetupSockets() {
// Get server url
appletBase = (URL)getCodeBase();
// Open the sockets
sck = new Socks(appletBase);
}
// Set up the SCPI command and response panels
private void SetupPanels() {
// Set up SCPI command panel
southPanel.setLayout(new GridLayout(1, 1));
p = new Panel();
p.setLayout(new BorderLayout());
p.add("West", new Label("SCPI command:"));
p.add("Center", scpiCommand);
southPanel.add(p);
// Set up the Response panel
setLayout(new BorderLayout(2,2));
add("Center", scpiResponse);
add("South", southPanel);
}