Author Topic: Needing help with Wizards  (Read 2932 times)

0 Members and 1 Guest are viewing this topic.

Offline simpson36

  • Active Member
  • Posts: 1,374
    • View Profile
Needing help with Wizards
« 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.

Offline simpson36

  • Active Member
  • Posts: 1,374
    • View Profile
Needing help with Wizards
« Reply #1 on: March 01, 2015, 06:42:57 AM »
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.


Offline MachMotion Development Team

  • Active Member
  • Posts: 55
    • View Profile
    • MachMotion
Needing help with Wizards
« Reply #2 on: March 01, 2015, 09:38:07 AM »
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
Andrew
MachMotion

Offline simpson36

  • Active Member
  • Posts: 1,374
    • View Profile
Needing help with Wizards
« Reply #3 on: March 01, 2015, 06:07:02 PM »
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


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.

Offline simpson36

  • Active Member
  • Posts: 1,374
    • View Profile
Needing help with Wizards
« Reply #4 on: March 01, 2015, 06:12:32 PM »
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?

Offline dude1

  • Active Member
  • Posts: 1,253
    • View Profile
Needing help with Wizards
« Reply #5 on: March 01, 2015, 06:30:50 PM »

Offline Chaoticone

  • Administrator
  • *
  • Posts: 5,460
  • Precision Chaos
    • View Profile
Needing help with Wizards
« Reply #6 on: March 02, 2015, 10:19:16 AM »
High road taken.  ;)
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!

Offline Bodini

  • Active Member
  • Posts: 216
    • View Profile
Needing help with Wizards
« Reply #7 on: March 02, 2015, 12:26:13 PM »
The bolt hole wizard included in mach4 shows how to write to the ini file, if I remember correctly.

Offline simpson36

  • Active Member
  • Posts: 1,374
    • View Profile
Re: Needing help with Wizards
« Reply #8 on: March 04, 2015, 03:48:45 AM »
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.


Offline Bodini

  • Active Member
  • Posts: 216
    • View Profile
Re: Needing help with Wizards
« Reply #9 on: March 04, 2015, 04:38:23 PM »
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.