Please login or register.

Login with username, password and session length

Author Topic: Visual Studio C++ express edition 2010  (Read 16940 times)

Riggs

  • Newbie
  • Helpful Post Rating: 0
  • Posts: 3
Visual Studio C++ express edition 2010
« on: July 13, 2010, 04:43:22 PM »

Ok I have:
Microsoft Windows Vista Home Pre 32 bit.
Active Home Pro, Version 3.271.
The most up to date SDK from the X10 website.
CM19A.
TM751
4x AM466

I am no real programmer but I want to learn, now there is documentation for the SDK on how to use it, I have tried to load the sample code and Visual Studio wants to convert it so i say yes and i just get errors, I cant run it in visual Studio without converting.
Can any one get me up and running so I can start learning, it would be nice to just create a single basic form with on and off to control one device from there I can learn my self.
« Last Edit: July 13, 2010, 04:55:57 PM by Riggs »
Logged

RichardUK

  • Jr. Member
  • **
  • Helpful Post Rating: 0
  • Posts: 24
    • Whzan
Re: Visual Studio C++ express edition 2010
« Reply #1 on: July 15, 2010, 05:48:24 AM »

Lets know how much of this makes sence and I can start to help you out as then i'll get a handle on your coding noob status. :)

I'm assuming you're using c#? If so create a new wpf project and add a reference to the com interface of the SDK. That last bit may be gibberish to you? If you do these steps then you'll be ready to start playing.

Here is the function in my code that tries to create a connection to a cm15 dll and if it works sends a dummy command to see if it's connected.


      public override void CheckConnection()
      {
         if (cm15 == null)
         {
            try
            {//This will still work if the device is not plugged in.
               cm15 = new ActiveHomeScriptLib.ActiveHomeClass();
               cm15.RecvAction += new ActiveHomeScriptLib._DIActiveHomeEvents_RecvActionEventHandler(cm15_RecvAction);
               
            }
            catch (Exception)
            {//Driver can not be installed. Whoops.
               //I may have to tweek this code so if this happens it waits for the driver to be installed.
               //This exception does not happen if the driver is installed but device not plugged in. In that case the allocation will be ok.
               
            }
         }
         else
         {//Cheeky way to test for cm15 connection.
            int res = (int)cm15.SendAction("queryplc", "e11 on", null, null);
            if (res == -1)
            {
               //send a "cm15 is disconnected from USB" error to user
            }
         }
      }

//Recive callback from the dll
void cm15_RecvAction(object bszAction, object bszParm1, object bszParm2, object bszParm3, object bszParm4, object bszParm5, object bszReserved)
      {
         string cmd = bszAction as string;

         if (String.Compare(cmd, "recvrf",true) == 0 ||
            String.Compare(cmd, "recvplc", true) == 0)
         {
            string address = bszParm1 as string;
            string state = bszParm2 as string;
            if (String.Compare(state, "on", true) == 0)
            {
               OnX10Message_OnReceived(address);
            }
            else if (String.Compare(state, "off", true) == 0)
            {
               OnX10Message_OffReceived(address);
            }
            else if (String.Compare(state, "Bright", true) == 0)
            {
               OnX10Message_BrightenReceived(address, (int)bszParm3);
            }
            else if (String.Compare(state, "Dim", true) == 0)
            {
               OnX10Message_DimReceived(address, (int)bszParm3);
            }
         }

         Debug.WriteLine(
            String.Format("{0} \'{1}\' \'{2}\' \'{3}\' \'{4}\' \'{5}\'",
               bszAction,
               bszParm1,
               bszParm2,
               bszParm3,
               bszParm4,
               bszParm5));
      }

//My send function.
      protected override void ExecuteX10QueuedCommands(List<String> pCommands)
      {
         if (cm15 != null )
         {
            foreach (string cmd in pCommands)
            {               
               try
               {
                  Debug.WriteLine("sendplc " + command);
                  object ret = cm15.SendAction("sendplc", command, null, null);
               }
               catch (Exception error)
               {
                  Debug.WriteLine("cm15 command failed " + error.Message);
               }
            }
         }
      }

Logged
Richard e Colins.
www.whzan.com

Riggs

  • Newbie
  • Helpful Post Rating: 0
  • Posts: 3
Re: Visual Studio C++ express edition 2010
« Reply #2 on: July 16, 2010, 11:48:05 AM »

OK I created the WPF project, I'm unsure about the reference to the com interface of the SDK, but i think i got it right, I have the CM19A at the min, my CM15A is in the mail so i just replaced CM15A with CM19A

