I am in need of some help as I'm out of my area of expertise here!
I recently purchased THIS Ultrasonic Range Finder. I'm trying to use the serial port interface and place the range data into a HomeSeer device.
HERE is the data sheet for that sensor.
I have COM1 connected to the sensor as follows. Pin#2 to "TX", Pin#5 to "GND" and a wall wart outputing 5.45 volts DC to pins "+5" and "GND". I am leaving "RX" on the sensor unconnected.
When I connect to the sensor via HyperTerminal I get an "R" followed by three digits which represents "inches" as stated in the data sheet. I can move my hand up and down over the sensor and it registers the correct distance.
From the data sheet:
So now I'm trying to create a script using HomeSeer ver 1.7.44. I have installed 1.7.44 on a test machine (Windows XP with all latest SP's and updates) so I don't break my regular HomeSeer machine. Also, nothing else can conflict as this is the only scripting/application that this test HomeSeer is running.
I created two scripts as shown below. "Sonic1.txt" opens the Com Port One and (at least in my mind) gets the data until it receives a carriage return (ASCII 13), then calls the data handling subroutine "sonic" which is in "sonic2.txt" script.
There it places the "data" into HomeSeer device "R1" (I previously created a virtual R1 device in HomeSeer). Then that script closes the Com Port.
I created an event that runs the script "sonic1.txt" every ten seconds.
All works well till after a few minutes, then I get an error stating that "Com1 is already open".
I don't know what is wrong but I believe it has something to do with the way I'm opening and closing the com port, or the way I'm expecting the last ASCII character in my "hs.opencomportex" statement in the sonic1.txt script.
I know I get the "R" with the inches, but I wanted to get this working first before I figure out a way to trim the string to get the inches data only into the HomeSeer device.
Is this the best way to get this data from the sonic sensor? I don't need fast, but I'm not sure how to control its receive line to request only one reading. I thought the hsopencomportex statement would let me only read this device once as I'm looking for a carriage return as the terminating string (even though the sonic sensor is constantly spitting out data on the serial port).
sonic1.txt script: (runs every ten seconds via a HomeSeer Event)
sonic2.txt script:
Help as always is very appreciated! Oh yes, I did close down HyperTerminal before operating the scripts so nothing else is accessing the serial port #1.
Thanks,
BSR
I recently purchased THIS Ultrasonic Range Finder. I'm trying to use the serial port interface and place the range data into a HomeSeer device.
HERE is the data sheet for that sensor.
I have COM1 connected to the sensor as follows. Pin#2 to "TX", Pin#5 to "GND" and a wall wart outputing 5.45 volts DC to pins "+5" and "GND". I am leaving "RX" on the sensor unconnected.
When I connect to the sensor via HyperTerminal I get an "R" followed by three digits which represents "inches" as stated in the data sheet. I can move my hand up and down over the sensor and it registers the correct distance.
From the data sheet:
Range information is sent in the form of a capital "R", followed by three ASCII character digits representing the range in inches up to a maximum of 255, followed by a carriage return (ASCII 13). The RS 232 data is sent immediately after an object is detected.
I created two scripts as shown below. "Sonic1.txt" opens the Com Port One and (at least in my mind) gets the data until it receives a carriage return (ASCII 13), then calls the data handling subroutine "sonic" which is in "sonic2.txt" script.
There it places the "data" into HomeSeer device "R1" (I previously created a virtual R1 device in HomeSeer). Then that script closes the Com Port.
I created an event that runs the script "sonic1.txt" every ten seconds.
All works well till after a few minutes, then I get an error stating that "Com1 is already open".
I don't know what is wrong but I believe it has something to do with the way I'm opening and closing the com port, or the way I'm expecting the last ASCII character in my "hs.opencomportex" statement in the sonic1.txt script.
I know I get the "R" with the inches, but I wanted to get this working first before I figure out a way to trim the string to get the inches data only into the HomeSeer device.
Is this the best way to get this data from the sonic sensor? I don't need fast, but I'm not sure how to control its receive line to request only one reading. I thought the hsopencomportex statement would let me only read this device once as I'm looking for a carriage return as the terminating string (even though the sonic sensor is constantly spitting out data on the serial port).
sonic1.txt script: (runs every ten seconds via a HomeSeer Event)
Code:
sub main() e=hs.OpenComPortex(1,"9600,n,8,1",1,"sonic2.txt","sonic", chr(13), 1) if e<> "" then msgbox "Error opening COM1: " & e end sub
Code:
sub sonic (data) hs.setdevicestring "r1", data 'write string to Homeseer device "r1" hs.CloseComPort(1) end sub
Thanks,
BSR
Comment