agrath / Sniper.Lighting.Dmx

Library for controlling DMX-512 devices using a DMXProUSB controller
29 stars 11 forks source link

Handle not starting [Question] #4

Open jochem4207 opened 4 years ago

jochem4207 commented 4 years ago

First of all, thank you for this code!

I'm trying to work with it and my Entec USB Pro got found immediately! :) I created a C# console app and loaded your demo class in there from your example in issue 2/3

My full 'program' is nothing more than this:

namespace Sniper.Lighting.DMX.DemoProject
{
    class Program
    {
        static void Main(string[] args)
        {
            Demo demo = new Demo();
            demo.ConnectToController();
            demo.TurnLightsOn();
            demo.Disconnect();
        }
    }
}

In TurnLightsOn I added:

          // Channel 11 is brightness for par 1
            int channel = 11;
            // Max value
            byte channelValue = 255;
            //call the controller to set the value on the queue; this is a permanent set (will stay until you change it)
            DmxController<DMXProUSB>.SetDmxValue(queue: queueId, channel: channel, priority: priority, value: channelValue, when: DateTime.Now);
            GetDMXControllerValues(11);

            // Channel 12 is red for par 1
            channel = 12;
            channelValue = 255;
            DmxController<DMXProUSB>.SetDmxValue(queue: queueId, channel: channel, priority: priority, value: channelValue, when: DateTime.Now);
            GetDMXControllerValues(12);
   private void GetDMXControllerValues(int channel)
        {
            Console.WriteLine(DmxController<DMXProUSB>.GetCurrentValues());
            Console.WriteLine(DmxController<DMXProUSB>.GetDmxValue(channel));
        }

Now this does totally nothing! and returns empty byte array and dmx value of 0. Do you have a clue where to look? I've the feeling that this code is not being hit:

Effect.cs -> StartIn(int delay)

   if (handle.Starting != null)
            {
                handle.Starting(this, new EffectEventArgs()
                {
                    Channel = handle.Channel,
                    Direction = handle.OriginalValue > handle.NewValue ? -1 : 1,
                    Step = currentStep,
                    Value = (byte)handle.OriginalValue
                });
            }

I'm currently trying to make it starting there.

Thanks for your time

Edit: info from console window:

D2XX Driver Version:: 02.212.28
Latency Timer:: 10
Sending GET_WIDGET_PARAMS packet...
PRO Connected Succesfully
Waiting for GET_WIDGET_PARAMS_REPLY packet...
GET WIDGET REPLY Received ...
-----------::PRO Connected [Information Follows]::------------
FIRMWARE VERSION: 1.44
BREAK TIME: 196 micro sec
MAB TIME: 213 micro sec
SEND REFRESH RATE: 40 packets/sec
jochem4207 commented 4 years ago

For anyone in the future that is visiting this, QLC+ has a webapi, that could be an alternative for this.

agrath commented 4 years ago

@jochem4207 without your full code it's a bit hard to diagnose your issue... I haven't used this library in about 2 years, so I'm a bit rusty on the details!

Check and confirm that you're using the right type of device, DMXProUSB or OpenDMXUSB, if I recall both respond to the FTDI intialization but may require different data to write buffers.

Did you call start on the DmxController? this starts the writer thread and actually connects to the device for writing the buffer? I think you must have because of the info from the console winodw which only gets generated in FTDI_OpenDevice called from Start.

The DmxController itself has another thread that is used for effect timing etc, but the actual DMX write doesn't happen without the start being called (this allows the library to be used without a real USB controller plugged in for simulating effects in testing etc)

The buffer that's returned by GetCurrentValues is the write buffer for the last DMX write, which is built by BuildBufferFromQueues() by processing all the effect queues, different queues can have different priority allowing multiple effects to be running but have a more important effect be shown, for example you could have a background queue and then an immediate queue.

Based on your description of the buffer returning an empty byte array, i'm guessing that the busLength is set to 0 and is not being loaded from your app settings, this in turn means that the actual byte[] buffer is 0 length. This defines how much data to actually send, see this app.config sample (or web.config if you're using a web app) It's configurable as for faster refresh if you're only sending a short array you can send it faster.

The write to buffer is guarded channel < length so this could explain what you're seeing.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="Sniper.Lighting.DMX.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <applicationSettings>
        <Sniper.Lighting.DMX.Properties.Settings>
            <setting name="DMXChannelCount" serializeAs="String">
                <value>512</value>
            </setting>
        </Sniper.Lighting.DMX.Properties.Settings>
    </applicationSettings>
</configuration>
jochem4207 commented 4 years ago

@agrath thank you first of all for your response. "My code" is now available on https://github.com/jochem4207/Sniper.Lighting.Dmx/tree/master/Code but it is not much more than your library and your example.

I haven't used this library in about 2 years, so I'm a bit rusty on the details!

That's understandable!

Check and confirm that you're using the right type of device, DMXProUSB or OpenDMXUSB, if I recall both respond to the FTDI intialization but may require different data to write buffers.

I'm using DMXProUSB in the code and I have this one, so I assume this is correct.

Did you call start on the DmxController? this starts the writer thread and actually connects to the device for writing the buffer? I think you must have because of the info from the console winodw which only gets generated in FTDI_OpenDevice called from Start.

Had to check but in your example (which I only modified a little bit) is a call to start https://github.com/jochem4207/Sniper.Lighting.Dmx/blob/4e3e5822c12f7e12050e87e37eb9b3cc7f04e715/Code/Sniper.Lighting.Dmx.DemoProject/Demo.cs#L69

 The DmxController itself has another thread that is used for effect timing etc, but the actual DMX write doesn't happen without the start being called (this allows the library to be used without a real USB controller plugged in for simulating effects in testing etc)

The buffer that's returned by GetCurrentValues is the write buffer for the last DMX write, which is built by BuildBufferFromQueues() by processing all the effect queues, different queues can have different priority allowing multiple effects to be running but have a more important effect be shown, for example you could have a background queue and then an immediate queue.

That's a lot of queues! I've to dive deeper into queues to understand it all.

i'm guessing that the busLength is set to 0 and is not being loaded from your app settings, I checked this to be sure on runtime (https://github.com/jochem4207/Sniper.Lighting.Dmx/blob/4e3e5822c12f7e12050e87e37eb9b3cc7f04e715/Code/Sniper.Lighting.Dmx/DMXProUSB.cs#L137) and it says 512.

Good way of thinking tho! Could've definitly been it.

I've to mention that sometimes when I send data I see my LED scanner (Which is on channel 1-10) respond to 'something'. But my Showtec Par 7 which I try to control (On channel 11-19) is not responding. I double checked with DMX Pro Manager from enttec (with manual slider control) if the it works from there and it does.

I also have to mention that I really like this code base but I'm highly likely to go on with QLC+ webapi. But it would be awesome to find the problem together for futher use by others (or me). In my readme (https://github.com/jochem4207/Sniper.Lighting.Dmx) I am describing my path what I plan to do.

Thanks! 💯