I right clicked on references and click add, chose com and selected ActiveHomeScriptLib.
There are a lot of errors


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
        }
            public override void CheckConnection()
      {
         if (cm19 == null)
         {
            try
            {//This will still work if the device is not plugged in.
               cm19 = new ActiveHomeScriptLib.ActiveHomeClass();
               cm19.RecvAction += new ActiveHomeScriptLib._DIActiveHomeEvents_RecvActionEventHandler(cm19_RecvAction);
               
            }
            catch (Exception)
            {//Driver can not be installed. Whoops.
               //I may have to tweek this code so if this happens it waits for the driver to be installed.
               //This exception does not happen if the driver is installed but device not plugged in. In that case the allocation will be ok.
               
            }
         }
         else
         {//Cheeky way to test for cm15 connection.
            int res = (int)cm19.SendAction("queryplc", "e11 on", null, null);
            if (res == -1)
            {
               //send a "cm15 is disconnected from USB" error to user
            }
         }
      }

//Recive callback from the dll
void cm15_RecvAction(object bszAction, object bszParm1, object bszParm2, object bszParm3, object bszParm4, object bszParm5, object bszReserved)
      {
         string cmd = bszAction as string;

         if (String.Compare(cmd, "recvrf",true) == 0 ||
            String.Compare(cmd, "recvplc", true) == 0)
         {
            string address = bszParm1 as string;
            string state = bszParm2 as string;
            if (String.Compare(state, "on", true) == 0)
            {
               OnX10Message_OnReceived(address);
            }
            else if (String.Compare(state, "off", true) == 0)
            {
               OnX10Message_OffReceived(address);
            }
            else if (String.Compare(state, "Bright", true) == 0)
            {
               OnX10Message_BrightenReceived(address, (int)bszParm3);
            }
            else if (String.Compare(state, "Dim", true) == 0)
            {
               OnX10Message_DimReceived(address, (int)bszParm3);
            }
         }

         Debug.WriteLine(
            String.Format("{0} \'{1}\' \'{2}\' \'{3}\' \'{4}\' \'{5}\'",
               bszAction,
               bszParm1,
               bszParm2,
               bszParm3,
               bszParm4,
               bszParm5));
      }

//My send function.
      protected override void ExecuteX10QueuedCommands(List<String> pCommands)
      {
         if (cm19 != null )
         {
            foreach (string cmd in pCommands)
            {               
               try
               {
                  Debug.WriteLine("sendplc " + command);
                  object ret = cm19.SendAction("sendplc", command, null, null);
               }
               catch (Exception error)
               {
                  Debug.WriteLine("cm19 command failed " + error.Message);
               }
            }
         }
      }

        }
    }

PS, I am complete newbe to C# the last programming lang I used was Turbo Pascal on an Amiga 501, it was just basic if then statements mainly a huge password program I did for fun, a long time a go LOL

Thank you for your help.
« Last Edit: July 16, 2010, 01:03:25 PM by Riggs »
Logged

RichardUK

  • Jr. Member
  • **
  • Helpful Post Rating: 0
  • Posts: 24
    • Whzan
Re: Visual Studio C++ express edition 2010
« Reply #3 on: July 19, 2010, 03:53:23 AM »

We all start somewhere, I did my first commercial software on an A500. :) C# is a good place for a noob as it has tones of util classes taking a lot of the leg work out for you.

As for adding the reference that is how I did it. Can you paste in the errors, I did find I had to 'fiddle' about before the app picked up the SDK references ok. Maybe a rebuild all. But you're 90% of the way there. :)
Logged
Richard e Colins.
www.whzan.com

Riggs

  • Newbie
  • Helpful Post Rating: 0
  • Posts: 3
Re: Visual Studio C++ express edition 2010
« Reply #4 on: July 19, 2010, 11:32:48 AM »

