ADICON Support Forum Applied Digital, Inc.
Page 1 of 1 1
Topic Options
#20598 - 11/29/08 05:06 AM Problems with serial port commands
Mark L Offline
journeyman


Registered: 11/21/03
Posts: 57
Loc: Banbury, UK
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)

Top
#20599 - 11/29/08 09:07 AM Re: Problems with serial port commands [Re: Mark L]
Guy Lavoie Administrator Offline
Beyond All Hope
*****

Registered: 12/21/02
Posts: 6401
Loc: Montreal, QC, Canada
One difference between your two examples is that in the non-working one, you are concatenating the string segments, and are using an ampersand. Try a plus sign instead. ie:

x10commandstring = bit1 + bit2 + house + key + repeat + dbzero + dbzero + checksum
_________________________
"If you don't know what you're doing, do it neatly..."

Top
#20603 - 11/30/08 12:44 AM Re: Problems with serial port commands [Re: Guy Lavoie]
Mark L Offline
journeyman


Registered: 11/21/03
Posts: 57
Loc: Banbury, UK
Thanks for the idea but that didn't work. There is an alternative way of string concatenation using the string class, that didn't work either. Have I somthing wrong in the actual string I am sending?
Top
#20605 - 11/30/08 06:34 PM Re: Problems with serial port commands [Re: Mark L]
Guy Lavoie Administrator Offline
Beyond All Hope
*****

Registered: 12/21/02
Posts: 6401
Loc: Montreal, QC, Canada
The string itself looks ok, although I have not tested it myself. I'll see if I can test it in the next couple of days. I (still) use VB5 but the string itself should be the same.
_________________________
"If you don't know what you're doing, do it neatly..."

Top
Page 1 of 1 1


Moderator:  Dan Smith, Monte G, ADI Tech Support, Guy Lavoie 
Hop to:
Who's Online
1 registered (John Vomastic) and 21 anonymous users online.
Recent Posts
SECU16IR Output Connecting To A Xantech Connecting Block
by Jean-Marie
Today at 08:36 AM
SECU16IR Output Connecting To A Xantech Connecting Block
by Jean-Marie
Today at 08:34 AM
how to post an icon
by manu
02/03/12 03:40 AM
Command Pair
by kuro
02/01/12 12:49 AM
Does anyone have a copy of the latest TSE?
by sevenzenith1
01/30/12 05:17 AM
Shout Box

Newest Members
feshh, manu, kuro, chuck214, Funkhauser
2747 Registered Users
Forum Stats
2747 Members
19 Forums
3837 Topics
22713 Posts

Max Online: 67 @ 08/16/11 03:08 PM
February
Su M Tu W Th F Sa
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29