Page 1 of 1

DMX values over SendMessage

Posted: 01 Aug 2013, 20:20
by sa1n
Hi there!

I'm looking for a way to send DMX values directly to freestyler, that means just that I want to set an output channel for a specific fixture. I used the code sample above and I currently have the following code:

Code: Select all

        private void ButtonClick(object sender, RoutedEventArgs e)
        {
            byte[] dmx = new byte[] { 255 };

            FsSendMessage fsSend = new FsSendMessage();
            
            //fsSend.SendMessageFunction(2, 1);
            fsSend.SendChMessageFunction(dmx,1);

        }

Code: Select all

using System;
using System.Runtime.InteropServices;

namespace Freestyler.NET.Wrapper
{
    public class FsSendMessage
    {
        //COMPILE AS X86 otherwise pointers need changing
        //For use with WM_COPYDATA and COPYDATASTRUCT
        [DllImport("User32.dll")]
        public static extern int SendMessage(int hWnd, int Msg, int wParam, ref Copydatastruct lParam);
        [DllImport("user32.dll")]
        public static extern int SendMessage(int hWnd, int Msg, int wParam, int LParam);
        [DllImport("user32.dll")]
        static extern int FindWindow(string lpClassName, string lpWindowName);

        private const int WmUser = 0x400;
        private const int WmCopy = 0x4A;



        private int freestylerConnected()
        {
            int ihandle = FindWindow(null, "FS");
            return ihandle;
        }

        private static Int32 VarPtr(object o)
        {
            GCHandle GC = GCHandle.Alloc(o, GCHandleType.Pinned);
            IntPtr ptr = GC.AddrOfPinnedObject();
            GC.Free();
            return ptr.ToInt32();
        }

        public struct Copydatastruct
        {
            public Int32 DwData;
            public Int32 CbData;
            [MarshalAs(UnmanagedType.I4)]
            public Int32 LpData;
        }

        public void SendChMessageFunction(byte[] DMXvalues, int functionCode)
        {

            Copydatastruct cds;
            cds.DwData = functionCode;
            cds.LpData = VarPtr(DMXvalues);
            cds.CbData = DMXvalues.Length;
            int hWnd = freestylerConnected();
            if (hWnd != 0)
            {
                SendMessage(hWnd, WmCopy, 0, ref cds);
            }

        }

        public void SendMessageFunction(int command, int value)
        {

            int iHandle = freestylerConnected();
            if (freestylerConnected() != 0)
            {
                SendMessage(iHandle, WmUser, command, value);
            }
        }
    }
}
Btw. I'm a c# developer. How can I send a dmx command?

Many thanks in advance!

Re: DMX values over SendMessage

Posted: 01 Aug 2013, 20:44
by Mattotone
public void SendChMessageFunction(byte[] DMXvalues, int functionCode)
Is the correct method, if your having issues try using the dll file i uploaded.
Ensure you compile your app x86

Re: DMX values over SendMessage

Posted: 02 Aug 2013, 08:02
by sa1n
Could you give me an example? I.e. send the dmx value 130 on dmx channel 5.

The program works fine with the standard functions.

Re: DMX values over SendMessage

Posted: 02 Aug 2013, 09:37
by Mattotone
is your application compiled as x86? The pointers required for dmx values only work when compiled for x86

to set just ch5 i think you need to send an output mask first. should be explained in the tcp/ip pdf in the fs directory.

also you can try this viewtopic.php?f=38&t=5111&start=10#p21032

Re: DMX values over SendMessage

Posted: 04 Aug 2013, 13:40
by sa1n
Yes, my application is compiled as x86. Is there an example?

Re: DMX values over SendMessage

Posted: 04 Aug 2013, 20:10
by Mattotone
:fs:
Freestyler Connection Demo.rar

Re: DMX values over SendMessage

Posted: 04 Aug 2013, 20:51
by sa1n
Wow! That's really great :) Many thanks!