// 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;
}
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();
}
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();
}
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.
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.
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.
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"?
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.
sendplc a1 on
sendplc a4 on
sendplc a3 dim 20
You had better do all of your research before the trial period ends !Yeah, I'm gonna cut my teeth into this tonight when I get off work. I'll run the AHP software through the sniffer and see what comes out. AHP doesn't "seem" to have a delay in my setup. When I say "Living Room Lights On", my lamp module and my two light switches appear to receive and execute the commands at the same time.
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.
04 66 06 62
04 6e 06 62
04 62 06 62
04 6a 06 62
04 61 06 62
04 69 06 62
04 65 06 62
04 6d 06 62
04 67 06 62
04 6f 06 62
04 63 06 62
04 6b 06 62
04 60 06 62
04 68 06 62
04 64 06 62
04 6c 06 62
04 e6 06 e2
04 ee 06 e2
04 e2 06 e2
04 ea 06 e2
04 e1 06 e2
04 e9 06 e2
04 e5 06 e2
04 ed 06 e2
04 e7 06 e2
04 ef 06 e2
04 e3 06 e2
04 eb 06 e2
04 e0 06 e2
04 e8 06 e2
04 e4 06 e2
04 ec 06 e2
ahsdk.SendAction("sendplc", "A1 ON");
//wait for a "0" response
ahsdk.SendAction("sendplc", "A2 DIM 20");
// rinse / repeat
ahsdk.SendAction("sendplc", "[{A1 ON}, {A2 DIM 20]}");
Housecode Device Code Binary Value Hex Value
A 1 0110 6
B 2 1110 E
C 3 0010 2
D 4 1010 A
E 5 0001 1
F 6 1001 9
G 7 0101 5
H 8 1101 D
I 9 0111 7
J 10 1111 F
K 11 0011 3
L 12 1011 B
M 13 0000 0
N 14 1000 8
O 15 0100 4
P 16 1100 C