Delphi で DMXインターフェース「Nicolaudie Siudi」を動かす

対応インターフェース「Siudi」

  • SLESAシリーズ
  • SUITE2シリーズ

「Easy Stand Alone (ESA)」「Sunlite Suite」シリーズや、開発キット「SLMEV」に付属してくる。

nicolaudie-sunlite-slmev-640.jpg

購入: イースペック

Program

Developer kit のファイル一式を Nicolaudie からダウンロードする。

Sample source code C++ (LsHardDevKit.zip) に含まれる LsHardDevKit.dll が必要。

※ 以前は DasHard2006.dll を使っていたが、変わった?

RAD Studio Delphi 10.1 Berlin / 10.2 Tokyo 向け

unit main;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.ComCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Timer1: TTimer;
    TrackBar1: TTrackBar;
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private 宣言 }
    hDevice, hUniverse1, hUniverse2: integer;
    dmx_out: array[0..511] of byte;
    dmx_in: array[0..511] of byte;
  public
    { Public 宣言 }
  end;

var
  Form1: TForm1;

implementation

const
  DHDK_DMXOUT = 1;
  DHDK_DMXIN  = 2;

procedure DHDK_init(protocol: integer; aSoftwareName: Pointer);
  stdcall; external 'LsHardDevKit.dll' name '_DHDK_init@8';
procedure DHDK_deinit;
  stdcall; external 'LsHardDevKit.dll' name '_DHDK_deinit@0';
function DHDK_enumerate: Bool;
  stdcall; external 'LsHardDevKit.dll' name '_DHDK_enumerate@0';
function DHDK_getDeviceCount: Integer;
  stdcall; external 'LsHardDevKit.dll' name '_DHDK_getDeviceCount@0';
function DHDK_getDevice(iDevice: integer): Integer;
  stdcall; external 'LsHardDevKit.dll' name '_DHDK_getDevice@4';
function DHDK_openDevice(hDevice: integer): Bool;
  stdcall; external 'LsHardDevKit.dll' name '_DHDK_openDevice@4';
procedure DHDK_closeDevice(hDevice: integer);
  stdcall; external 'LsHardDevKit.dll' name '_DHDK_closeDevice@4';

function DHDK_getDeviceProtocol(hDevice: integer): Integer;
  stdcall; external 'LsHardDevKit.dll' name '_DHDK_getDeviceProtocol@4';
function DHDK_getDeviceTypeName(hDevice: integer; buffer: Pointer; size: integer): Bool;
  stdcall; external 'LsHardDevKit.dll' name '_DHDK_getDeviceTypeName@12';
function DHDK_getDeviceName(hDevice: integer; buffer: Pointer; size: integer): Bool;
  stdcall; external 'LsHardDevKit.dll' name '_DHDK_getDeviceName@12';

function DHDK_getDeviceSerial(hDevice: integer): Integer;
  stdcall; external 'LsHardDevKit.dll' name '_DHDK_getDeviceSerial@4';
function DHDK_getDmxUniverseCount(hDevice: integer): Integer;
  stdcall; external 'LsHardDevKit.dll' name '_DHDK_getDmxUniverseCount@4';

function DHDK_getDmxUniverse(hDevice: integer; univeNumber: integer): Integer;
  stdcall; external 'LsHardDevKit.dll' name '_DHDK_getDmxUniverse@8';
function DHDK_configureDmxUniverse(hDmxUniverse: integer; mode: integer): Integer;
  stdcall; external 'LsHardDevKit.dll' name '_DHDK_configureDmxUniverse@8';
function DHDK_sendDmx(hDmxUniverse: integer; dmxBuffer: Pointer; size: integer): Bool;
  stdcall; external 'LsHardDevKit.dll' name '_DHDK_sendDmx@12';
function DHDK_receiveDmx(hDmxUniverse: integer; dmxBuffer: Pointer; size: integer): Integer;
  stdcall; external 'LsHardDevKit.dll' name '_DHDK_receiveDmx@12';


{$R *.dfm}

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if (hDevice > 0) then
    DHDK_closeDevice(hDevice);
  DHDK_deinit;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  i, r: integer;
  buf: PAnsiChar;
begin
  hDevice := -1;
  for i := 0 to 511 do
  begin
    dmx_out[i] := 0;
    dmx_in[i] := 0;
  end;

  DHDK_init(1, PChar('myname'));
  memo1.Lines.add('init: ' + inttostr(r));

  if (DHDK_enumerate) then
    memo1.Lines.add('true')
  else
    memo1.Lines.add('false');

  r := DHDK_getDeviceCount;
  memo1.Lines.add('count: ' + inttostr(r));

  if (r > 0) then
  begin
    hDevice := DHDK_getDevice(0);
    memo1.Lines.add('get: ' + inttostr(hDevice));

    if (DHDK_openDevice(hDevice)) then
    begin
      r := DHDK_getDeviceProtocol(hDevice);
      memo1.Lines.add('pro: ' + inttostr(r));

      r := DHDK_getDeviceSerial(hDevice);
      memo1.Lines.add('serial: ' + inttostr(r));

      buf := AllocMem(100);
      DHDK_getDeviceTypeName(hDevice, buf, 100);
      memo1.Lines.add('name: ' + string(buf));

      r := DHDK_getDmxUniverseCount(hDevice);
      memo1.Lines.add('count: ' + inttostr(r));

      if (r >= 2) then
      begin
        hUniverse1 := DHDK_getDmxUniverse(hDevice, 0);
        memo1.Lines.add('univ1: ' + inttostr(hUniverse1));
        if (hUniverse1 > 0) then
          DHDK_configureDmxUniverse(hUniverse1, DHDK_DMXOUT);

        hUniverse2 := DHDK_getDmxUniverse(hDevice, 1);
        memo1.Lines.add('univ2: ' + inttostr(hUniverse2));
        if (hUniverse2 > 0) then
          DHDK_configureDmxUniverse(hUniverse2, DHDK_DMXIN);

        Timer1.Enabled := true;
      end;
    end;
  end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  dmx_out[0] := 255 - TrackBar1.Position;
  if (hUniverse1 > 0) then
    DHDK_sendDmx(hUniverse1, @dmx_out, 512);

  if (hUniverse2 > 0) then
    DHDK_receiveDmx(hUniverse2, @dmx_in, 512);

  label1.Caption := inttohex(dmx_out[0], 2) + ' ' + inttohex(dmx_in[0], 2);
end;

end.
文書の先頭へ
delphi-siudi.txt · 最終更新: 2018/04/05 16:10 by sugakoubou