Please login or register.

Login with username, password and session length
Advanced search  

News:

The New WIFI Module is now available!
                   *****Here's the link******

Pages: [1] 2

Author Topic: How are we supposed to send RAW commands?  (Read 11620 times)

rockinthesixstring

  • Jr. Member
  • **
  • Helpful Post Rating: 0
  • Posts: 24
How are we supposed to send RAW commands?
« on: November 11, 2012, 05:12:45 PM »

I've spent two days on this and have come up empty.

tl;dr
I really want to be able to sendrawplc commands with my app, but I can't figure out how.

long version
I've been researching as much as possible, I've looked through the help file, and I've searched on these forums as well as others. I did find a raw command [ sendrawplc 07 67 0E 1F 31 ] to experiment with from this thread, but it doesn't say what command it is, nor how to achieve the desired hex codes.

Now I'm assuming that my code is all wrong (since THIS DOES NOT WORK - [for emphasis so that no one else copy/pastes it]), but I can't find the right way.

Here's what I'm currently trying.


First I post three fields to the controller

  • SendAction = "sendrawplc"
  • Device = "A1"
  • Command = "On"

Code: (csharp) [Select]
       // POST api/<controller>
        public StatusModel Post(CommandModel command)
        {
            // create active home object
            var activeHome = new ActiveHomeClass();
            
            // convert input to hex
            var hex = String.Format("{0} {1}", command.Device.ToUpper(), command.Command.ToUpper()).ToHex();

            // execute command
            var info = (int)activeHome.SendAction(command.SendAction, hex, null, null);

            // return results
            var status = new StatusModel { Device = command.Device, Status = info };

            // clear active home object
            activeHome = null;

            // send the status back to the client
            return status;
        }

ToHex() Version "A"
Code: (csharp) [Select]
       public static string ToHex(this string input)
        {
            byte[] bytes = new byte[input.Length * sizeof(char)];
            System.Buffer.BlockCopy(input.ToCharArray(), 0, bytes, 0, bytes.Length);

            var builder = new StringBuilder();
            foreach (var letter in bytes)
            {
                uint value = Convert.ToUInt32(letter);
                builder.Append(String.Format("{0:X}", value));
                builder.Append(" ");
            }

             return (builder.ToString()).TrimEnd();
        }

ToHex() Version "B"
Code: (csharp) [Select]
       public static string ToHex(this string input)
        {
            var hex = input.ToCharArray();

            var builder = new StringBuilder();
            foreach (var letter in hex)
            {
                uint value = Convert.ToUInt32(letter);
                builder.Append(String.Format("{0:X}", value));
                builder.Append(" ");
            }

            return (builder.ToString()).TrimEnd();
        }

Neither of those two [ToHex] methods work.
My encoded string looks like [ sendrawplc 41 31 20 4F 4E] and [ sendrawplc 41 0 31 0 20 0 4F 0 4E 0] respectively, but nether one of those actually turn on my lights at address A1.

What am I doing wrong?
« Last Edit: November 11, 2012, 05:22:21 PM by rockinthesixstring »
Logged

spval

  • Full Member
  • ***
  • Helpful Post Rating: 1
  • Posts: 30
Re: How are we supposed to send RAW commands?
« Reply #1 on: November 12, 2012, 06:18:22 AM »

You gave me a project to work on this morning. I have never used "sendrawplc", but I had fun getting it to work. I don't program in C#. I converted my VB.NET to C# in my example. You can probably figure it out:

VB.NET:
Imports ActiveHomeScriptLib
Imports System.Threading
Public Class Form1
    Dim WithEvents ActiveHomeObj As ActiveHomeScriptLib.ActiveHome
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ActiveHomeObj = New ActiveHome
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        ActiveHomeObj.SendAction("sendrawplc", "04 66") ' turn A1 ON
        ActiveHomeObj.SendAction("sendrawplc", "06 62")
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        ActiveHomeObj.SendAction("sendrawplc", "04 66") ' turn A1 Off
        ActiveHomeObj.SendAction("sendrawplc", "06 63")
    End Sub

End Class


********************************************************************************************
C#:
using ActiveHomeScriptLib;

public class Form1

{
   
ActiveHomeScriptLib.ActiveHome ActiveHomeObj;

   private void  // ERROR: Handles clauses are not supported in C#

Form1_Load(object sender, EventArgs e)

