CasparObjects a little VB.NET wrapper library

#1
For some time now I use my own .NET wrapper libray for CasparCG. It has not many fancy functions, but works very well for me. It can start the server if not already running, it gives back the response of the server and you can query for templates and media-files. It let you fill template variables via a list of fields. As a goody there is a grab function and a TGA writer, that can be used to render Targa files for use in a editing system.

Today a wrote a small demo programm:
Image
You find the demo and the library as VB.NET source here:
https://dl.dropboxusercontent.com/u/136 ... bjects.zip
Didi Kunz
CasparCG Client-Programmer, Template Maker & Live CG-Operator
Media Support, CH-5722 Gränichen, Switzerland http://mediasupport.ch/
Problems? Guide to posting Bug reports & Feature requests

Re: CasparObjects a little VB.NET wrapper library

#4
Hi Didi,

I've been trying your demo client. I like it, it shows me a lot of things I didn't know how to code. Thank you very much.

I've found what maybe is a little bug. When you read the templates folder and fill the listbox, if you have a template inside a user folder inside templates main folder, the "\" character between user folder name and template name is removed and so both names get together, and further fields seek fails. I've fixed this way:

CasparCG.vb file

Code: Select all

Public Function GetTemplateNames() As List(Of String)

      Dim lst As List(Of String) = New List(Of String)
      Dim Ret() As String = Execute("TLS").Data.Split(Microsoft.VisualBasic.vbCrLf)

      For Each s As String In Ret
         If s.Contains(Chr(&H22)) Then
                // You wrote this:
                // Dim tmpl As String = s.Substring(1, s.IndexOf(Chr(&H22), 2) - 1).Replace("\", "").Replace(Chr(&H22), "") 
                //
                // And I've changed .Replace("\", "") to .Replace("\", "/")
                //
                Dim tmpl As String = s.Substring(1, s.IndexOf(Chr(&H22), 2) - 1).Replace("\", "/").Replace(Chr(&H22), "")
                lst.Add(tmpl)
         End If
      Next
      Return lst

   End Function
I'll keep testing. Thanks.
Jesús

Re: CasparObjects a little VB.NET wrapper library

#5
jrogo wrote:Hi Didi,

I've been trying your demo client. I like it, it shows me a lot of things I didn't know how to code. Thank you very much.

I've found what maybe is a little bug. When you read the templates folder and fill the listbox, if you have a template inside a user folder inside templates main folder, the "\" character between user folder name and template name is removed and so both names get together, and further fields seek fails. I've fixed this way:

CasparCG.vb file

Code: Select all

Public Function GetTemplateNames() As List(Of String)

      Dim lst As List(Of String) = New List(Of String)
      Dim Ret() As String = Execute("TLS").Data.Split(Microsoft.VisualBasic.vbCrLf)

      For Each s As String In Ret
         If s.Contains(Chr(&H22)) Then
                // You wrote this:
                // Dim tmpl As String = s.Substring(1, s.IndexOf(Chr(&H22), 2) - 1).Replace("\", "").Replace(Chr(&H22), "") 
                //
                // And I've changed .Replace("\", "") to .Replace("\", "/")
                //
                Dim tmpl As String = s.Substring(1, s.IndexOf(Chr(&H22), 2) - 1).Replace("\", "/").Replace(Chr(&H22), "")
                lst.Add(tmpl)
         End If
      Next
      Return lst

   End Function
I'll keep testing. Thanks.
Jesús
You are right, I don't know, what for the .Replace(Chr(&H22), "") actually was for. It makes more sense the way you do it. Thank you.
Didi Kunz
CasparCG Client-Programmer, Template Maker & Live CG-Operator
Media Support, CH-5722 Gränichen, Switzerland http://mediasupport.ch/
Problems? Guide to posting Bug reports & Feature requests

Re: CasparObjects a little VB.NET wrapper library

#8
yuskadeepak wrote:Hi Mr Didi Kunz,
Do you have a sample that shows how to send the template data fields using your library ? thanks in advance.

Regards,
yus
Hi yus,

don't call me "Mr Didi Kunz" :) it feels like being very old :) Didi is sufficient. I will do a updated version and a little tutorial in the next few days.

Didi
Didi Kunz
CasparCG Client-Programmer, Template Maker & Live CG-Operator
Media Support, CH-5722 Gränichen, Switzerland http://mediasupport.ch/
Problems? Guide to posting Bug reports & Feature requests

Re: CasparObjects a little VB.NET wrapper library

#10
There is a tutorial project in VB.NET 2010 here: https://dl.dropboxusercontent.com/u/136 ... torial.zip it includes the CasparObjects source files.

The CasparObjects source and documentation, without tutorial, is here https://dl.dropboxusercontent.com/u/136 ... bjects.zip

Hope it's useful to somebody.
Didi Kunz
CasparCG Client-Programmer, Template Maker & Live CG-Operator
Media Support, CH-5722 Gränichen, Switzerland http://mediasupport.ch/
Problems? Guide to posting Bug reports & Feature requests

Re: CasparObjects a little VB.NET wrapper library

#12
Hello Didi,
I am trying to use your dll and example. I have started with trying to run the CasparObject Tutorial but I get the following exeption :
'System.InvalidOperationException" on the line
Protected Overrides Sub OnCreateMainForm()
Me.MainForm = Global.CasparObjectsTutorial.frmMain <<<----
End Sub

Here is the French message :
Une exception non gérée du type 'System.InvalidOperationException' s'est produite dans System.Xml.dll
Informations supplémentaires : Il existe une erreur dans le document XML (1, 1).

As you may know I am not yet an experienced C# programmer but I try my best. I though I has done something silly.

So I have referenced you dll in my project and I have written this little piece of code (simple translation in C# of your VB.NET :
CasparCG _Caspar = new CasparCG("192.168.71.1");
try
{
_Caspar.Connect();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Impossible de se connecter à CasparCG");

}
if (_Caspar.Connected)
foreach (String lS in _Caspar.GetTemplateNames())
{
System.Diagnostics.Debug.WriteLine(lS);
MessageBox.Show("Template", "lS");
}

and guess what when I run it ?

I get the same exception on the line
CasparCG _Caspar = new CasparCG("192.168.71.1");
By the way I am sure of the IP address and there is a running CasparCG server on it.

Can you give me a clue to get further ?
Regards,
Sylvain

Re: CasparObjects a little VB.NET wrapper library

#13
The error in the XML library is a stupid idiot's (me) fault by messing around with a xml file and not doing it right. I will look into that tomorrow.

The connection error is more serious. Are you able to connect to Cadpar with the official client? Or is the firewall blocking Visual Studio?
Didi Kunz
CasparCG Client-Programmer, Template Maker & Live CG-Operator
Media Support, CH-5722 Gränichen, Switzerland http://mediasupport.ch/
Problems? Guide to posting Bug reports & Feature requests

Re: CasparObjects a little VB.NET wrapper library

#14
Hello Didi,
No I do not have any connectionError just the same one with the XML library. Yes I can get to connect with the official client.
Please let me know if you have sorted the xml librairie. I have not seen any xml is it "internal" the only new file I have referrenced in my projet to integrate the CasparObjects is a dll.
Regards,
Sylvain

Re: CasparObjects a little VB.NET wrapper library

#15
Hello Sylvain,

Can you please give this https://dl.dropboxusercontent.com/u/136 ... torial.zip a try? I changed the setup of the CasparObjectsTutorial, so that it should work. I also added a possibility to enter a IP-Address.

Hope this does it. otherways we must setup a TeamViewer session tomorrow.
Didi Kunz
CasparCG Client-Programmer, Template Maker & Live CG-Operator
Media Support, CH-5722 Gränichen, Switzerland http://mediasupport.ch/
Problems? Guide to posting Bug reports & Feature requests

Re: CasparObjects a little VB.NET wrapper library

#17
Hi guys,
I'm trying the CasparObject to send commands to a CasparCG Server, and it is working right.
I have two questions:
Can I know the name of a running template?
Just for example, I start a client, I load a template in a channel-layer and I run it.
In a second client, based on CasparObject, I would like to know the name of the running template on that cannel-layer.
Can I query the server?

Second question.
I have a running template, can I read some properties about the template?
An example to be more understandable.
I have a template with a timer. When the timer fires, I set a boolean variable (or property or.. something else) to Ture. i would like to check the value of the field to know when the timer is fired. Can I do that with CasparObject?
Thanks

Re: CasparObjects a little VB.NET wrapper library

#18
vbMizio wrote:Can I know the name of a running template?
No, that is not implemented. There is no AMCP command for that.
vbMizio wrote:I have a running template, can I read some properties about the template?
No, also not, as there is also no AMCP command for that.

What you can do with the library is get general informations about a template. There is a function called "GetTemplate" taht returns a template-object parsed out of the return of a INFO TEMPLATE command. It contains also the fieldnames (as long as they are properly exported in the template).

What could be a scenario where you would need that kind of informations from running templates?

A workaround would be to use a socket from inside a template and send a DATA comand to the server where the other client could qury for, but it's far from beeing an elegant solution. As said above: what would you use it for?
Didi Kunz
CasparCG Client-Programmer, Template Maker & Live CG-Operator
Media Support, CH-5722 Gränichen, Switzerland http://mediasupport.ch/
Problems? Guide to posting Bug reports & Feature requests

Re: CasparObjects a little VB.NET wrapper library

#19
Hi didi,
about the first question, ok, no problem.
About the secon one.
The scenario...
A crawl with some news. I start the crawl, when a crawl has finished its work, the crawl stop.
Then I would like to be able to know that the crawl is over, so I can update the crawl text and the restart.
I think I can set a timer on my client and send the new text after a bit, so I need to calculate the lenght (time) of the crawl by the lenght ( number of characters) of the text.
A second way can be write the code by AS3 to read a text file every loop, to make the template able to update itself.

Re: CasparObjects a little VB.NET wrapper library

#20
You could also build a crawl template, that you can send new data to it and as soon as the text runs off reload the data. So that you don't need to know when or if the crawl has finished. It could hide itself when there is no data any more, or just loop with the last data until new data arrives, As long as you give the template it's own layer you can leave it sitting there "for ever".
Didi Kunz
CasparCG Client-Programmer, Template Maker & Live CG-Operator
Media Support, CH-5722 Gränichen, Switzerland http://mediasupport.ch/
Problems? Guide to posting Bug reports & Feature requests