Saving parameters after shut down

More
14 May 2013 01:30 #34025 by mariusl
ArcEye, cant get this parameter file of yours to work. It compiles happily but does bugger all further. I cant seem to get any data from any of the pins. Even if I hard code it. It seems that it does not fall into the while loop. Maybe something with the signal stuff?

Regards
Marius


www.bluearccnc.com

Please Log in or Create an account to join the conversation.

More
14 May 2013 02:08 #34026 by ArcEye
Hi

I didn't realise that was what you were using, it was just a back of an envelope demo of what I was speaking about.
I said at the time I had not tested it (albeit I had used something similar before)

Let me know how many pins of what type (bit, s32, float) you want to connect to and read / write and I will look at it tomorrow

regards

Please Log in or Create an account to join the conversation.

More
14 May 2013 02:35 #34031 by mariusl
ArcEye
I realized it was just a demo. It was the closest thing that I could find that would do what I wanted, Well almost.

I am looking at saving and retrieving three floats. Basically three spin box settings for the THC. velocity_tolerance, volt_setting and volt_tolerance.

Regards
Marius


www.bluearccnc.com

Please Log in or Create an account to join the conversation.

More
14 May 2013 04:06 #34036 by andypugh

I am looking at saving and retrieving three floats. Basically three spin box settings for the THC. velocity_tolerance, volt_setting and volt_tolerance.


This becomes automatic with an on_destroy option set up in GladeVCP.

If you look in this thread: www.linuxcnc.org/index.php/english/forum...ility?start=40#33860

There is a panel already set up with three spinboxes that retain values on shut-down. You could just change the labels.

Please Log in or Create an account to join the conversation.

More
14 May 2013 12:37 #34044 by mariusl
Hi Andy
I am not using Gladevcp but rather pyvcp. Glade is too complex with a steep learning curve. For most of the stuff I do on custom screens, I need the simplicity of pyvcp and the widgets that it offers. I am far more comfortable writing components than screen objects.

Soon I will move over to Gscreen and then I will have the time to learn, hopefully. :)

Regards
Marius


www.bluearccnc.com

Please Log in or Create an account to join the conversation.

More
14 May 2013 18:52 - 14 May 2013 18:57 #34065 by ArcEye
Hi

