Mini Maestro 12 and Java

Hello! Please show live code that runs on JAVA … I used an example:

import gnu.io.CommPort;
import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;

public class PololuSerialExample {

      public PololuSerialExample() {
            super();
      }

      static void listPorts() {
            java.util.Enumeration<CommPortIdentifier> portEnum = CommPortIdentifier.getPortIdentifiers();
            while (portEnum.hasMoreElements()) {
                  CommPortIdentifier portIdentifier = portEnum.nextElement();
                  System.out.println(portIdentifier.getName() + " - "
                          + getPortTypeName(portIdentifier.getPortType()));
            }
      }

      static String getPortTypeName(int portType) {
            switch (portType) {
                  case CommPortIdentifier.PORT_I2C:
                        return "I2C";
                  case CommPortIdentifier.PORT_PARALLEL:
                        return "Parallel";
                  case CommPortIdentifier.PORT_RAW:
                        return "Raw";
                  case CommPortIdentifier.PORT_RS485:
                        return "RS485";
                  case CommPortIdentifier.PORT_SERIAL:
                        return "Serial";
                  default:
                        return "unknown type";
            }
      }

      public static void main(String[] args) {

            // We renamed /dev/ttyACM0 to /dev/ttyUSB0 because the rxtx.org library
            // doesn't recognize devices prefixed by ttyACM.
            String portName = "COM5";

            try {

                  listPorts();

                  CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
                  if (portIdentifier.isCurrentlyOwned()) {
                        System.out.println("Error: Port is currently in use");
                  } else {
                        CommPort commPort = portIdentifier.open("Owner", 2000);
                        if (commPort instanceof SerialPort) {

                              // we create a output stream for serial port:
                              SerialPort serialPort = (SerialPort) commPort;
                              serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8,
                                      SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
                              OutputStream serialStream = serialPort.getOutputStream();

                              byte command = (byte) 0xFF;
                              int servo = 0;
                              int position = 992;

                              String message = String.format(
                                      "Writing command=%d servo=%d, psition=%d",
                                      command, servo, position);
                              System.out.println(message);


                              byte[] bytes = new byte[]{(byte) command,
                                    (byte) servo, (byte) position};


                              serialStream.flush();
                              serialStream.write(bytes);



                              commPort.close();
                        }
                  }
            } catch (Exception e) {
                  e.printStackTrace();
            }
      }
}

code is not legal competence. took it on this forum, it is connected properly, the Maestro Control Center all turns.
Hello from Russia

Hello.

What operating system does your computer run? Could you please tell me what Serial mode you chose for the Maestro? You can find out by looking in the “Serial settings” tab of the Maestro Control Center. Also, could you please tell me how you chose COM5?

We do not have any example code for Java except the code from other customers that you found in that other thread. I do not understand what you mean by “code is not legal competence”. If you still need more help after checking the serial mode and the COM port, please try to give a better description of what is going wrong.

The Maestro can be controlled just like any other serial device. You might want to search the internet for information about sending bytes to a serial port with Java.

If you cannot get the serial interface working, you could instead make your java program just run UscCmd, the command-line utility for the Maestro that should already be installed on your computer.

–David

  1. so I opted for COM5 and COM6.
  2. I was referring to working code.
  3. os windows 7
  4. Maestro Control Center it works

when I post. LED blinks when sending packets, but nothing happens

give an example of a package of motion actuator. I want to say that I send him so he moved?

I apologize for my english

COM5 is the correct choice. Could you please tell me what serial mode you chose for the Maestro? The serial modes are documented in the “Serial Settings” section of the Maestro user’s guide.

–David

Maestro Control Center is working.
I can not run from a java program servos.

import gnu.io.CommPort;
import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;
import java.io.InputStream;
import java.io.OutputStream;

public class PololuSerialExample {

      public PololuSerialExample() {
            super();
      }

      static void listPorts() {
            java.util.Enumeration<CommPortIdentifier> portEnum = CommPortIdentifier.getPortIdentifiers();
            while (portEnum.hasMoreElements()) {
                  CommPortIdentifier portIdentifier = portEnum.nextElement();
                  System.out.println(portIdentifier.getName() + " - "
                          + getPortTypeName(portIdentifier.getPortType()));
            }
      }

      static String getPortTypeName(int portType) {
            switch (portType) {
                  case CommPortIdentifier.PORT_I2C:
                        return "I2C";
                  case CommPortIdentifier.PORT_PARALLEL:
                        return "Parallel";
                  case CommPortIdentifier.PORT_RAW:
                        return "Raw";
                  case CommPortIdentifier.PORT_RS485:
                        return "RS485";
                  case CommPortIdentifier.PORT_SERIAL:
                        return "Serial";
                  default:
                        return "unknown type";
            }
      }

      public static void main(String[] args) {

            // We renamed /dev/ttyACM0 to /dev/ttyUSB0 because the rxtx.org library
            // doesn't recognize devices prefixed by ttyACM.
            String portName = "COM5";

            try {

                  listPorts();

                  CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
                  if (portIdentifier.isCurrentlyOwned()) {
                        System.out.println("Error: Port is currently in use");
                  } else {
                        CommPort commPort = portIdentifier.open("Owner", 2000);
                        if (commPort instanceof SerialPort) {

                              // we create a output stream for serial port:
                              SerialPort serialPort = (SerialPort) commPort;
                              serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8,
                                      SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
                              OutputStream serialStream = serialPort.getOutputStream();

                              byte command = (byte) 0x84;
                              int servo = 0x00;
                              int target1 = 0x70;
                              int target2 = 0x2E;
                              String message = String.format(
                                      "Writing command=%d servo=%d, psition=%d, target=%d",
                                      command, servo, target1, target2);
                              System.out.println(message);


                              byte[] bytes = new byte[]{command,
                                    (byte) servo, (byte) target1, (byte) target2};

                              serialStream.flush();
                              serialStream.write(bytes);

                              serialStream.close();

                              commPort.close();
                        }
                  }
            } catch (Exception e) {
                  e.printStackTrace();
            }
      }
}

on COM5 is sending, but I see no movement.
This is what happens:

while the program Maestro Control Center did not send to COM5. that’s what I heard from the Maestro Control Center

6-port the same…
question, which sends the “Maestro Control Center” your team?

Last screen - JAVA program sends

paraphrasing. Maestro Control Center software does not send to COM5 their teams. how do I know where it sends? I also want to go there



it is unclear

I can see from your screenshot that the Maestro’s serial mode is UART, fixed baud rate. Please try changing it to USB Dual Port. I also recommend reading all the information about the serial interface in the Maestro user’s guide.

The Maestro Control Center does not use a virtual COM port; it uses the native USB interface.

–David

as a simple thank you, David. спасибо тебе по русски огромное, я пять дней не спал искал ответы где не надо))) Я выпью за твое здоровье) удачи тебе, спасибо мужик ты настоящий прогер!