Friday, April 27, 2012

Android CNC App

I got the whole toolchain working today!  Android app to tgFX, to TinyG, to JGRO CNC.  See the video for a sense of how it currently works.  I hope to have the configuration settings exposed to the UI tonight, so that you don't have to edit the code to change the link to the server.

While the current version relies on tgFX to talk to the hardware (TinyG), that isn't strictly necessary.  I put together a simple serial to network java program which will serve a similar purpose.  I may put that up on github soon too.

Once I get the basics working fairly well, I'll move on to phase 2, which is using my ICS tablet to talk directly to the TinyG vis host USB support.  That will be very nice, and will get me to my main goal - use of the CNC system without a PC being required.

The write code is fairly pedestrian, but the read code from the network took a little work to sort out.  I'm using an AsyncTask to do the blocking reads, and after each line it parses the JSON and updates the necessary state info. 
private class ListenerTask extends AsyncTask {

  protected Void doInBackground(InputStream... params) {
    byte[] buffer = new byte[1024];
    InputStream is = params[0];
    int b;
    int idx=0;
    try {
      while (!isCancelled()) {
        if ((b = == -1) {
      buffer[idx++] = (byte) b;
      if (b == '\n') {
        publishProgress(new String(buffer,0,idx));
        idx = 0;
   } catch (IOException e) {
     Log.e(TAG, "listener read: " + e.getMessage());
   return null;

  protected void onProgressUpdate(String... values) {
    if (values.length > 0) {
      Log.i(TAG, "onProgressUpdate: " + values[0].length() + " bytes received.");
      if (machine.processJSON(values[0])) {

  protected void onCancelled() {
    Log.i(TAG, "ListenerTask cancelled");

Thursday, April 26, 2012

Android CNC code published

I finally setup a github repo for my CNC jogger application.  It's still very much a work in progress, but it's working!  I'm going to be spending some time adding some configuration controls next, and hope to have some additional features and a better control layout by the end of the week.

Code is in Github.  Will post a video of the whole things working on Friday!

Thursday, April 12, 2012

Android CNC Controller Progress

I'm making progress.

I've been discussing some of the controller options with the guys at Synthetos, looking for smart ways to collaborate.  Riley is working on a GUI called tgFX, and while it doesn't meet my needs, I didn't want to duplicate a lot of work either.  The outcome of that discussion means I've added one large new feature to the project, which is the ability to talk to TinyG via the network in addition to direct USB.  tgFX has a network port that it is happy to use as a network to serial gateway, and I've written a simple java program which does the same job without all of the GUI-ness.  What this means is that I've been able to spend more of my time recently working out the architecture in my app and less on the specifics of handling USB host on Android.

At the moment, I have a basic jog interface on the Android, and it is able to connect, get status information from the network port, and send commands.  Still left to do is to have the jog buttons actually send the right commands (easy enough now that I have the basic messaging working) and to have the status information from the device update the axis information/state on the device.  Hopefully it will all be up and working in the next few days.

I will have code posted up soon.