Think I have sorted it.
Part of the problem was needing to specifically flush the file write, because it is in a polling loop function and the other was sorting out the file path
(I just did a ~/ in the example, but that won't work with C only bash)
component paramsaver;

pin in float invalue1                "Receives value1 to update to";
pin out float outvalue1              "Sends value1";
pin in float invalue2                "Receives value2 to update to";
pin out float outvalue2              "Sends value2";
pin in float invalue3                "Receives value3 to update to";
pin out float outvalue3              "Sends value3";

pin in bit readtrigger = 0          "signal to read from file";
pin in bit writetrigger = 0         "signal to write to file";

option singleton yes;               
option userspace yes;

author "ArcEye <arceyeATmgwareDOTcoDOTuk>";
license "GPL";
;;

#include <stdio.h>    /* Standard input/output definitions */
#include <stdlib.h> 
#include <stdint.h>   /* Standard types */
#include <string.h>   /* String function definitions */
#include <unistd.h>   /* UNIX standard function definitions */
#include <fcntl.h>    /* File control definitions */
#include <errno.h>    /* Error number definitions */
#include <signal.h>
#include <pwd.h>

int done = 0;

void adios(int sig) { done = 1; }


void user_mainloop(void)
{
char line[80];
char filepath[80];
float val1, val2, val3;
int read, write;

struct passwd *pw = getpwuid(getuid());
const char *homedir = pw->pw_dir;

    sprintf(filepath, "%s/linuxcnc/param.sav", homedir);

    read = write = 0;
    
    signal(SIGINT, adios);
    signal(SIGTERM, adios);
      
    while(!done)
        {
        usleep(250000);
        
        FOR_ALL_INSTS()  
            { 
            if(!readtrigger && read) read = 0;
            if(!writetrigger && write) write = 0;
            
            if(readtrigger && !read)
            // reads the file and sets the out pins to the values read
            // connect to the spinbox param-pin which will update the widget display
                {
                FILE *fp1;
                fp1 = fopen(filepath, "r");
                fgets(line, sizeof(line), fp1);
                // only write to pins if sscanf was sucessful 
                if (sscanf(line, "%f %f %f ", &val1, &val2, &val3) != 1)
                    outvalue1 = val1; outvalue2 = val2; outvalue3 = val3;
                fclose(fp1);
                read = 1;  
                }
            else if(writetrigger && ! write)
            // reads the values from the in pins and write to file
            // connect to the spinbox out pin
                {
                FILE *fp2;
                fp2 = fopen(filepath, "w");
                fprintf(fp2, "%lf %lf %lf\n", invalue1, invalue2, invalue3);
                fflush(fp2);
                fclose(fp2);
                write = 1;
                }           
            }
        }

    exit(0);
}

and proof of concept running in a sim



The input pins receive what you want to write to file and are connected to the spinbox hal pin so as to reflect the current value
The output pins receive the saved values from file and are connected to the spinbox.N.param_pin so as to update the spinbox from file

Note that the amended pyvcp_widgets param_pins and the corresponding paramsaver.output pins will remain at the last values they were set at until set again
They are checked internally in pyvcp_widget.py against the last value that they were set to, not the last value of the spinbox widget.

The connections for the pyvcp panel in the screenshot were as below, which demonstrates
net 1p pyvcp.spinbox.0.param_pin <= paramsaver.outvalue1
net 2p pyvcp.spinbox0 => paramsaver.invalue1
net 3p pyvcp.spinbox.1.param_pin <= paramsaver.outvalue2
net 4p pyvcp.spinbox1 => paramsaver.invalue2
net 5p pyvcp.spinbox.2.param_pin <= paramsaver.outvalue3
net 6p pyvcp.spinbox2 => paramsaver.invalue3

net 7p pyvcp.load => paramsaver.readtrigger
net 8p pyvcp.write => paramsaver.writetrigger

Hopefully will do what you want

regards
Attachments:
Last edit: 14 May 2013 18:57 by ArcEye.
The following user(s) said Thank You: mariusl

Please Log in or Create an account to join the conversation.

More
14 May 2013 18:59 #34069 by mariusl
Hi ArcEye,
Wow that looks great. Just what the doctor ordered. I am going to create a way to read the file when the machine is enabled and then write it when a value has changed. That should do it for me.
Thanks a lot man.

Regards
Marius


www.bluearccnc.com

Please Log in or Create an account to join the conversation.

More
14 May 2013 19:06 #34071 by ArcEye

I am going to create a way to read the file when the machine is enabled and then write it when a value has changed


You just need to ensure that whatever flag you use to trigger is one that goes false too.
The read and write mechanisms are locked with an internal flag until the pin goes false again, to prevent cycling

halui.machine.is-on or whatever would work for loading, but if you switched off and on again it would load for a second time, needs some thought.

regards

Please Log in or Create an account to join the conversation.

More
14 May 2013 19:14 #34073 by mariusl
I will use a piece of logic code to sense the change and to toggle an internal bit. I will set it once only when the machine is started. This will cause the read signal. I dont mind if it reads every time that machine is started again.
As I said the write will happen whenever a change was made.

Regards
Marius


www.bluearccnc.com

Please Log in or Create an account to join the conversation.

More
14 May 2013 19:27 #34075 by andypugh

    signal(SIGINT, adios);
    signal(SIGTERM, adios);


Why not put "restore" and "save" in the SIGINT and SIGTERM routines?

(I _think_ that the contents of the shared memory are retained until everything has quit)

Please Log in or Create an account to join the conversation.

Time to create page: 0.170 seconds
Powered by Kunena Forum