DMX values over SendMessage
Posted: 01 Aug 2013, 20:20
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:
Btw. I'm a c# developer. How can I send a dmx command?
Many thanks in advance!
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);
}
}
}
}
Many thanks in advance!