Hi

i have just made this patch for the use of storing the current tool in spindle
value to a file.
this is aimed to people that have a ATC of sorts but with no means of reading in
current tool position or there is no ideal way to fix a means of reading in
current tool position.
i hope this is usefull to others in one form oranother

the code uses a varible read from the ini file
varible should be in EMCIO section, called
TOOL_STORE =

TOOL_STORE = 0 or not declared, means default behavour of EMC, no value stored
or read. even if value is in the file.
TOOL_STORE = 1, means the value is read on load up of EMC, if file does not
exsist, one is made to store value, and value of zero is assended as default.
                              value is stored on each tool change complete, or
when M61 Q is issued.

Patch code is attached to bottom of this email, was made using Git.

i hope this can be helpful to others etc, i am by no means a programmer so
please review the code carfully

thank you
Robert

Date: Sun, 21 Jun 2009 20:57:45 +0100
Subject: [PATCH] add tool in spindle store

Signed-off-by: robert harpham <rob...@innovative-rc.co.uk>
---
src/emc/iotask/ioControl.cc |  115 ++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 113 insertions(+), 2 deletions(-)
mode change 100644 => 100755 src/emc/iotask/ioControl.cc

diff --git a/src/emc/iotask/ioControl.cc b/src/emc/iotask/ioControl.cc
old mode 100644
new mode 100755
index ec0c60a..e654b59
--- a/src/emc/iotask/ioControl.cc
+++ b/src/emc/iotask/ioControl.cc
@@ -76,6 +76,9 @@ static NML *emcErrorBuffer = 0;

static char *ttcomments[CANON_TOOL_MAX+1];

+//int to read ini value to
+int store_toolInSpindle = 0;
+
struct iocontrol_str {
    hal_bit_t *user_enable_out;    /* output, TRUE when EMC wants stop */
    hal_bit_t *emc_enable_in;    /* input, TRUE on any external stop */
@@ -235,11 +238,89 @@ static int iniLoad(const char *filename)
         filename, EMC_IO_CYCLE_TIME);
    }

+//START for read_toolInSpindle
+//find the TOOL_STORE from ini file in EMCIO section
+    if (NULL != (inistring = inifile.Find("TOOL_STORE", "EMCIO"))) {
+        if(1 == sscanf(inistring, "%i", &store_toolInSpindle)) { +           
if (store_toolInSpindle == 1){
+            store_toolInSpindle = 1;
+            } else {
+            store_toolInSpindle = 0;
+            }
+
+        }
+    } else {
+    // not found, use default
+    store_toolInSpindle = 0;
+    }
+// END read_toolInSpindle
+   
+   
    // close it
    inifile.Close();

    return 0;
}
+//START read_toolInSpindle
+FILE *fo;
+
+int read_toolInSpindle();
+void save_toolInSpindle(int s32);
+
+/********************************************************************
+*
+* Description: read_toolInSpindle
+*            Reads the tool values from file +*           
+* Returns:    tool number from file
+*
+* +* Called By:
+********************************************************************/
+
+int read_toolInSpindle()
+{
+  char s[80];
+  int out;
+
+  fo = fopen("toolInSpindle.txt", "rt");
+  if(fo == NULL)
+  {
+    printf("Unable to open input file!\n");
+    out = 0;
+  }
+  else
+  {
+    fgets(s, 80, fo);  /* get a whole line from the file */
+    sscanf(s, "%i", &out);
+    fclose(fo);
+  }
+
+  return out;
+}
+/********************************************************************
+*
+* Description: save_toolInSpindle(int s32)
+*            saves the tool values from emcioStatus.tool.toolInSpindle into 
file
+*           
+*
+* +* Called By:
+********************************************************************/
+void save_toolInSpindle(int s32)
+{
+  fo = fopen("toolInSpindle.txt", "wt");
+  if(fo == NULL)
+  {
+    printf("Unable to open output file!\n");
+  }
+  else
+  {
+    fprintf(fo, "%i", s32);
+    fclose(fo);
+  }
+}
+//END read_toolInSpindle