Error   1   'WpfApplication1.MainWindow.CheckConnection()': no suitable method found to override   C:\Users\Simon\documents\visual studio 2010\Projects\WpfApplication1\WpfApplication1\MainWindow.xaml.cs   30   34   WpfApplication1
Error   2   'WpfApplication1.MainWindow.ExecuteX10QueuedCommands(System.Collections.Generic.List<string>)': no suitable method found to override   C:\Users\Simon\documents\visual studio 2010\Projects\WpfApplication1\WpfApplication1\MainWindow.xaml.cs   96   31   WpfApplication1
Error   3   The name 'cm19' does not exist in the current context   C:\Users\Simon\documents\visual studio 2010\Projects\WpfApplication1\WpfApplication1\MainWindow.xaml.cs   32   14   WpfApplication1
Error   4   The name 'cm19' does not exist in the current context   C:\Users\Simon\documents\visual studio 2010\Projects\WpfApplication1\WpfApplication1\MainWindow.xaml.cs   36   16   WpfApplication1
Error   5   Interop type 'ActiveHomeScriptLib.ActiveHomeClass' cannot be embedded. Use the applicable interface instead.   C:\Users\Simon\documents\visual studio 2010\Projects\WpfApplication1\WpfApplication1\MainWindow.xaml.cs   36   47   WpfApplication1
Error   6   The name 'cm19' does not exist in the current context   C:\Users\Simon\documents\visual studio 2010\Projects\WpfApplication1\WpfApplication1\MainWindow.xaml.cs   37   16   WpfApplication1
Error   7   The name 'cm19_RecvAction' does not exist in the current context   C:\Users\Simon\documents\visual studio 2010\Projects\WpfApplication1\WpfApplication1\MainWindow.xaml.cs   37   102   WpfApplication1
Error   8   The name 'cm19' does not exist in the current context   C:\Users\Simon\documents\visual studio 2010\Projects\WpfApplication1\WpfApplication1\MainWindow.xaml.cs   49   28   WpfApplication1
Error   9   The name 'OnX10Message_OnReceived' does not exist in the current context   C:\Users\Simon\documents\visual studio 2010\Projects\WpfApplication1\WpfApplication1\MainWindow.xaml.cs   69   16   WpfApplication1
Error   10   The name 'OnX10Message_OffReceived' does not exist in the current context   C:\Users\Simon\documents\visual studio 2010\Projects\WpfApplication1\WpfApplication1\MainWindow.xaml.cs   73   16   WpfApplication1
Error   11   The name 'OnX10Message_BrightenReceived' does not exist in the current context   C:\Users\Simon\documents\visual studio 2010\Projects\WpfApplication1\WpfApplication1\MainWindow.xaml.cs   77   16   WpfApplication1
Error   12   The name 'OnX10Message_DimReceived' does not exist in the current context   C:\Users\Simon\documents\visual studio 2010\Projects\WpfApplication1\WpfApplication1\MainWindow.xaml.cs   81   16   WpfApplication1
Error   13   The name 'Debug' does not exist in the current context   C:\Users\Simon\documents\visual studio 2010\Projects\WpfApplication1\WpfApplication1\MainWindow.xaml.cs   85   10   WpfApplication1
Error   14   The name 'cm19' does not exist in the current context   C:\Users\Simon\documents\visual studio 2010\Projects\WpfApplication1\WpfApplication1\MainWindow.xaml.cs   98   14   WpfApplication1
Error   15   The name 'Debug' does not exist in the current context   C:\Users\Simon\documents\visual studio 2010\Projects\WpfApplication1\WpfApplication1\MainWindow.xaml.cs   104   19   WpfApplication1
Error   16   The name 'command' does not exist in the current context   C:\Users\Simon\documents\visual studio 2010\Projects\WpfApplication1\WpfApplication1\MainWindow.xaml.cs   104   48   WpfApplication1
Error   17   The name 'cm19' does not exist in the current context   C:\Users\Simon\documents\visual studio 2010\Projects\WpfApplication1\WpfApplication1\MainWindow.xaml.cs   105   32   WpfApplication1
Error   18   The name 'command' does not exist in the current context   C:\Users\Simon\documents\visual studio 2010\Projects\WpfApplication1\WpfApplication1\MainWindow.xaml.cs   105   59   WpfApplication1
Error   19   The name 'Debug' does not exist in the current context   C:\Users\Simon\documents\visual studio 2010\Projects\WpfApplication1\WpfApplication1\MainWindow.xaml.cs   109   19   WpfApplication1
Logged

EL34

  • Hero Member
  • *****
  • Helpful Post Rating: 21
  • Posts: 278
    • My X-10 projects
Re: Visual Studio C++ express edition 2010
« Reply #5 on: July 19, 2010, 12:51:15 PM »

It's way easier if someone can zip up a simple working project that he can open.
Just a button that turns on a X10 device is all you need and then he can start feom that point.

I'd do it for you, but I use VB2008 express.
I have a working VB project on my web site that users can download
It has a basic X10 traffic monitor and shows how to switch on and off X10 devices with buttons.
Logged
W10 - CM15A - AHP 3.301 - i Witness - MyHouse online - Smart Macros - SDK using Visual Basic express 2008
My X10 page-> http://www.el34world.com/Misc/home/X10_0.htm

RichardUK

  • Jr. Member
  • **
  • Helpful Post Rating: 0
  • Posts: 24
    • Whzan
