Huanyang VFD Macro/ Plugin

Page 1 of 29 123411 ... LastLast
Results 1 to 20 of 568

Thread: Huanyang VFD Macro/ Plugin

  1. #1
    Member
    Join Date
    Mar 2010
    Location
    America
    Posts
    813
    Downloads
    0
    Uploads
    0

    Default Huanyang VFD Macro/ Plugin

    Hello Everyone,

    If you were using a Huanyang plugin for Mach3 to control VFD/spinde or using Spindle Talker than this macro's for you. I didn't add actual RPM yet but I will.

    Only set up in UCCNC is in configuration, set spindle velocity min to 8000(rpm) and max to 24000(rpm). Any setting below it wont set frequency. Go to Macroloop set up and add M1092 with autorun.

    If you used HY plugin you should already have these settings for HY VFD but here's a reminder.

    PD163 is set to 1
    PD164 is set to 1
    PD165 is set to 3



    Similar Threads:
    Attached Files Attached Files
    Last edited by ger21; 04-16-2017 at 12:43 PM.


  2. #2
    Member
    Join Date
    Mar 2010
    Location
    America
    Posts
    813
    Downloads
    0
    Uploads
    0

    Default Re: Hunayang VFD Macro

    Sorry Mods I meant to post this in macro sharing, didn't mean to make a second thread.



  3. #3
    Member
    Join Date
    Apr 2013
    Location
    Sweden
    Posts
    1899
    Downloads
    2
    Uploads
    0

    Default Re: Hunayang VFD Macro

    It's a good start if it works, but... hard coding checksum and RPM? Why? Also, why all the Open/Close ports? Oh... I see teh reason...

    Proposal of improvements:

    Make the port number a variable at the top. Having to change a number of "COM 1" in the code is not very nice from a programmer perspective.

    Open port should be done once at the beginning and close at the end, preferably when you start UCCNC, but at least at the start/end of macro loop, not every time you enter an if state. If you are not locking the port during start-up some other software might grab the resource. Maybe that's nor realistic normally in a PC running UCCNC, but it is a possible source of issue, so generally you want to lock all the ports you need as long as UCCNC (or Mach3) is running and only open/close ports which you want to let other resources to use, shared with you, like for example a USB hard disk. I suppose this is not the case with your VFD, you don't want to share that with any other software, in case that software would grab the port between your open/close, so it is best to lock (open) when you start UCCNC. You don't have to worry about closing the port, when you close UCCNC the port will (should) be closed and released.

    Why fix the RPM? Isn't it better to read the RPM field, convert to frequency and out of the converted value make up the bytes to send plus calculate the checksum? The checksum calculation is definitely working in HY and is according to Modbus standard.

    If you think the above is too complicated you should increase the number of RPM and even add 6000. Most high speed spindles have a minimum RPM of 6000, so everything above 1 RPM and below 79999 RPM should set and send 6000RPM to the VFD.

    Comparing for an interval of values is normally done through OR statements, not through two IF statements. Try...

    if ((AS3.Getfielddouble(869) = 8000) | (AS3.Getfielddouble(869) < 10000) )

    ...instead of using...

    if (AS3.Getfielddouble(869) >= 8000 )

    if (AS3.Getfielddouble(869) <= 9999 )


    ...which is not a very nice way of doing the same and makes the code look "messier".

    The last IF statement is unnecessary because if all the others above are failed then it is obvious that the RPM should be set to 24000. Also, if you want to use the statement...

    if (AS3.Getfielddouble(869) == 24000 )

    ...then it would be better to write...

    if (AS3.Getfielddouble(869) > 23999 )

    ...since it covers all cases above 23999, even the errors of trying to set higher than 24000RPM.

    Never the less, I am glad that you got it working and the above proposals are just proposals and my opinion. The most important in my opinion is to grab the port and don't let it go inside the macro loop, but I would grab it during the startup of UCCNC.

    In my opinion, it is also a good idea to add comments and a header with some explanation about what the code is doing and how it is working. I don't write code without comments because that's causing future extra work and comments also allow for better re-usability or code improvements/modifications. I also like indenting, especially if there are a lot of loops and statements. It is difficult to find errors and visualize what the code is doing, what belongs to which part if it is written like a book, strait flow of text down the page. In this case it is an important note in the header that the "COM1 " is fixed and may not suit everybody and that it must be changed in the code before the code is used with something else than COM 1. You can say that it's obvious, but it is a good idea to document the major things to think about in the code.

    Last edited by A_Camera; 11-08-2016 at 06:38 AM.


  4. #4
    Member
    Join Date
    Mar 2010
    Location
    America
    Posts
    813
    Downloads
    0
    Uploads
    0

    Default Re: Hunayang VFD Macro

    Hi A_C,

    Been away for the past 2 weeks with no comp access so sorry for the late response.

    The Macro does work well and thrilled that its now possible to use UCCNC with it controlling spindle. I wasn't really happy with the way the set frequency is written for the only reason that its making the macro loop very long, I would prefer a formula but with the lack of experience in macro writing that's to advanced for me write now, I will tweak as I learn.

    Is there any limit or disadvantage in size of a macro ?

    Thanks for your tips on improvement and will certainly try, that's the sort of response I was hoping to get here. I quickly tried your comparison suggestion but received a script error in UCCNC.

    Replaced

    if (AS3.Getfielddouble(869) >= 8000 )

    if (AS3.Getfielddouble(869) <= 9999 )




    with

    if ((AS3.Getfielddouble(869) = 8000) | (AS3.Getfielddouble(869) < 10000) )


    Did I do something wrong?

    Thanks for your help,
    Dan



  5. #5
    Member
    Join Date
    Jun 2015
    Location
    Sweden
    Posts
    943
    Downloads
    0
    Uploads
    0

    Default Re: Hunayang VFD Macro

    Comparion for equal value is == and not =.in C#.
    = is giving value and not comparion.
    This is definietly wrong: AS3.Getfielddouble(869) = 8000 in your if statement.
    OR is || and not | , if I recall | is bitwise or ... probably, not sure.

    Should be OK like this: if ((AS3.Getfielddouble(869) == 8000) || (AS3.Getfielddouble(869) < 10000) )



  6. #6
    Member
    Join Date
    Mar 2010
    Location
    America
    Posts
    813
    Downloads
    0
    Uploads
    0

    Default Re: Hunayang VFD Macro

    Thank you OlfCNC that did it.



  7. #7
    Member vmax549's Avatar
    Join Date
    Oct 2005
    Location
    Lady Lake
    Posts
    1145
    Downloads
    3
    Uploads
    0

    Default Re: Hunayang VFD Macro

    HIYA Dan. I have another piece of the puzzle for you to test (;-)

    (;-) TP



  8. #8
    Member
    Join Date
    Mar 2010
    Location
    America
    Posts
    813
    Downloads
    0
    Uploads
    0

    Default Re: Hunayang VFD Macro

    Hi TP,

    I just tested the macro you sent last week and works great! Right now I'm trying to send it to serial port instead of message box, than the last thing to overcome is the checksum. Like I mentioned in email the HY manual supply's code in C language to accomplish this. You already succeeded in accomplishing the hardiest part.

    Can't thank you enough for all your help,
    Dan



  9. #9
    Member
    Join Date
    Mar 2010
    Location
    America
    Posts
    813
    Downloads
    0
    Uploads
    0

    Default Re: Hunayang VFD Macro

    Thanks to Vmax549 I aborted hard coding the RPM and checksum in macro since he wrote one that gets Sset ,converts to Hzs and calculates the checksum. Works Great!!! I will continue to use and test and than will post for anyone who's interested.



  10. #10
    Member
    Join Date
    Apr 2013
    Location
    Sweden
    Posts
    1899
    Downloads
    2
    Uploads
    0

    Default Re: Hunayang VFD Macro

    Quote Originally Posted by OlfCNC View Post
    Comparion for equal value is == and not =.in C#.
    = is giving value and not comparion.
    This is definietly wrong: AS3.Getfielddouble(869) = 8000 in your if statement.
    OR is || and not | , if I recall | is bitwise or ... probably, not sure.

    Should be OK like this: if ((AS3.Getfielddouble(869) == 8000) || (AS3.Getfielddouble(869) < 10000) )
    Yes and no.

    Yes of course, it should be == not just =
    No for || vs. | but if you use || or | in this case makes no difference. If you use || then if the first evaluation is true the second will not be executed. Some times you want to make sure (especially in checking for intervals) that both evaluations are executed, even if the first evaluation is true. In other words, in my opinion it is better to use | here because what we are doing is checking for intervals. Of course, this is now irrelevant since Dan can now read and set any spindle speed and don't have to look for intervals and set it step wise.

    https://www.youtube.com/c/AdaptingCamera/videos
    https://adapting-camera.blogspot.com


  11. #11
    Member
    Join Date
    Apr 2013
    Location
    Sweden
    Posts
    1899
    Downloads
    2
    Uploads
    0

    Default Re: Hunayang VFD Macro

    Quote Originally Posted by Dan911 View Post
    Hi A_C,

    Been away for the past 2 weeks with no comp access so sorry for the late response.
    Don't worry, no big deal, of course priorities must be IRL and not here. I just assumed that everything is fine so life goes on.

    Quote Originally Posted by Dan911 View Post
    The Macro does work well and thrilled that its now possible to use UCCNC with it controlling spindle. I wasn't really happy with the way the set frequency is written for the only reason that its making the macro loop very long, I would prefer a formula but with the lack of experience in macro writing that's to advanced for me write now, I will tweak as I learn.

    Is there any limit or disadvantage in size of a macro ?
    No, it actually makes no difference in this case, and it is probably more efficient than a formula because because a formula needs calculations and comparisons are very fast. It's just nicer with a formula, not necessarily more efficient. Some times it is better to write a longer program than a more condensed one, since the longer one may be easier to debug and figure out where it goes wrong. Of course, there are no general rules, except that a far too condensed code can be extremely difficult to read if it is a complex code.
    Quote Originally Posted by Dan911 View Post
    Thanks for your tips on improvement and will certainly try, that's the sort of response I was hoping to get here. I quickly tried your comparison suggestion but received a script error in UCCNC.

    Replaced

    if (AS3.Getfielddouble(869) >= 8000 )

    if (AS3.Getfielddouble(869) <= 9999 )

    with

    if ((AS3.Getfielddouble(869) = 8000) | (AS3.Getfielddouble(869) < 10000) )

    Did I do something wrong?
    No, I did. It should be:

    if ((AS3.Getfielddouble(869) == 8000) | (AS3.Getfielddouble(869) < 10000) )

    The above should work, but you can also do like Olf suggests:

    if ((AS3.Getfielddouble(869) == 8000) || (AS3.Getfielddouble(869) < 10000) )

    Quote Originally Posted by Dan911 View Post
    Thanks for your help,
    Dan
    You're welcome. Glad that it is working, especially now with the better flexibility and calculated values.

    https://www.youtube.com/c/AdaptingCamera/videos
    https://adapting-camera.blogspot.com


  12. #12
    Member
    Join Date
    Mar 2010
    Location
    America
    Posts
    813
    Downloads
    0
    Uploads
    0

    Default Re: Hunayang VFD Macro

    I guess its not as many people as I thought using the HY plugin and spindle talker and would find this macro of use. The Macro works great, and my last test will be how UCCNC handles large files. This is why I found UCCNC of interest
    in the first place, Mach3 was buggy when it came to them.

    Here's the macro for anyone who wants to give it a try.

    __________________________________________________ __________________________________________________ __________________________________________________ _____________


    // Macro to send Modbus string with CRC added
    // Get Sset and convert to Hzs **********************************



    if (AS3.Getfielddouble(869) >= 8000)
    {
    double Sspeed = AS3.Getfielddouble(869);
    string Over = AS3.Getfield(233);
    int index = Over.IndexOf('%');
    string sub;
    if (index >= 0)
    {
    sub = Over.Substring(0, index);
    double Sover = Convert.ToDouble (sub) ;
    double Sact = (Sspeed * (Sover/100));
    double Shzs = ( Sspeed* (Sover/100));
    Shzs =( ( Shzs *.016667)*100);
    Shzs = Math.Floor(Shzs);
    int Shzs2 = Convert.ToInt32(Shzs);
    string str = Shzs2.ToString("X");
    string full = str ;
    string part1 = ( "0x" + full.Substring(0, 2));
    int Part1 = Convert.ToInt32(part1, 16);
    string part2 = ("0x" + full.Substring(2, 2));
    int Part2 = Convert.ToInt32(part2, 16);
    System.IO.Ports.SerialPort spSerial = new System.IO.Ports.SerialPort();
    spSerial.PortName = "COM1";
    spSerial.BaudRate = 9600;
    spSerial.DataBits = 8;
    spSerial.StopBits = System.IO.Ports.StopBits.One;
    spSerial.Parity = System.IO.Ports.Parity.None;
    spSerial.Open();

    int[] intSend = new int[8];
    intSend[0] = 0x01; // ID of slave device
    intSend[1] = 0x05; // code of the command
    intSend[2] = 0x03; // Start of Address
    intSend[3] = Part1; // PART1 RPM
    intSend[4] = Part2; // PART2 RPM
    intSend[5] = 0x00; // END of string
    int int_crc = 0xFFFF;
    int int_lsb;
    int int_crc_byte_a, int_crc_byte_b;
    for (int int_i = 0; int_i < intSend.Length - 2; int_i++)
    {
    int_crc = int_crc ^ intSend[int_i];
    for (int int_j = 0; int_j < 8; int_j++)
    {
    int_lsb = int_crc & 0x0001; // Mask of LSB
    int_crc = int_crc >> 1;
    int_crc = int_crc & 0x7FFF;
    if (int_lsb == 1) int_crc = int_crc ^ 0xA001;

    }
    }

    int_crc_byte_a = int_crc & 0x00FF;
    int_crc_byte_b = (int_crc >> 8) & 0x00FF;

    byte[] bytSend = new byte[8];
    byte bytTransfer;
    for (int i = 0; i <= intSend.Length - 2; i++)
    {
    bytSend[i] = (byte)intSend[i];
    }

    bytTransfer = (byte)int_crc_byte_a;
    bytSend[intSend.Length - 2] = bytTransfer;
    bytTransfer = (byte)int_crc_byte_b;
    bytSend[intSend.Length - 1] = bytTransfer;
    spSerial.Write(bytSend, 0, bytSend.Length);
    spSerial.Close();

    }
    }


    // EOF


    if ( AS3.GetLED(50) == true ) // IF CW LED is active

    {

    System.IO.Ports.SerialPort spSerial = new System.IO.Ports.SerialPort();
    spSerial.PortName = "COM1";
    spSerial.BaudRate = 9600;
    spSerial.DataBits = 8;
    spSerial.StopBits = System.IO.Ports.StopBits.One;
    spSerial.Parity = System.IO.Ports.Parity.None;
    spSerial.Open();
    byte[] bytestosend = { 0x01, 0x3, 0x01, 0x01, 0x31, 0x88 };
    spSerial.Write(bytestosend, 0, bytestosend.Length);
    spSerial.Close();

    }

    else



    if ( AS3.GetLED(51) == true ) // IF CCW LED is active

    {
    System.IO.Ports.SerialPort spSerial = new System.IO.Ports.SerialPort();
    spSerial.PortName = "COM1";
    spSerial.BaudRate = 9600;
    spSerial.DataBits = 8;
    spSerial.StopBits = System.IO.Ports.StopBits.One;
    spSerial.Parity = System.IO.Ports.Parity.None;
    spSerial.Open();
    byte[] bytestosend = { 0x01, 0x3, 0x01, 0x011, 0x30, 0x44 };
    spSerial.Write(bytestosend, 0, bytestosend.Length);
    spSerial.Close();
    }

    else


    // Shuts off spindle

    {

    System.IO.Ports.SerialPort spSerial = new System.IO.Ports.SerialPort();
    spSerial.PortName = "COM1";
    spSerial.BaudRate = 9600;
    spSerial.DataBits = 8;
    spSerial.StopBits = System.IO.Ports.StopBits.One;
    spSerial.Parity = System.IO.Ports.Parity.None;
    spSerial.Open();
    byte[] bytestosend = { 0x01, 0x3, 0x01, 0x08, 0xf1, 0x8e };
    spSerial.Write(bytestosend, 0, bytestosend.Length);
    spSerial.Close();
    }



  13. #13
    Member
    Join Date
    Apr 2013
    Location
    Sweden
    Posts
    1899
    Downloads
    2
    Uploads
    0

    Default Re: Hunayang VFD Macro

    Dan,

    Thanks for sharing this and it's great that it is working, however there is at least one thing I don't understand in this macro. "Sact" is not seem to be used so why is it there at all? Or, is this not the whole macro?

    Like I mentioned before, without indentions and comments it is a bit difficult to understand and looks overcomplicated and incomplete. However, if you share this with the intentions of others might be interested in using it, it would be better if shared fully, or at least given some explanations.

    Last edited by A_Camera; 11-19-2016 at 02:24 PM.
    https://www.youtube.com/c/AdaptingCamera/videos
    https://adapting-camera.blogspot.com


  14. #14
    Member
    Join Date
    Mar 2010
    Location
    America
    Posts
    813
    Downloads
    0
    Uploads
    0

    Default Re: Hunayang VFD Macro

    Quote Originally Posted by A_Camera View Post
    Dan,

    Thanks for sharing this and it's great that it is working, however there is at least one thing I don't understand in this macro. "Sact" is not seem to be used so why is it there at all? Or, is this not the whole macro?

    Like I mentioned before, without indentions and comments it is a bit difficult to understand and looks overcomplicated and incomplete. However, if you share this with the intentions of others might be interested in using it, it would be better if shared fully, or at least given some explanations.
    Hey A_C

    First off let me start by writing I can take No credit for the the Sset and checksum conversion, Vmax549 generously written it for me, he was also a huge help in the rest. I did post the full macro and I thoroughly tested with gcode, MDI, buttons and worked flawless without a glitch for hours before posting.

    Good observation with the Sact, I removed it and it didn't take any effect. All my testing was done with it though, maybe TP will post why its there. There is some tweaking I would like to do, but the macro is perfectly functional as is. If you or anyone have any questions or see ways to tweak please post, that's why I posted macro instead of linking download.

    Dan



  15. #15
    Member vmax549's Avatar
    Join Date
    Oct 2005
    Location
    Lady Lake
    Posts
    1145
    Downloads
    3
    Uploads
    0

    Default Re: Hunayang VFD Macro

    (;-) DAN can take a lot of credit as I only feed him parts and pieces as I was able to make them work. He did a GREAT deal of work in testing as I do not have one of those VFD here to test with.

    Teh Sact was a duplicate and it can be removed . I started in one direction then changed teh function and i never went far enough back to clean it all out.

    NOW can it be made more efficent ?? I am SURE it can. Teh idea was to get it all working dependably then take teh code back apart and streamline teh process if possible. BUT the old addage holds true IF it is not broken don't try to fix it as you might break it not fix it.

    (;-) TP



  16. #16
    Member ger21's Avatar
    Join Date
    Mar 2003
    Location
    Shelby Township
    Posts
    35538
    Downloads
    1
    Uploads
    0

    Default Re: Hunayang VFD Macro

    I made this a sticky.
    I'll probably be getting a Huanyang at some point, as I can get two, and have a spare for less than a Hitachi.

    Gerry

    UCCNC 2017 Screenset
    [URL]http://www.thecncwoodworker.com/2017.html[/URL]

    Mach3 2010 Screenset
    [URL]http://www.thecncwoodworker.com/2010.html[/URL]

    JointCAM - CNC Dovetails & Box Joints
    [URL]http://www.g-forcecnc.com/jointcam.html[/URL]

    (Note: The opinions expressed in this post are my own and are not necessarily those of CNCzone and its management)


  17. #17
    Registered jfong's Avatar
    Join Date
    Apr 2004
    Posts
    733
    Downloads
    3
    Uploads
    0

    Default Re: Hunayang VFD Macro

    I appreciate all the hard work. I've been pretty busy with upcoming holidays and such that I haven't used my cnc in a few weeks. When I get a chance, I will be testing out the macro and update everyone. Thanks Dan and everyone involved. Much appreciated for sure.



  18. #18
    Member
    Join Date
    Mar 2010
    Location
    America
    Posts
    813
    Downloads
    0
    Uploads
    0

    Default Re: Hunayang VFD Macro

    Hey Gerry,

    I hope I don't jink myself by posting this, but had my HY vfd for over 2 years with at least and average of and hour a week of use with no problems and still going. Also, when you step up from a 2.2kw and only 1 phase available your choices of VFD becomes limited.

    I certainly have no complaints.

    Dan



  19. #19
    Member ger21's Avatar
    Join Date
    Mar 2003
    Location
    Shelby Township
    Posts
    35538
    Downloads
    1
    Uploads
    0

    Default Re: Hunayang VFD Macro

    Thanks Dan. I already have the spindles, just need the VFD.
    What are you using to go from the PC to the VFD? A USB to RS-485 or something like that?

    Gerry

    UCCNC 2017 Screenset
    [URL]http://www.thecncwoodworker.com/2017.html[/URL]

    Mach3 2010 Screenset
    [URL]http://www.thecncwoodworker.com/2010.html[/URL]

    JointCAM - CNC Dovetails & Box Joints
    [URL]http://www.g-forcecnc.com/jointcam.html[/URL]

    (Note: The opinions expressed in this post are my own and are not necessarily those of CNCzone and its management)


  20. #20
    Member
    Join Date
    Mar 2010
    Location
    America
    Posts
    813
    Downloads
    0
    Uploads
    0

    Default Re: Hunayang VFD Macro

    RS232 to RS485

    Bought it on ebay over 2 years ago for $5.00 free delivery...lol



    Huanyang VFD Macro/ Plugin-rs-485_jpg_3-jpg



Page 1 of 29 123411 ... LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


About CNCzone.com

    We are the largest and most active discussion forum for manufacturing industry. The site is 100% free to join and use, so join today!

Follow us on


Our Brands

Huanyang VFD Macro/ Plugin

Huanyang VFD Macro/ Plugin