G代码?文字在Gcode中发送一个字符串

时间:2013-04-08 13:47:08

标签: java serial-port

如何将Gcodes传送到CNC机器?我的意思是,我可以使用这个连接到读取Gcode的CNC机器接口的SimpleWrite程序吗?

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("COM1")) {
            //if (portId.getName().equals("/dev/term/a")) {
                try {
                    serialPort = (SerialPort)
                        portId.open("SimpleWriteApp", 2000);
                } catch (PortInUseException e) {}
                try {
                    outputStream = serialPort.getOutputStream();
                } catch (IOException e) {}
                try {
                    serialPort.setSerialPortParams(9600,
                        SerialPort.DATABITS_8,
                        SerialPort.STOPBITS_1,
                        SerialPort.PARITY_NONE);
                } catch (UnsupportedCommOperationException e) {}
                try {
                    outputStream.write(messageString.getBytes());
                } catch (IOException e) {}
            }
        }
    }
}

}

我可以将字符串G0 X100 Y100 Z20发送到cnc机器,而不是发送Hello world吗?或者这不是解释Gcode的方式吗?

@Edit

我已多次尝试过这个程序。我试图发送Gcode,而不是发送hello world字符串,但它没有用。有没有人知道如何在不使用gcode解释器的情况下发送一个Gcode?

@ 2e EDIT 我的愚蠢错误就是忘记在每个Gcode之后输入“\ n”。感谢彼得解决我的愚蠢错误!

亲切的问候 帕斯卡

0 个答案:

没有答案
相关问题