Dev1an / Swift-Atem

Blackmagic Design Atem network protocol implementation in swift 5.1 using NIO 2
MIT License
59 stars 27 forks source link

What am I doing wrong? #20

Closed psycook closed 3 years ago

psycook commented 3 years ago

Hi Dev1an,

Your Swift-Atem package look amazing but I just cannot get it working. I must be doing something wrong as the control software will connect to my Atem Mini and so will your NodeJS Atem package.

My code is very simple:

        let controller = try? Controller(ipAddress: "192.168.68.240") { connection in
            connection.when { (connected: Config.InitiationComplete) in
                print(connected)
                print("Type a number and press <enter> to change the current preview")
            }
            connection.whenDisconnected = {
                print("Disconnected")
            }
        }

        controller?.send(message: Do.ChangeProgramBus(to:VideoSource.input(2)))

I keep getting the following in the output:

channel active
👹 Not sending because connectionstate is nil
🛑 Shutting down connection [IPv4]192.168.68.240:9910
channel inactive
Disconnected
lost connection due to channel inactive

I guess the issues here is the fact that the logging isn't really telling me anything. Is there a way to enable full logging that might give me a clue why this isn't working?

Thanks, Simon

Dev1an commented 3 years ago

Can you try to send your message after you receive ‘Config.InitiationComplete’?

psycook commented 3 years ago

Thank you Damiaan,

I don't get the Config.InitiationComplete message.

I'm starting to think it's somehow environmental in my XCode project (as the NodeJS app works with no issues). It seems to be shutting down the channel immediately. I have enabled outbound & inbound networking for my app's sandbox but that has no effect.

These are the messages I get from the app:

channel active

🛑 Shutting down connection [IPv4]192.168.68.240:9910 http://192.168.68.240:9910

channel inactive

Disconnected

lost connection due to channel inactive

The IP is definitely correct for my switcher. I just can't get it to connect!

Best regards, Simon

On Thu, 15 Jul 2021 at 18:49, Damiaan Dufaux @.***> wrote:

Can you try to send your message after you receive ‘Config.InitiationComplete’?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Dev1an/Swift-Atem/issues/20#issuecomment-880894884, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADE3TDUOVE2W6NLG7G7IFL3TX4NTHANCNFSM5AN457FA .

Dev1an commented 3 years ago

Hmm okay. There are definitely still some problems with how the library handles errors. What version are you using? Can you try using the ‘development’ branch?

psycook commented 3 years ago

Thanks Damiaan,

Interesting. I switched to the development branch and it all started working! This package is awesome by the way. You have saved me a massive amount of time.

Best regards, Simon

On Thu, 15 Jul 2021 at 20:33, Damiaan Dufaux @.***> wrote:

Hmm okay. There are definitely still some problems with how the library handles errors. What version are you using? Can you try using the ‘development’ branch?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Dev1an/Swift-Atem/issues/20#issuecomment-880958631, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADE3TDUK3SY5Y573EFZ7Y2LTX4ZX7ANCNFSM5AN457FA .

Dev1an commented 3 years ago

Nice to hear! I will work on a tagged (more stable) release in august with up to date documentation. May I ask what you are using the library for?

psycook commented 3 years ago

That's good news indeed.

I work for Salesforce and we are currently building an experience to run in our Innovation Centers. I am using your swift library to control the Atem switchers so we can automate our displays. I have a simple macOS app that acts as a broker and receives websocket messages from our servers. Once an atem command is received it can switch the video display! Should look cool when finished.

I have a couple of quick questions if that's ok?

Firstly, does Swift-Atem support calling macros on the Atem? I can see anything obvious in the API but I'm new to Atems so perhaps I'm missing something. This would be extremely helpful.

Also, what's your recommendation for reconnecting if the Atem is lost for some reason. I wrote a simple watchdog scheduler to monitor the connection state but it seems to crash with too many files open after a while. Is there some resource clean up I should be doing if the connection fails?

Thanks again for your help and the great library.

Best regards, Simon

On Mon, 19 Jul 2021 at 21:15, Damiaan Dufaux @.***> wrote:

Nice to hear! I will work on a tagged (more stable) release in august with up to date documentation. May I ask what you are using the library for?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Dev1an/Swift-Atem/issues/20#issuecomment-882829860, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADE3TDX2WAGK6VGPBRKDXLDTYSBVFANCNFSM5AN457FA .

Dev1an commented 3 years ago

You can send any command you want to the ATEM using this library (as is illustrated by Adam Tow's excellent mixeffect.app). But for now you need to implement the serialising and parsing of most of the commands yourself, because I've had no time to implement them yet.

Macros

For the macros you are in luck because you can simply use the code from #10 already. I will merge this next month as discussed in #15.

When you implement other commands yourself, please feel free to submit pull requests with your implementation, I will merge them when I have time.

Connection handling

I wrote a simple watchdog scheduler to monitor the connection state

Where do you get the connection state from? For now (in the dev branch), you should handle connection errors using these closures of ControllerConnection:

These closure properties will probably become methods like func when<M>((M) -> Void) in a future release.


If you still encounter issues using these API's please open separate issues for them (or comment on the pull requests) so that we can solve them in a structured manner.