G43 G49 status Led and Toggle
Hello everyone I am trying to implement a button to turn tool length compensation on and off or at the least a Led to see the status.
Only thing I can think of is to monitor the variables for tool length offset and current fixture offset
Is there an easier solution
I don't have the ability to recompile from visual studio.
2 Attachment(s)
Re: G43 G49 status Led and Toggle
Hi dirtdigger257,
I can't think of an easy way to do this without adding some new functionality.
The Tool Length Index is -1 when Length Compensation is turned off.
Here is a C Program that maintains a Virtual Bit (actually a KFLOP LED Bit 46) based on periodically requesting the Index
Code:
#include "KMotionDef.h"
#define TMP 10 // which spare persist to use to transfer data
#include "KflopToKMotionCNCFunctions.c"
void ServiceToolOffsetMode(void);
main()
{
for (;;) // forever loop
{
ServiceToolOffsetMode();
}
}
#define STATUSBIT 46
// periodically set Virtual Bit based on Tool Table Index
void ServiceToolOffsetMode(void)
{
static double LastTime = 0;
int Units, TWORD, HWORD, DWORD;
if (Time_sec() < LastTime + 0.3)
return;
LastTime = Time_sec();
GetMiscSettings(&Units, &TWORD, &HWORD, &DWORD);
SetStateBit(STATUSBIT, HWORD != -1);
}
https://youtu.be/j82hDWQ9l3o
Attached Program and Screen Script
1 Attachment(s)
Re: G43 G49 status Led and Toggle
Hi dirtdigger257,
You could use 2 Threads but each extra Thread increases the time between Time Slices so it is better to use less Threads where possible.
Please try the code below (and attached) that is written in a non-blocking manner so your MPG should always be serviced using a single loop.
Code:
#include "KMotionDef.h"
#define TMP 10 // which spare persist to use to transfer data
#include "KflopToKMotionCNCFunctions.c"
void ServiceToolOffsetMode(void);
main()
{
for (;;) // forever loop
{
ServiceToolOffsetMode();
}
}
#define STATUSBIT 46
// periodically set Virtual Bit based on Tool Table Index
// keeps track of state of sequence to always return immediately
void ServiceToolOffsetMode(void)
{
static BOOL WaitingForResponse = FALSE;
static double LastTime = 0;
int HWORD;
if (WaitingForResponse) // Waiting for a response from the PC?
{
if (persist.UserData[PC_COMM_PERSIST] <= 0) // Has PC Responded??
{
HWORD = persist.UserData[TMP + 2]; // Get Tool H Word
SetStateBit(STATUSBIT, HWORD != -1); // -1 indicates no active offset
LastTime = Time_sec();
WaitingForResponse = FALSE;
}
}
else
{
if (Time_sec() > LastTime + 0.3) // only request periodically
{
DoPCIntNoWait(PC_COMM_GET_MISC_SETTINGS, TMP); // Request settings from PC
WaitingForResponse = TRUE; // Remember we are waiting for a response
}
}
}
Re: G43 G49 status Led and Toggle
Quote:
Originally Posted by
TomKerekes
Hi dirtdigger257,
You could use 2 Threads but each extra Thread increases the time between Time Slices so it is better to use less Threads where possible.
Please try the code below (and attached) that is written in a non-blocking manner so your MPG should always be serviced using a single loop.
Code:
#include "KMotionDef.h"
#define TMP 10 // which spare persist to use to transfer data
#include "KflopToKMotionCNCFunctions.c"
void ServiceToolOffsetMode(void);
main()
{
for (;;) // forever loop
{
ServiceToolOffsetMode();
}
}
#define STATUSBIT 46
// periodically set Virtual Bit based on Tool Table Index
// keeps track of state of sequence to always return immediately
void ServiceToolOffsetMode(void)
{
static BOOL WaitingForResponse = FALSE;
static double LastTime = 0;
int HWORD;
if (WaitingForResponse) // Waiting for a response from the PC?
{
if (persist.UserData[PC_COMM_PERSIST] <= 0) // Has PC Responded??
{
HWORD = persist.UserData[TMP + 2]; // Get Tool H Word
SetStateBit(STATUSBIT, HWORD != -1); // -1 indicates no active offset
LastTime = Time_sec();
WaitingForResponse = FALSE;
}
}
else
{
if (Time_sec() > LastTime + 0.3) // only request periodically
{
DoPCIntNoWait(PC_COMM_GET_MISC_SETTINGS, TMP); // Request settings from PC
WaitingForResponse = TRUE; // Remember we are waiting for a response
}
}
}
Hi tom,
Thanks for your reply, i am having some problem while running the above c program,
The issue is When i am starting KmotionCNC.exe first time then it runs fine.
But when i am giving G49 and closing KmotionCNC.exe
After running the KmotionCNC.exe again i am getting LED On state but , i turned it off while closing KmotionCNC.exe
I want this whole state off or on untill unless i give G43 H1001 or G43.4 H1001 or G49.
Closing KmotionCNC should not reset it.
3 Attachment(s)
Re: G43 G49 status Led and Toggle
Hi Amit,
The LED is displaying the true state of the Interpreter.
If the Tool Setup Options: Tool Length/Offset Immediately and M6 on Tool Table Changes
Attachment 427158
are selected, then when KMotionCNC starts up the Tool Compensation is enabled and set to match the selected tool displayed on the screen:
Attachment 427160
If those options are not selected then the Settings File parameter slot_for_length_offset
Attachment 427162
can be used to initialize which Tool is in use or -1 for not applied.
If no setting is included the Interpreter length offset is initialized to -1 for none.
Quote:
I want this whole state off or on untill unless i give G43 H1001 or G43.4 H1001 or G49.
Disable the Options and set the Settings file parameter slot_for_length_offset to -1 to initialize the Interpreter with no Length Compensation in effect.
Re: G43 G49 status Led and Toggle
Quote:
Originally Posted by
TomKerekes
Hi tom,
Thanks for your reply,
I tried the above method for the tool offset led toggle, i am facing one problem that,
When i am turning power on the kflop board its remembering its last state wheather it was turned on or off last time.
But i don't want to remember that, i just want after every power recycle G43 G49, LED should be initially off.and i have to manually turn it ON on every power off and on Sequence.
Waiting for your kind reply.
Re: G43 G49 status Led and Toggle
Hi Amit,
Please be more specific what you are doing.