Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: simpson36 on March 01, 2015, 06:19:54 AM
-
Hello 'Screen Set Ideas' thread!
I am porting a 4th axis motor controller over to MACH4 from MACH3 and the last task in this is to write a Lua script to collect operational parameters from the user and pass them (over TCP Modbus) to the controller where they are stored (originally in EEPROM, now on an SD card).
But first, let me take just a minute here for some well deserved kudos. When I last visited MACH4 last summer (on release of the demo), it was a big deal to get Modbus going and add a button here and there on the screen. I have only had a few minutes to peruse this thread, but the level of work being done is just astonishing to see. I have noted a couple of 'non programmers' who are now doing high level programming and displaying truly impressive accomplishments here. ;D
OK, so enough of that. I've mucked up this post now, so I will start another with some details of my task and some questions to get me started in the right direction.
-
I need a program (presumably a Lua script) that will collect data from a user, 'disassemble' the floats for xfer over Modbus and send the data to a devise over Modbus TCP. This process is already working on the MACH3 TCP Modbus version of the controller and it is a matter of duplicating the functionality in MACH4 . . and hopefully also streamlining the process as well.
The 'nuts and bolts' of breaking up the floats and sending them to the controller is no problem. What I am seeking is some advice and direction as to the best method in MACH4/Lua to make a single input screen to collect a series of integer and Floating point numbers from a user.
Attached is an image of my 'configurator' (a windows program written in C#). I would like to do something similar inside MACH4. This program is now replaced in the TCP Modbus version of the controller and parameters are collected one at a time in a series of clumsy VM scripts. I'm not looking for someone to write the script for me of for 'Lua 101 over the Internet'. What I want it just to be pointed in the right direction so that my efforts are not wasted going down the wrong road.
So to get off on the right track, my specific questions are:
1) What is the best method to use to create a single input screen for a mixture of integers and floats (no text).
* If possible, it would be nice to be able to edit any and all of the fields prior so doing a single 'save'.
2) Presumably, this screen would need an array to store the values in.
* What would be the best storage mechanism for this? Registers? Variables? Which ones?
* IF it was desirable to have MACH4 retain these parameters, how best to do that?
I know that MACH stores some data in the .ini file, but I don't know which would be best to use or why.
-
Hi simpson36,
I would use wxFormBuilder to create the dialog, don't forget to add the code to show the dialog after you create it. Example: MyDialog:Show() or MyDialog:ShowModal(). I would save all your setting to the ini file in mach using the ini API calls that are built in. I like saving and reading everything to the ini as a string and then converting it to a number after you read it (use "tostring()" or "tonumber()"). I don't know what your going to do with this project, but if you need mach to write these settings to modbus every time mach starts up you should make a 2 functions, one that reads the settings from the dialog and saves them to the ini, and a second function to read from the ini and write them to the modbus registers.
Good Luck,
Andrew with MachMotion
-
Hi simpson36,
I don't know what your going to do with this project,
This is the 4th axis motor controller. Note the date of the video upload. The device is much more powerful and capable in it's current version. The project is porting it over to MACH4 interfaced with TCP Modbus
https://www.youtube.com/watch?v=vBLuF_F2_qs (https://www.youtube.com/watch?v=vBLuF_F2_qs)
but if you need mach to write these settings to modbus every time mach starts up you should make a 2 functions, one that reads the settings from the dialog and saves them to the ini, and a second function to read from the ini and write them to the modbus registers.
Good Luck,
Andrew with MachMotion
The parameters are stored in the controller. They are used to calculate the correct frequency for the step signal to produce the correct Spindle RPM. The only reason to keep them in MACH4 is to show the user what the current settings are without needing to read them out of the controller.
i.e. the user prompt reads: "Encoder Resolution is currently 266144, enter new value or Zero to keep"
Still a good tip though, thanks. Can you be more specific about storing data in the .ini? It would need to be registers that MACH4 already stores, yes? You can't just arbitrarily write data into the .ini, I would assume.
-
Hi simpson36,
I would use wxFormBuilder to create the dialog, . . . . .
Andrew with MachMotion
I have the Lua distributions up to the newest 5.3 and whatever comes with MACH4. wxFormBuilder is not present. Where would I acquire this tool?
-
http://sourceforge.net/projects/wxformbuilder/
-
High road taken. ;)
-
The bolt hole wizard included in mach4 shows how to write to the ini file, if I remember correctly.
-
Thanks Brett 8)
Bodini,
Before I was informed (no pun intended) about wxFormbuilder, I started with the BoltCircle sample wizard. I was pretty far along unraveling that beast when I got wxFormbuilder to play with. It is apparent that it was used to create some of the wizards and indeed the BoltCircle has a function in it to write data to the .ini file. For the time being, I sidestepped that whole operation, but left the function in the code in case I want to go back and tinker with that.
For the wizard I was creating, only a small amount of the code was screen ops (plagiarized from the BoltCircle Wizard, so I pushed on and finished the thing 'manually'. Wx *seems* to have its own library as the commands and syntax are different from straight Lua. It is a challenge to start with an existing wizard and reverse engineer the structure.
However, I did complete my little utility. Screen attached.
-
the BoltCircle has a function in it to write data to the .ini file. For the time being, I sidestepped that whole operation, but left the function in the code in case I want to go back and tinker with that.
I also decided to side-step it. It's another can of worms and if I need it, I'll open it. ;)
As you may have already found out, you can pre-populate your wx.wxTextCtrl fields by setting something in the "value" box in wxFormBuilder. I found this to be an acceptable compromise.
Wx *seems* to have its own library as the commands and syntax are different from straight Lua. It is a challenge to start with an existing wizard and reverse engineer the structure.
I got a book about a year ago called "Cross-Platform GUI Programming with wxWidgets" by Julian Smart (and others) from Amazon for about $10 used. It's not a good book, but the info is in there. It has helped me, but dang they made it difficult to use (It uses lengthy paragraphs instead of bullet points and bold letters. ::) ::) ::) .)
Also, I have a text file with a list of wxLua functions that I thought I got on this forum but I'll be darned if I can find it again. I will attach it to this message.
Good job on the wizard.
-
That list was posted up a while back by Craig.
BTW: If you look in the Mach4 Toolbox, there are some wxWizard templates, as well as some controls examples,
that can help you get your head around the wxLua stuff.
Scott
-
The WxFormbuilder gives you about everything you need EXCEPT an EASY way to move things around . Wish we had a Screen Builder for Wizards like the MaCH4 Screen builder. OR hopefully someone in OZ will make a better WxBuilder that you can easily move things around.
Just a thought, (;-) TP
-
I also decided to side-step it. It's another can of worms and if I need it, I'll open it. ;)
As you may have already found out, you can pre-populate your wx.wxTextCtrl fields by setting something in the "value" box in wxFormBuilder. I found this to be an acceptable compromise.
I have this figured out and working. It's not that bad of a process. You can pre-populate with the stored values (or strings) which is what I wanted to do. Sounds like you didn't want to fool with it, so I won't bother to post it. If you decide otherwise, just give me a holler.
Thanks for the wxfunction listing!