   {

      ActiveHomeObj = new ActiveHome();

   }

   
private void  // ERROR: Handles clauses are not supported in C#

Button1_Click(object sender, EventArgs e)

   {

      ActiveHomeObj.SendAction("sendrawplc", "04 66");

      // turn A1 ON

      ActiveHomeObj.SendAction("sendrawplc", "06 62");

   }


   private void  // ERROR: Handles clauses are not supported in C#

Button2_Click(object sender, EventArgs e)

   {

      ActiveHomeObj.SendAction("sendrawplc", "04 66");

      // turn A1 Off
   
           ActiveHomeObj.SendAction("sendrawplc", "06 63");

   }


}

*************************************************************************************************
Examples:

A1 ON:
  ActiveHomeObj.SendAction("sendrawplc", "04 66")
  ActiveHomeObj.SendAction("sendrawplc", "06 62")

A1 OFF:
 ActiveHomeObj.SendAction("sendrawplc", "04 66")
 ActiveHomeObj.SendAction("sendrawplc", "06 63")



A5 ON:
   ActiveHomeObj.SendAction("sendrawplc", "04 61")
   ActiveHomeObj.SendAction("sendrawplc", "06 62")

A5 OFF:
  ActiveHomeObj.SendAction("sendrawplc", "04 61")
  ActiveHomeObj.SendAction("sendrawplc", "06 63")

C1 ON:
 ActiveHomeObj.SendAction("sendrawplc", "04 26")
 ActiveHomeObj.SendAction("sendrawplc", "06 22")

C1 OFF:
  ActiveHomeObj.SendAction("sendrawplc", "04 26")
  ActiveHomeObj.SendAction("sendrawplc", "06 23")
Logged

rockinthesixstring

  • Jr. Member
  • **
  • Helpful Post Rating: 0
  • Posts: 24
Re: How are we supposed to send RAW commands?
« Reply #2 on: November 12, 2012, 09:50:02 AM »

Thank you for this, can you please explain your code?

eg:

  • Why is `04 66` = 'A1'... or is it?
  • I assume that `06 62` is on and `06 63` is off, but what are the rest of the commands?
  • What about all the other house codes? How did you generate them, or locate their corresponding numbers?
    • A2, A3, A4...
    • B1, B2, B3...
  • Lastly, why do they need to be broken into two separate `SendAction`s?

Thanks for getting as far as you did! I tested your A1 and it worked.
« Last Edit: November 12, 2012, 09:53:16 AM by rockinthesixstring »
Logged

spval

  • Full Member
  • ***
  • Helpful Post Rating: 1
  • Posts: 30
Re: How are we supposed to send RAW commands?
« Reply #3 on: November 12, 2012, 10:38:02 AM »

This is going back to the x10 protocol from ions ago. There is info on the web about it. You can spend many hours trying to figure it out. Let me try to speed things up. This is an event that was generated while sending a "C1 ON" command to a CM11A interface:

CM11 <-- 04 26 ("C1" command)
CM11 --> 2A (checksum)
CM11 <-- 00 (acknowledging checksum)
CM11 --> 55 (acknowledgement reply)
CM11 <-- 06 22 ("C.On" command)
CM11 --> 28 (checksum)
CM11 <-- 00 (acknowledging checksum)
CM11 --> 55 (acknowledgement reply)

