Hi Dan,
I'm currently on a business trip in Brussels and won't be back home before Thursday, so I can't try it out. Also, as I said before, why would anyone with a real Modbus VFD would be interested in using this? The macro I am using works fine, it requires less lines and together with the built-in functions in UCCNC it is in my opinion a better solution. Never the less, I will try this one out for you, but can't promise to spend time on it if it is not working. ...just got my food in the restaurant I am in... will get back later.
Edit:
OK, now I am back in my hotel...
I don't mean to be rude, just that I see no point in this for anyone else except for those who have non-Modbus VFDs. Compare the macro I have, with the one you have and need:
Code:
// ----------------------------------------------------------------------------------------------------
//
// M300 Macro for Set spindle speed via Modbus
//
// When this macro is called it will check the Set Spindle Speed and the Speindle Speed Override DRO
// and will calculate the matching frequency. This is set in Modbus register which is sent to the VFD.
//
// This macro works with any VFD as long as the VFD calculates the frequency using the formula:
//
// f = RPM / 0.6
//
// If a diifferent formula is used it can easily be changed in the last line.
//
// ----------------------------------------------------------------------------------------------------
//
// Constants
//
ushort SSetDRO = 869; // Defined by UCCNC
ushort SspeedOverrideDRO = 233; // Defined by UCCNC
ushort VFDFrequencyRegister = 1; // User definable within the limits of UCCNC Modbus registers
ushort MaximumRPM = 24000; // User definable within the limits of VFD and the motor
//
// Variables
//
string SspeedOverride;
int IndexOfPercentSign;
string SSpeedOverride;
double RealRPM;
//
// Program starts here
//
// The first two lines need to be added if the macro is run as a macro loop in Windows computers
// which use something else than US English floating point and number representation.
//
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US", false);
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US", false);
//
// ----------------------------------------------------------------------------------------------------
//
//
// Get the string of Spindle speed override percent, strip off the '%' sign.
//
SspeedOverride = AS3.Getfield(SspeedOverrideDRO);
IndexOfPercentSign = SspeedOverride.IndexOf('%');
//
// Necessary to check for zero to prevent the macro from crashing when UCCNC is started,
// because the macro starts before UCCNC initialized the string. The code will only be executed
// if UCCNC is ready for running.
//
if (IndexOfPercentSign > 0) // IndexOfPercentSign is zero only if the string is not initialized
{
SSpeedOverride = SspeedOverride.Substring(0, IndexOfPercentSign);
//
// Calculate the real RPM by multiplying the set spindle RPM with the override percent.
//
RealRPM = ( AS3.Getfielddouble(SSetDRO) * ( (double) Convert.ToDouble (SSpeedOverride) / 100));
if (RealRPM > MaximumRPM)
{
RealRPM = MaximumRPM; // Force maximum RPM to prevent exception
}
//
// Calculate the matching RPM frequency and send the value to UCCNC Modbus register.
//
exec.SetModbusregister(VFDFrequencyRegister, (ushort) Convert.ToUInt16(RealRPM / 0.6));
}
//
// ------------------------------------------------------------------------------------------------------
//
// End of program
I made some small changes on my way to Brussels, so the above code is not the one I tested last night, but it is not shorter than the one I have at home, I just tidied up a little. It is only 10 lines of code, including the two you don't need and an additional two testing the maximum speed, if you remove all the comment lines. OK, it is only for handling the spindle speed, but the CW/CCW/OFF takes only another six lines or so, if it would be added to the same code. I have a different macro for that, because I think it is better to keep them separate, but it could easily be added to this and the code would still be pretty clear and understandable. I don't have the code for that here with me, so I can't show it now, but it sure is simpler and more straight forward than yours.