|
I'm trying to write some simple Visual Basic instructions to an Ocelot. I can open a serial port OK and send to it but I can't get anything to happen. The example I'll post is to send X10 C1, C ON. I'm using the current serial protocol so I'm doing this:
ocelotSP = New SerialPort() ocelotSP.PortName = "com8" ocelotSP.BaudRate = 9600 ocelotSP.ReadTimeout = 500 ocelotSP.WriteTimeout = 500
bit1 = Chr(200) bit2 = Chr(55) house = Chr(2) ' house code C key = Chr(0) ' unit code 1 repeat = Chr(1) dbzero = Chr(0) checksum = Chr(2) x10commandstring = bit1 & bit2 & house & key & repeat & dbzero & dbzero & checksum key2 = Chr(18) checksum2 = Chr(20)
x10commandstring2 = bit1 & bit2 & house & key2 & repeat & dbzero & dbzero & checksum2
Then when a button is clicked in the application I do this to send C1:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ocelotSP.Open() ocelotSP.WriteLine(x10commandstring)
ocelotSP.Close()
End Sub
And then this:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click ocelotSP.Open() ocelotSP.WriteLine(x10commandstring2)
ocelotSP.Close() End Sub
The network lights flash so something goes (I use the Ocelot on a network attached via a serial port convertor)
The thing I don't get is when I also set up a button in the application to send the "old" ASCII code to do the same command it works just fine:
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click ocelotSP.Open() ocelotSP.WriteLine("+X020001") ' send C1 by ascii (old method) ocelotSP.WriteLine("+X021801") ' send C ON by ascii (old method) ocelotSP.Close() End Sub
Excuse the clunky VB programming but this is a new hobby for me!
I kept thinking that the construction of the string I'm sending must be wrong but I don't see how.
All help gratefully received.
Edited by Mark L (11/29/08 05:07 AM)
|