Look at the left and right arrows. The pc sending code (your C#) is the left arrows and the response from the CM11A interface is the right arrows.
So, in your case you generate a Hex "04 26", a Hex "00" (which wasn't required while testing the command), a Hex "06 22" (which is the On code) and finally a Hex "00" (which wasn't required while testing the command).

This is the important info taken from the x10 protocol page:

The housecodes and device codes range from A to P and 1 to 16 respectively although they do not follow a binary sequence. The encoding format for these codes is as follows

   Housecode   Device Code   Binary Value
   A      1      0110
   B      2      1110
   C      3      0010
   D      4      1010
   E      5      0001
   F      6      1001
   G      7      0101
   H      8      1101
   I      9      0111
   J      10      1111
   K      11      0011
   L      12      1011
   M      13      0000
   N      14      1000
   O      15      0100
   P      16      1100

1.2   Function Codes.

   Function         Binary Value
   All Units Off         0000
   All Lights On         0001
   On            0010
   Off            0011
   Dim            0100
   Bright            0101
   All Lights Off         0110
   Extended Code         0111
   Hail Request         1000
   Hail Acknowledge                    1001
   Pre-set Dim (1)         1010
   Pre-set Dim (2)         1011
   Extended Data Transfer      1100
   Status On         1101   
   Status Off         1110
   Status Request         1111

Rather than trying to figure out what the Hex values are for a particular HouseCode and Device Number, I just used a program where I typed in the HC and Device number and let the program convert it to Hex automatically, and then the program would show me the hex code once the command was sent. I used a CM11A interface at the time. Do you by chance have one ? If so, I'll provide you with the program if you would like.
« Last Edit: November 12, 2012, 11:07:59 AM by spval »
Logged

Brian H

  • Community Organizer
  • Hero Member
  • **
  • Helpful Post Rating: 282
  • Posts: 12176
Re: How are we supposed to send RAW commands?
« Reply #4 on: November 12, 2012, 10:49:02 AM »

Dave Houston.
Has a few of the X10 protocol information on his web site.
http://www.davehouston.net/
Logged

rockinthesixstring

  • Jr. Member
  • **
  • Helpful Post Rating: 0
  • Posts: 24
Re: How are we supposed to send RAW commands?
« Reply #5 on: November 12, 2012, 12:50:45 PM »

@spval, I have a CM15A, but your original A1 On command worked through it just fine.

You're right in staying that I need to simply send the HC and Device code to a hex converter and see how it goes.

My assumption therefore is that instead of sending "A1 On" to my `ToHex()` method, I should be sending "0110 1 0010" ([HC] [DC] [FC]) to my `ToHex()` method... is that correct? Now unfortunately I'll have to figure out what conversion code is needed to get the appropriate output.
Logged

spval

  • Full Member
  • ***
  • Helpful Post Rating: 1
  • Posts: 30
Re: How are we supposed to send RAW commands?
« Reply #6 on: November 12, 2012, 01:02:46 PM »

I'm sorry, but I can't help you with your format of sending Hex. Looks more like a question for a C# forum, but I believe that you have the wrong idea there for generating the Hex bytes that you are looking for. If you don't want to figure out the protocol, then you need some sort of a sniffer that will capture the x10 event in Hex. May I suggest downloading the free trial of "Device Monitoring Studio" by HHD software ?
http://www.hhdsoftware.com/Downloads   I haven't used it for USB capturing (CM15A), just Serial. So, if you generated a "ActiveHomeObj.SendAction("sendplc", "a1 on");, then you should see the Hex equivalent that is sent to the CM15A. It should work great for you. Otherwise, if you want to provide me a list of HC / Device codes and functions that you need to get you going, I can get the Hex codes for you.

« Last Edit: November 12, 2012, 01:48:57 PM by spval »
Logged

rockinthesixstring

  • Jr. Member
  • **
  • Helpful Post Rating: 0
  • Posts: 24
Re: How are we supposed to send RAW commands?
« Reply #7 on: November 12, 2012, 01:45:05 PM »

I'm sorry, but I can't help you with your format of sending Hex. Looks more like a question for a C# forum, but I believe that you have the wrong idea there for generating the Hex bytes that you are looking for. If you don't want to figure out the protocol, then you need some sort of a sniffer that will capture the x10 event in Hex. May I suggest downloading the free trial of "Device Monitoring Studio" by HHD software ?
http://www.hhdsoftware.com/Downloads   I haven't used it for USB capturing (CM15A), just Serial. It should work great for you. Otherwise, if you want to provide me a list of HC / Device codes and functions that you need to get you going, I can get the Hex codes for you.

Yeah, I think I'm just a little confused on the whole thing. My track of thinking is of JOINING the three strings.

[HC][DC] [FC]

as in [A][1] [On]
is the same as [0110][1] [0010]

But I must be off here.

I don't really care about language per-se as I can read VB, or figure out PHP, Ruby, or whatever. The problem is HOW are we converting the [hc][dc] and [fc] binary that you showed into the raw hex that the method requires. It's just not translating in my head.

Basically, how did you get 04 66 (used in your ActiveHomeObj.SendAction("sendrawplc", "04 66"))
from 0110 1 (described in the table that you posted.)?

The end result is that I'm wiring up a C# wrapper around ALL of the required commands. Basically all HC, DC and FC commands need to be recognized in my library.
« Last Edit: November 12, 2012, 01:51:13 PM by rockinthesixstring »
Logged

rockinthesixstring

  • Jr. Member
  • **
  • Helpful Post Rating: 0
  • Posts: 24
Re: How are we supposed to send RAW commands?
« Reply #8 on: November 12, 2012, 01:48:09 PM »

Quote
Rather than trying to figure out what the Hex values are for a particular HouseCode and Device Number, I just used a program where I typed in the HC and Device number and let the program convert it to Hex automatically, and then the program would show me the hex code once the command was sent. I used a CM11A interface at the time. Do you by chance have one ? If so, I'll provide you with the program if you would like.

Since I have a CM15A, I'd like to try your program if you can point me in the right direction, all though it would be nicer in the long run for me to be able to do this conversion on my own. This way "if" more commands are added to the SDK, I can just plug the new commands into a config file and be off to the races..
Logged

spval

  • Full Member
  • ***
  • Helpful Post Rating: 1
  • Posts: 30
Re: How are we supposed to send RAW commands?
« Reply #9 on: November 12, 2012, 01:56:16 PM »

I understand. The program that I was referring to was only for the CM11A (it captures the hex codes that both the CM15A and the CM11A use). I added to my last post " So, if you generated a "ActiveHomeObj.SendAction("sendplc", "a1 on");, then you should see the Hex equivalent that is sent to the CM15A.
Logged

rockinthesixstring

  • Jr. Member
  • **
  • Helpful Post Rating: 0
  • Posts: 24
Re: How are we supposed to send RAW commands?
« Reply #10 on: November 12, 2012, 02:05:23 PM »

I understand. The program that I was referring to was only for the CM11A (it captures the hex codes that both the CM15A and the CM11A use). I added to my last post " So, if you generated a "ActiveHomeObj.SendAction("sendplc", "a1 on");, then you should see the Hex equivalent that is sent to the CM15A.

So do I do that with a copy of "Device Monitoring Studio"?
Logged

rockinthesixstring

  • Jr. Member
  • **
  • Helpful Post Rating: 0
  • Posts: 24
Re: How are we supposed to send RAW commands?
« Reply #11 on: November 12, 2012, 02:10:20 PM »

I understand. The program that I was referring to was only for the CM11A (it captures the hex codes that both the CM15A and the CM11A use). I added to my last post " So, if you generated a "ActiveHomeObj.SendAction("sendplc", "a1 on");, then you should see the Hex equivalent that is sent to the CM15A.

So do I do that with a copy of "Device Monitoring Studio"?

Ok, so yeah, running that software is showing me the commands sent. I wish I knew the conversion code so that I could do it without having to sniff every call, but alas, this will do just fine. Maybe I'll post all of my results in another thread for the next guy to see.
Logged

spval

  • Full Member
  • ***
  • Helpful Post Rating: 1
  • Posts: 30
Re: How are we supposed to send RAW commands?
« Reply #12 on: November 12, 2012, 02:14:09 PM »

So, you have Device Monitoring Studio running and you captured a command ?
Logged

rockinthesixstring

  • Jr. Member
  • **
  • Helpful Post Rating: 0
  • Posts: 24
Re: How are we supposed to send RAW commands?
« Reply #13 on: November 12, 2012, 02:23:12 PM »

So, you have Device Monitoring Studio running and you captured a command ?

Yep, sure did. This is a good runner-up method to my original need of doing all the conversions programmatically. I can be happy with this for sure. Thanks for all your help.

PS:
do you know how to string multiple commands together on a single `sendrawplc` call?
I guess that's the whole reason I'm going down this rabbit trail in the first place.

IE: I'd like to combine

Code: [Select]
sendplc a1 on
 sendplc a4 on
 sendplc a3 dim 20

all into a single call. That way... "hopefully", all the modules will react simultaneously.

When I try and call all of those methods individually, I have to delay it a bit, but I see in AHP that I can group all three into something like "G1 on" that will fire those. I'm assuming that AHP is stringing the calls using the sendrawplc command.

note: I'm trying to avoid using AHP or even installing it for that matter.
Logged

spval

  • Full Member
  • ***
  • Helpful Post Rating: 1
  • Posts: 30
Re: How are we supposed to send RAW commands?
« Reply #14 on: November 12, 2012, 02:41:44 PM »

You had better do all of your research before the trial period ends !
I have always put up with the delay when stringing multiple commands together. In fact, I padded them with thread.sleep values in between each command, just to make sure that I didn't lock up the interface. If you have some sort of x10 controller and you set two devices with different codes to go on at the same time, is there any delay ?. I just have the sdk installed and no AHP. You should be able to create anything that AHP can do.

Logged
Pages: [1] 2
 

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