Announcement

Collapse
No announcement yet.

gtp java

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • gtp java

    i sorry, but what is a gtp en the example Web_serverV4, and how i write de code?
    Syntax:
    gtp.send(byte[] array)
    byte[] array = gtp.receive()

    /************************************************** ******/
    /* Start of custom application code */
    /* ADD YOUR CODE HERE */
    /************************************************** ******/
    c.gridx = 0; c.gridy = 2; c.gridwidth = 3; c.gridheight = 1;
    c.anchor = GridBagConstraints.WEST;
    add((new Text_io(gtp)), c);
    /************************************************** ******/
    /* End of custom application code */
    /************************************************** ******

  • #2
    gtp is a reference to the TCPIP class object connected to the Lantronix device. You use the send() and receive() methods to send / receive data from your device.
    Were you not supplied with the source code?

    Comment


    • #3
      hi, look this error:

      import java.awt.*;
      import java.awt.event.*;
      import java.applet.Applet;
      import java.net.*;
      import java.io.*;
      import java.lang.*;
      import java.text.*;
      import java.util.*;

      public class Test extends Applet {

      static private boolean isapplet = true;
      static private InetAddress arg_ip = null;
      static private int arg_port = 0;

      public tcpip gtp = null;;
      InetAddress reader_ip = null;
      int port = 10001;
      public void init()
      {
      gtp = null;
      reader_ip = null;
      port = 10001;
      }
      public void start()
      {
      String st = new String("TCP/IP connection status: ");
      setFont(new Font("Dialog",Font.BOLD,16));
      setLayout(new GridBagLayout());
      GridBagConstraints c = new GridBagConstraints();
      c.gridx = 0; c.gridy = 0; c.gridwidth = 1; c.gridheight = 1;
      c.anchor = GridBagConstraints.CENTER;
      c.fill = GridBagConstraints.BOTH;
      c.insets = new Insets(5,5,5,5);
      setBackground(Color.yellow);
      setSize(600,500);
      /* Either get the IP address from the HTTP server if we're
      an applet, or from the commandline (if passed). */
      if (isapplet) {
      try{
      reader_ip = InetAddress.getByName(getCodeBase().getHost());
      }
      catch (UnknownHostException e){}
      }
      else {
      reader_ip = arg_ip;
      if (arg_port != 0) {
      port = arg_port;
      }
      }
      /* Open a socket to the Device Server's serial port */
      if (reader_ip != null) {
      if (gtp == null) {
      gtp = new tcpip(reader_ip, port);
      if (gtp.s == null) {
      st += "Connection FAILED! ";
      gtp = null;
      }
      }
      }
      if (gtp == null) {
      st += "Not Connected";
      add((new Label(st)), c);
      return;
      }
      st += "Connected";
      add((new Label(st)), c);
      /* You may now perform IO with the Device Server via
      * gtp.send(byte[] data_out);
      * byte[] data_in = gtp.receive();
      * functions.
      * In our example we'll use two TextBoxes which have been extended
      * to handle IO to the Device Server. Data typed in the upper
      * text box will be sent to the Device Server, and data received
      * will be displayed in the lower text box.
      */
      /************************************************** ******/
      /* Start of custom application code */
      /* ADD YOUR CODE HERE */
      /************************************************** ******/

      c.gridx = 0; c.gridy = 2; c.gridwidth = 3; c.gridheight = 1;
      c.anchor = GridBagConstraints.WEST;
      add((new Text_io(gtp)), c);
      gtp.send(byte[] array)
      byte[] array = gtp.receive();
      /************************************************** ******/
      /* End of custom application code */
      /************************************************** ******/
      }
      public void destroy()
      {
      if (gtp != null)
      gtp.disconnect();
      gtp = null;
      }
      public void stop() {
      }
      public static void main(String[] args) {
      Frame frame = new Frame("TCP/IP Test");
      frame.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
      System.exit(0);
      }
      });
      if (args.length > 0) {
      try{
      arg_ip = InetAddress.getByName(args[0]);
      }
      catch (UnknownHostException e){}
      if (args.length > 1) {
      try {
      arg_port = Integer.valueOf(args[1]).intValue();
      }
      catch (NumberFormatException e) {}
      }
      }
      Test ap = new Test();
      frame.add(ap);
      ap.init();
      isapplet = false;
      ap.start();
      frame.pack();
      // frame.show(); /* deprecated */
      frame.setVisible(true);
      }
      }

      Comment


      • #4
        is highlighted where it says to add code here

        Comment


        • #5
          I think you are asking for:
          sval = new byte[100];
          Now sval is declared to hold 100 bytes. Stuff sval with data, set length to the number of data bytes, then call
          gtp.send(sval, length);

          gtp.receive() returns a pointer to the byte array declared in the receive().

          Comment

          Working...
          X