Announcement

Collapse
No announcement yet.

Need help with SpeakerClient syntax

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Need help with SpeakerClient syntax

    I am not a C programmer, but trying to convert SpeakerClient.cs to an equivalent SpeakerClient.vb I am having the following issue that I cannot seem to work out.

    Here is the cs code:

    Code:
    class SpeakerClient : IFromSpeaker
    {
    private ISpeechAPI _speakHost;
    private IScsServiceClient<ISpeechAPI> _client;
    private const int SPEAKER_INTERFACE_VERSION = 10; // 10=first version for HS3 with new WCF like API
    private string _clientName = "";
    public static object objlock = new object();
    
    public SpeakerClient(string name)
    {
    _clientName = name;
    }
    
    public bool Connect(string username, string password)
    {
    lock (objlock)
    {
    string ipAddress = "127.0.0.1";
    
    Logger.LogInfo("Connecting speaker client {0} to HomeSeer IP {1}", _clientName, ipAddress);
    
    try
    {
    _client = ScsServiceClientBuilder.CreateClient<ISpeechAPI>(new ScsTcpEndPoint(ipAddress, 10401), this);
    _client.Disconnected += new EventHandler(ClientDisconnected);
    _client.Connected += new EventHandler(ClientConnected);
    }
    catch (Exception e)
    and here is the VB code I am having trouble with the statements highlighted in red showing as errors:

    Code:
    Public Sub Connect(ByVal username As String, ByVal password As String)
    Dim ipAddress As String = "127.0.0.1"
    
    Lock(objlock)
    
    OutputHSLog(LOG_INFO, "Connecting speaker client " & _clientName & " to HomeSeer IP " & ipAddress)
    
    Try
    _client = ScsServiceClientBuilder.CreateClient(Of ISpeechAPI)(New ScsTcpEndPoint(ipAddress, 10401))
    
    _client.Disconnected += New EventHandler(ClientDisconnected)
    _client.Connected += New EventHandler(ClientConnected)
    
    Catch ex As Exception
    What am I doing wrong?
    -Larry

    A member of "The HA Pioneer Group", MyWebSite

    Plugins:
    VWS, AB8SS, lrpSpeak, Calendar, Arduino, Harmony, BlueIris, Sprinklers, ZipBackup...

    Hardware:
    Intel NUC8i7BEH1 running Windows 10 Pro headless, HS3 Pro, Plex running on Synology dual High Availability DS-1815+ NAS (24Tb each), Synology Surveillance Station running on DS-416 Slim (8Tb), Samsung SmartThings, Google Home, Alexa, Hubitat Elevation, ZNET, Ubiquiti UniFi Network, Davis Vantage Pro II Weather Station. Whole house speaker system using a couple of AB8SS switches. Vantage Pro II Weather Station, Rain8Net Sprinklers, Hubitat Elevation, Google Home, Alexa, DSC Security System, Ubiquiti UniFi Network.

    #2
    Originally posted by lpitman View Post
    and here is the VB code I am having trouble with the statements highlighted in red showing as errors:
    What's the error?

    Comment


      #3
      Code:
      Public Class test
      
          Public Event MyEvent(sender As Object, e As EventArgs)
      
          Private Sub foo()
              Dim myobj As New test()
              AddHandler myobj.MyEvent, AddressOf ehh
          End Sub
      
          Private Sub ehh(sender As Object, e As EventArgs)
          ' do something
          End Sub
      
      End Class

      Comment


        #4
        It's telling me that I must use RaiseEvent, but I don't know the sintax. Please see attached CS file. This is what I'm trying to convert to an equal VB file.
        Attached Files
        -Larry

        A member of "The HA Pioneer Group", MyWebSite

        Plugins:
        VWS, AB8SS, lrpSpeak, Calendar, Arduino, Harmony, BlueIris, Sprinklers, ZipBackup...

        Hardware:
        Intel NUC8i7BEH1 running Windows 10 Pro headless, HS3 Pro, Plex running on Synology dual High Availability DS-1815+ NAS (24Tb each), Synology Surveillance Station running on DS-416 Slim (8Tb), Samsung SmartThings, Google Home, Alexa, Hubitat Elevation, ZNET, Ubiquiti UniFi Network, Davis Vantage Pro II Weather Station. Whole house speaker system using a couple of AB8SS switches. Vantage Pro II Weather Station, Rain8Net Sprinklers, Hubitat Elevation, Google Home, Alexa, DSC Security System, Ubiquiti UniFi Network.

        Comment


          #5
          Originally posted by lpitman View Post
          It's telling me that I must use RaiseEvent, but I don't know the sintax. Please see attached CS file. This is what I'm trying to convert to an equal VB file.
          You don't need to RaiseEvent - this will be called by IScsServiceClient.
          Your code is client - so you need to receive the event - which is done by AddHandler.
          So when your client connects/disconnects - your handler will be called to inform you.

          So you just need

          AddHandler _client.Connected, AddressOf ClientConnected


          Private Sub ClientConnected(sender As Object, e As EventArgs)
          ' do something
          End Sub

          Comment


            #6
            Thank you that makes it more clear.
            -Larry

            A member of "The HA Pioneer Group", MyWebSite

            Plugins:
            VWS, AB8SS, lrpSpeak, Calendar, Arduino, Harmony, BlueIris, Sprinklers, ZipBackup...

            Hardware:
            Intel NUC8i7BEH1 running Windows 10 Pro headless, HS3 Pro, Plex running on Synology dual High Availability DS-1815+ NAS (24Tb each), Synology Surveillance Station running on DS-416 Slim (8Tb), Samsung SmartThings, Google Home, Alexa, Hubitat Elevation, ZNET, Ubiquiti UniFi Network, Davis Vantage Pro II Weather Station. Whole house speaker system using a couple of AB8SS switches. Vantage Pro II Weather Station, Rain8Net Sprinklers, Hubitat Elevation, Google Home, Alexa, DSC Security System, Ubiquiti UniFi Network.

            Comment

            Working...
            X