/********************************************************************
*
@@ -670,6 +751,7 @@ void hal_init_pins(void)
    *(iocontrol_data->tool_prepare)=0;        /* output, pin that notifies HAL
it needs to prepare a tool */
    *(iocontrol_data->tool_prep_number)=0;    /* output, pin that holds the tool
number to be prepared, only valid when tool-prepare=TRUE */
    *(iocontrol_data->tool_change)=0;        /* output, notifies a tool-change
should happen (emc should be in the tool-change position) */
+    *(iocontrol_data->tool_number) = read_toolInSpindle(); /*output s32, pin
that sets tool in spindle number */
}


@@ -737,6 +819,13 @@ int read_tool_inputs(void)
        if (*iocontrol_data->tool_change && *iocontrol_data->tool_changed) {
    emcioStatus.tool.toolInSpindle = emcioStatus.tool.toolPrepped; //the tool
now in the spindle is the one that was prepared
+//read_toolInSpindle
+        //see if we need to save the toolinspindle value
+        if (store_toolInSpindle == 1){
+        printf("michaels hack\n");
+        save_toolInSpindle(emcioStatus.tool.toolInSpindle);
+        } +//read_toolInSpindle
    *(iocontrol_data->tool_number) = emcioStatus.tool.toolInSpindle; //likewise
in HAL
    emcioStatus.tool.toolPrepped = -1; //reset the tool preped number, -1 to
permit tool 0 to be loaded
    *(iocontrol_data->tool_prep_number) = 0; //likewise in HAL
@@ -828,7 +917,15 @@ int main(int argc, char *argv[])
    /* set status values to 'normal' */
    emcioStatus.aux.estop = 1; //estop=1 means to emc that ESTOP condition is 
met
    emcioStatus.tool.toolPrepped = -1;
-    emcioStatus.tool.toolInSpindle = 0;
+//read_toolInSpindle
+    //see if we need to set the value on startup
+    if (store_toolInSpindle == 1){
+    emcioStatus.tool.toolInSpindle = read_toolInSpindle();
+    } else {
+    //if we dont read it set it to 0
+    emcioStatus.tool.toolInSpindle = 0;
+    }
+//read_toolInSpindle
    emcioStatus.coolant.mist = 0;
    emcioStatus.coolant.flood = 0;
    emcioStatus.lube.on = 0;
@@ -935,7 +1032,15 @@ int main(int argc, char *argv[])

    case EMC_TOOL_UNLOAD_TYPE:
        rtapi_print_msg(RTAPI_MSG_DBG, "EMC_TOOL_UNLOAD\n");
-        emcioStatus.tool.toolInSpindle = 0;
+//read_toolInSpindle
+            //see if we need to read value on startup
+            if (store_toolInSpindle == 1){
+            emcioStatus.tool.toolInSpindle = read_toolInSpindle();
+            } else {
+            //if we dont read it set it to 0
+            emcioStatus.tool.toolInSpindle = 0;
+            }
+//read_toolInSpindle
        break;

    case EMC_TOOL_LOAD_TOOL_TABLE_TYPE:
@@ -982,6 +1087,12 @@ int main(int argc, char *argv[])
        number = ((EMC_TOOL_SET_NUMBER *) emcioCommand)->tool;
        rtapi_print_msg(RTAPI_MSG_DBG, "EMC_TOOL_SET_NUMBER old_loaded=%d
new_number=%d\n", emcioStatus.tool.toolInSpindle, number);
        emcioStatus.tool.toolInSpindle = number;
+//read_toolInSpindle
+            // see if we save the tool
+            if (store_toolInSpindle == 1){
+            save_toolInSpindle(emcioStatus.tool.toolInSpindle);
+            }
+//read_toolInSpindle
        *(iocontrol_data->tool_number) = emcioStatus.tool.toolInSpindle;
//likewise in HAL
        }
        break;
-- 
1.5.4.3




------------------------------------------------------------------------------
Are you an open source citizen? Join us for the Open Source Bridge conference!
Portland, OR, June 17-19. Two days of sessions, one day of unconference: $250.
Need another reason to go? 24-hour hacker lounge. Register today!
http://ad.doubleclick.net/clk;215844324;13503038;v?http://opensourcebridge.org
_______________________________________________
Emc-developers mailing list
Emc-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-developers

Reply via email to