Unoffical empeg BBS

Quick Links: Empeg FAQ | RioCar.Org | Hijack | BigDisk Builder | jEmplode | emphatic
Repairs: Repairs

Topic Options
#279020 - 04/04/2006 03:25 Noob programming question
lectric
pooh-bah

Registered: 20/01/2002
Posts: 2085
Loc: New Orleans, LA
OK, say I have a device that I connect to over ethernet. I use port 10001, and the device accepts strings of ascii text. To be more specific, I'm trying to control one of these to control, say, a jacuzzi. I need to be able to read things like water level, temp, jets status, etc.

If I want to send the command strings over the wire directly without using hyperterminal, hwo do I go about this? I have programmed before, but it's been about 15 years. Is there a good language that I should use? I'm thinking something along the lines of VB since that's the easiest for me to be able to create a small app without having to REALLY understand the underworkings of the OS. A friend asked me to help on this project, and while the hardware seems to be exactly what I need, I have NO idea how to interface it with the software.

Any hints/pointers would be GREATLY appreciated as the project itself would be quite interesting.

Top
#279021 - 04/04/2006 04:31 Re: Noob programming question [Re: lectric]
tonyc
carpal tunnel

Registered: 27/06/1999
Posts: 7058
Loc: Pittsburgh, PA
I don't know how advanced your needs are, but I think what you want can probably be done with a shell script (or possibly batch file) wrapper around Netcat. Unless you're really looking for a programming project, I'd give this a try.
_________________________
- Tony C
my empeg stuff

Top
#279022 - 04/04/2006 10:22 Re: Noob programming question [Re: tonyc]
mlord
carpal tunnel

Registered: 29/08/2000
Posts: 14493
Loc: Canada
sockcat is another alternative, similar to netcat but more powerful for TCP.

EDIT: correction, it is spelled socat.

Cheers


Edited by mlord (04/04/2006 15:30)

Top
#279023 - 04/04/2006 11:45 Re: Noob programming question [Re: tonyc]
lectric
pooh-bah

Registered: 20/01/2002
Posts: 2085
Loc: New Orleans, LA
Ahhh... cool. I was planning on writing a cute little proggie to control it but I'll tinker around with those to see how easy it is. Perhaps I will just write a bunch of scripts and call them directly from the program. The only issue I can think of is making it use user-customizeable values.

Top
#279024 - 04/04/2006 11:46 Re: Noob programming question [Re: lectric]
lectric
pooh-bah

Registered: 20/01/2002
Posts: 2085
Loc: New Orleans, LA
Hmmm... I should be able to make use of the %1 and %2 variables.

Top
#279025 - 04/04/2006 15:25 Re: Noob programming question [Re: lectric]
Anonymous
Unregistered


How about Tcl/Tk. It's a an interpreted dynamic language that is cross-platform, including Windows, Mac, and Linux.

There are two things that Tcl/Tk makes easy: sockets and graphical interfaces.

You can literally have a convo with your jacuzzi server and have a simple interface in 10 lines of code. And of course you can make it as complex as you need.

Check out tcl.tk. I use it a lot (as in everyday), so if you need any help or examples to start off, I can help you out.

Top
#279026 - 04/04/2006 21:14 Re: Noob programming question [Re: ]
lectric
pooh-bah

Registered: 20/01/2002
Posts: 2085
Loc: New Orleans, LA
Will do. Thanks for the pointers.

Top
#279027 - 04/04/2006 22:27 Re: Noob programming question [Re: lectric]
DWallach
carpal tunnel

Registered: 30/04/2000
Posts: 3810
Furthermore, depending on the complexity of the protocol of your controller, Tcl/Tk has an extension called Expect that's all about saying "wait for this, then send that, then wait for this, and then send that".

Top
#279028 - 05/04/2006 17:25 Re: Noob programming question [Re: lectric]
Anonymous
Unregistered


To give you an example of how easy it'll be to get started, here's some example code:

Code:
 
# Create a procedure to connect to the device.
proc openConnection {address} {

# Open a connection to the device and save the socket handle in the local var $sock.
set sock [socket $address 10001]

# Configure the connection.
fconfigure $sock -buffering line -blocking false

# Setup an event callback that will be triggered whenever data is received from the device.
fileevent $sock readable [list showOutput $sock]

return $sock
}

# Create a procedure to display output from the device.
proc showOutput {sock} {

# Put what the device sent us into our text box.
.textbox insert end [read $sock]

# Check if the connection has been closed.
if { [eof $sock] } {
close $sock
.textbox insert end "The device has been disconnected."
}
}

# Create a procedure to routinely check the status of a relay on the device.
proc getStatus {sock} {

# Check if the connection is still open.
if { [lsearch -exact [file channels] $sock] > -1 } {

# Get the status of relay 1 on the device.
puts $sock 1sR

# Call this procedure again in ten seconds.
after 10000 [list getStatus $sock]
}
}


# Show the console so that you can interactively type commands.
catch {console show}

# Create a simple text box.
pack [text .textbox]

# Connect to the device
set sock [openConnection jacuzzi.net]

# Activate relay 1.
puts $sock 1r1

# Get the status of the device every 10 seconds.
getStatus $sock




It's a little more than 10 lines of code (19 to be exact, excluding comments & formatting), but of course I added more than is necessary, but this is still a simple example.

As DWallach mentioned, Expect is a nice tool that may make things easier for you. Expect is probably more widely known among developers than the language it was written in. But it's not like Tcl is difficult to learn, and Expect is used mostly for testing applications.

I hope this helps. I know it's always fun programmatically controlling things other than computer monitors.

Top
#279029 - 05/04/2006 23:32 Re: Noob programming question [Re: ]
lectric
pooh-bah

Registered: 20/01/2002
Posts: 2085
Loc: New Orleans, LA
Excellent. Thank you very much. Unfortunately for me, it has apparently been FAAAR too long since I programmed. At least, without a book next to me. Looks like I need to go buy a TCL/TK for dummies book.

Top