C
C#8mo ago
Paladin

Connecting to an ATEM Switcher via C# (Multiplatform)

So, I am trying to invoke some disconnection logic, in order to access COM ports. The SDK says it is possible to connect on other platforms but it seems to be proving difficult.
The SDK interface is modeled on Microsoft’s Component Object Model (COM). On Microsoft Windows platforms, it is provided as a native COM interface registered with the operating system. On other platforms application code is provided to allow the same COM style interface to be used.
The SDK interface is modeled on Microsoft’s Component Object Model (COM). On Microsoft Windows platforms, it is provided as a native COM interface registered with the operating system. On other platforms application code is provided to allow the same COM style interface to be used.
Here is the code I'm using atm from the ATEMConnect.cs file
[DllImport("BMDSwitcherAPI.dll")]
public static extern IntPtr ConnectToSwitcher(string ipAddress);

public void ConnectToAtemSwitcher(string ipAddress)
{
IntPtr switcherPtr = ConnectToSwitcher(ipAddress);

if (switcherPtr != IntPtr.Zero)
{
Console.WriteLine("Successfully connected to ATEM switcher at IP: " + ipAddress);
// Continue with your operations on the switcher
}
else
{
Console.WriteLine("Failed to connect to ATEM switcher at IP: " + ipAddress);
}
}

public void DisconnectFromAtemSwitcher(IntPtr switcherPtr)
{
IBMDSwitcher switcher = (IBMDSwitcher)Marshal.GetObjectForIUnknown(switcherPtr);

// Assuming Disconnect method exists in the switcher API

Console.WriteLine("Disconnected from ATEM switcher");
}
[DllImport("BMDSwitcherAPI.dll")]
public static extern IntPtr ConnectToSwitcher(string ipAddress);

public void ConnectToAtemSwitcher(string ipAddress)
{
IntPtr switcherPtr = ConnectToSwitcher(ipAddress);

if (switcherPtr != IntPtr.Zero)
{
Console.WriteLine("Successfully connected to ATEM switcher at IP: " + ipAddress);
// Continue with your operations on the switcher
}
else
{
Console.WriteLine("Failed to connect to ATEM switcher at IP: " + ipAddress);
}
}

public void DisconnectFromAtemSwitcher(IntPtr switcherPtr)
{
IBMDSwitcher switcher = (IBMDSwitcher)Marshal.GetObjectForIUnknown(switcherPtr);

// Assuming Disconnect method exists in the switcher API

Console.WriteLine("Disconnected from ATEM switcher");
}
Marshal.GetObjectForIUnknown(switcherPtr) is proving to be the problem as it says in the IDE it is Windows only, but I aren't sure what the equivalent is. I asked in #chat about P/Invoke but I'd still likely need to use something like that even with P/Invoke. I'm not sure how I can get this to access on Mac.
4 Replies
Omnissiah
Omnissiah8mo ago
you should be able to pretty much copy the code from the manual/pdf in the sdk, does their program connect successfully to the switcher?
Paladin
PaladinOP8mo ago
Their program is either Windows only in C#, or their cross-platform examples are pure C++
Omnissiah
Omnissiah8mo ago
yes, but as a test, because you have to have the same version of the client installed in the pc and the stuff installed in the switcher itself also in my project i don't really import apis manually, i imported the reference
<ItemGroup>
<COMReference Include="BMDSwitcherAPI">
<WrapperTool>tlbimp</WrapperTool>
<VersionMinor>0</VersionMinor>
<VersionMajor>1</VersionMajor>
<Guid>8a92b919-156c-4d61-94ef-03f9be4004b0</Guid>
<Lcid>0</Lcid>
<Isolated>false</Isolated>
<EmbedInteropTypes>true</EmbedInteropTypes>
</COMReference>
</ItemGroup>
<ItemGroup>
<COMReference Include="BMDSwitcherAPI">
<WrapperTool>tlbimp</WrapperTool>
<VersionMinor>0</VersionMinor>
<VersionMajor>1</VersionMajor>
<Guid>8a92b919-156c-4d61-94ef-03f9be4004b0</Guid>
<Lcid>0</Lcid>
<Isolated>false</Isolated>
<EmbedInteropTypes>true</EmbedInteropTypes>
</COMReference>
</ItemGroup>
(and i really have to 🛌 )
Paladin
PaladinOP8mo ago
No worries. I'll see if I can figure anything out from that. Thank you for the help! Also, I see what you meant by that now. Sorry for the confusion. Yes the example programs do connect successfully (well, most of them anyway)
Want results from more Discord servers?
Add your server