Re: Visual Studio C++ express edition 2010
« Reply #6 on: July 20, 2010, 04:55:50 AM »

Yes I was thinking the same. The errors you have is because the code you've cut'n' pasted in is dependant on code of mine which is not nessery for the coms with the cm15 / cm19 unit. Give me an hour or so and i'll zip up an early test app I have. At work at the moment so may have to mail it to you. I'll post when I have something to send.

At somepoint the 'gateways' we have for our website, Whzan, will become open source. Just got a lot to do till we are ready to open source it so best if I send you my test app.
Logged
Richard e Colins.
www.whzan.com

RichardUK

  • Jr. Member
  • **
  • Helpful Post Rating: 0
  • Posts: 24
    • Whzan
Re: Visual Studio C++ express edition 2010
« Reply #7 on: July 20, 2010, 10:53:41 AM »

I have a little, very simple, test app as a vs2008 project so 'should' be ok with your version of vs. If you PM me with your email i'll send it to you.
Logged
Richard e Colins.
www.whzan.com

pconroy

  • Hero Member
  • *****
  • Helpful Post Rating: 9
  • Posts: 294
Re: Visual Studio C++ express edition 2010
« Reply #8 on: July 20, 2010, 01:58:49 PM »

Whzan

That's a beautiful site Richard.
Well done.
Logged

RichardUK

  • Jr. Member
  • **
  • Helpful Post Rating: 0
  • Posts: 24
    • Whzan
Re: Visual Studio C++ express edition 2010
« Reply #9 on: July 23, 2010, 04:33:01 AM »

Whzan

That's a beautiful site Richard.
Well done.

Thanks. :) If you have time would be cool to know if it worked ok for you. Only so much testing we can do our end. Any sugestions or bugs very much appreciated.
Logged
Richard e Colins.
www.whzan.com

pconroy

  • Hero Member
  • *****
  • Helpful Post Rating: 9
  • Posts: 294
Re: Visual Studio C++ express edition 2010
« Reply #10 on: July 23, 2010, 12:42:19 PM »

Sure - what site-specific things do you want me to check out?
I just poked around for a bit.


I will admit - that I'm not exactly sure what problem is getting solved.   ;D
Logged

RichardUK

  • Jr. Member
  • **
  • Helpful Post Rating: 0
  • Posts: 24
    • Whzan
Re: Visual Studio C++ express edition 2010
« Reply #11 on: July 26, 2010, 04:17:59 AM »

 That's a good comment, it's essentially a low cost web base offsite monitoring solution. The way it's constructed means that it does not matter what you're monitoring as the data format passed to the database is the same. It's the 'gateway' as we call it that abstracts out the hardware.

The problem it solves is in the PLC world it can be a high cost to remotely monitor, for example, production lines . They normally involve dedicated servers websites and the IT crowd that goes with it. Our solution is on the cloud so as long as you have a 'gateway' for your hardware, be it X10, Modbus or a custom hardware protocol you'll be able to at low setup and running costs monitor from off site. And as we use silverlight it looks really cool too. :)

If you have some X10 hardware I'll be grateful if you could try out the X10 gateway, free to download, and see what you think. Simple stuff like 'is it too confusing', are the tutorial videos helpful and the obvious one, does it work. I guess if you have no need to remotely check on you're X10 kit then it may not be for you. The X10 maybe missing some functionally so anything you need pop a message on the support forum and we'll add it. :)
Logged
Richard e Colins.
www.whzan.com

pconroy

  • Hero Member
  • *****
  • Helpful Post Rating: 9
  • Posts: 294
Re: Visual Studio C++ express edition 2010
« Reply #12 on: July 26, 2010, 05:18:37 PM »

That's a good comment, it's essentially a low cost web base offsite monitoring solution. The way it's constructed means that it does not matter what you're monitoring as the data format passed to the database is the same. It's the 'gateway' as we call it that abstracts out the hardware.

Interesting - that sounds a little similar to the approach I've taken for my own install.  I have a centralized HA server, in the basement, that accepts normalized data streams from a variety of clients.  The two clients, so far, are a weather station and X10 Controllers.  My idea was that you should be able to scatter as many clients around your house as you wanted, and they call "phone home" to a server.  That server is also my gateway to the outside world and exposes Web Services, http, etc.

I'm pretty much an all Linux install.
I'll take a peek at your site again.


Best wishes for a huge product success!
Logged
 

X10.com | About X10 | X10 Security Systems | Cameras| Package Deals
© Copyright 2014-2016 X10.com All rights reserved.