i'm added CHDK Liveview to mweerden/CHDKPTPRemote

  • 7 Replies
  • 2764 Views
i'm added CHDK Liveview to mweerden/CHDKPTPRemote
« on: 19 / December / 2012, 08:16:10 »
Advertisements
Hello, i'm added CHDK Liveview 2.1 to CHDKPTPRemote for dotNET dev. :xmas

forked from mweerden/CHDKPTPRemote:   https://github.com/chakphanu/CHDKPTPRemote

Re: i'm added CHDK Liveview to mweerden/CHDKPTPRemote
« Reply #1 on: 19 / December / 2012, 08:32:14 »
Hi and welcome !

To run this on my old Win XP PC, do I have to install the .NET framework ?

I have another PC that does have a version of .NET framework installed.

I assume it is included with Win 7 Home Premium on another of my PC's, I have not checked.


David

*

Offline dvip

  • ****
  • 451
Re: i'm added CHDK Liveview to mweerden/CHDKPTPRemote
« Reply #2 on: 19 / December / 2012, 11:33:53 »
It looks like you will have to have Microsoft Visual C# to have this running.

*

Offline tonyb

  • *
  • 14
Re: i'm added CHDK Liveview to mweerden/CHDKPTPRemote
« Reply #3 on: 20 / December / 2012, 21:12:24 »
How do u use this? Is there an exe file to run? What do you need to use it?


Re: i'm added CHDK Liveview to mweerden/CHDKPTPRemote
« Reply #4 on: 13 / June / 2013, 05:57:20 »
Hi everyone!

I'm having a problem with CHDKPTPRemote C# wrapper. I cant get return value of executed script. for example when i execute the following code:

object r = session.ExecuteScript("get_exp_count()", true);

it returns me null value in 'r' always.. is there any solution to this problem????
Naveed E Sahar

*

Offline reyalp

  • ******
  • 11591
Re: i'm added CHDK Liveview to mweerden/CHDKPTPRemote
« Reply #5 on: 13 / June / 2013, 15:47:34 »
object r = session.ExecuteScript("get_exp_count()", true);

it returns me null value in 'r' always.. is there any solution to this problem????
I don't know anything about the C# wrapper, but in general if you want something returned from lua, you would need to use something like
"return get_exp_count()"
It's possible the C# code prepends a return automatically, though given that this breaks if the lua code is non-trivial, so I would hope it doesn't.
Don't forget what the H stands for.

*

Offline Davo

  • ***
  • 144
Re: i'm added CHDK Liveview to mweerden/CHDKPTPRemote
« Reply #6 on: 31 / August / 2013, 09:56:04 »
Quote
I'm having a problem with CHDKPTPRemote C# wrapper. I cant get return value of executed script. for example when i execute the following code:

object r = session.ExecuteScript("get_exp_count()", true);

it returns me null value in 'r' always.. is there any solution to this problem????

I am having the same problem and wondered if a solution had been found yet. The original mweerden and chakphanu branch projects are a fantastic piece of work. I am using them to build an astro .NET app that will control my computerized scope via ASCOM.NET with my A810. I already have LiveView with optional OSD up and running as well as the usual camera controls. However, I can't get the return values which I need to read Tv, ISO, etc.

It looks like the return values are calculated in this code from Session.cs but I can't see the problem.

Code: [Select]
        // returns return data (if any) unless get_error is true
        private object GetScriptMessage(int script_id, bool return_string_as_byte_array, bool get_error = false)
        {
            CHDK_ScriptMsgType type;
            int subtype, script_id2;
            byte[] data;
            while (true)
            {
                _session.CHDK_ReadScriptMsg(out type, out subtype, out script_id2, out data);

                if (type == CHDK_ScriptMsgType.PTP_CHDK_S_MSGTYPE_NONE) // no more messages; no return value
                    return null;

                if (script_id2 != script_id) // ignore message from other scripts
                    continue;

                if (!get_error && type == CHDK_ScriptMsgType.PTP_CHDK_S_MSGTYPE_RET) // return info!
                {
                    switch ((CHDK_ScriptDataType)subtype)
                    {
                        case CHDK_ScriptDataType.PTP_CHDK_TYPE_BOOLEAN:
                            return (data[0] | data[1] | data[2] | data[3]) != 0;
                        case CHDK_ScriptDataType.PTP_CHDK_TYPE_INTEGER:
                            return data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
                        case CHDK_ScriptDataType.PTP_CHDK_TYPE_STRING:
                            if (return_string_as_byte_array)
                                return data;
                            else
                                return (new ASCIIEncoding()).GetString(data);
                        default:
                            throw new Exception("script returned unsupported data type: " + type.ToString());
                    }
                }

                if (type == CHDK_ScriptMsgType.PTP_CHDK_S_MSGTYPE_ERR) // hmm.. error
                {
                    if (get_error)
                    {
                        return (new ASCIIEncoding()).GetString(data);
                    }
                    else
                    {
                        throw new Exception("error running script: " + (new ASCIIEncoding()).GetString(data));
                    }
                }

                // ignore other (user) messages
            }
        }

        // TODO: should be able to distinguish "real" exceptions and script errors
        public object ExecuteScript(string script, bool return_string_as_byte_array = false)
        {
            int script_id;
            CHDK_ScriptErrorType status;
            _session.CHDK_ExecuteScript(script, CHDK_ScriptLanguage.PTP_CHDK_SL_LUA, out script_id, out status);

            if (status == CHDK_ScriptErrorType.PTP_CHDK_S_ERRTYPE_COMPILE)
            {
                object msg = GetScriptMessage(script_id, false, true);
                if (msg.GetType() == typeof(string))
                {
                    throw new Exception("script compilation error: " + (string)msg);
                }
                else
                {
                    throw new Exception("script compilation error (unknown reason)");
                }
            }

            // wait for end
            while (true)
            {
                CHDK_ScriptStatus flags;
                _session.CHDK_ScriptStatus(out flags);
                if (!flags.HasFlag(CHDK_ScriptStatus.PTP_CHDK_SCRIPT_STATUS_RUN))
                {
                    break;
                }

                System.Threading.Thread.Sleep(100);
            }

            // get result
            return GetScriptMessage(script_id, return_string_as_byte_array);
        }

Maybe the original authors could help us out with a demo of how to read Tv using x=get_tv96();?

*

Offline Davo

  • ***
  • 144
Re: i'm added CHDK Liveview to mweerden/CHDKPTPRemote
« Reply #7 on: 02 / September / 2013, 07:08:56 »
The author of the original branch, mweerden, very kindly shone a light into the dark recesses of my brain.

You need to add 'return ' to the command which is in line with reyalp's reply. Here is the C# code to get the focus distance.

Code: [Select]
int focus = (int)session.ExecuteScript("return get_focus()");
CHDKPTPRemote.NET is a really useful piece of work and allows you to create your own camera control software very easily.


 

Related Topics