General area when it fits no where else

Moderator: Mmiscool

User avatar
By PhilTilson
#72474 The project I am working on is a water level sensor using ultrasonic detectors. That side of things is working fine; the problem is with the web page display.

In order to demonstrate the problem, I have cut the program down to the minimum. Here's the listing:
Code: Select allmemclear

v$ = ""
dtg$ = ""

serial2begin 9600, 12, 13

gosub [paintscreen]
timer 5000, [doit]
wait

[doit]
gosub [gettime]
gosub [getdata]
wait

[gettime]
dtg$ = time("day month year  hour:min:sec")
return

[getdata]
serial2print "U"
serial2input v$
return

[paintscreen]
cls
textbox dtg$
cssid htmlid(), "left: 0px; top: 0px; width: 140px;"
button "Exit", [TestExit]
cssid htmlid(), "background-color: green; color: white; left: 370px;"

gosub [gettime]
return

[TestExit]
serialprintln "Exit pressed!"
end


After initialising a couple of variables I open up the serial2 comms and call the routine to display the web page. In this cut down example, this is simply a text box, containing the time, and a button to exit the program.
SonicScreen.jpg

Then a timer call runs the [doit] routine every five seconds. This calls the [gettime] routine, to update the time and the [getdata] routine to get the sensor data. Again, I have cut down the [getdata] routine to a minimum, and it doesn't actually do anything. The normal operation is that I write a "U" character to the ultrasonic controller to trigger the sensor and then read the data that is returned. BUT...

...if I comment out the second line - serial2input v$ - the program works as expected. The web page displays with a text box showing the time immediately followed by a green Exit button. The time updates every five seconds and when I click the Exit button, the program terminates. Of course it does!

With that second line in place, however, things are quite different. The web page displays as before and, after five seconds, the time updates. But that's as far as it goes. The time then stays exactly the same and the green Exit button is inoperative. On the serial1 port, it then starts displaying "0 winsock connected 192.168.1.180" every second! The only way I can interrupt the program is to get back to the edit page and do a Save.

The question is, why on earth should reading the serial2 input cause this effect?

Before anyone asks, the actual routine to read the data and calculate the level works fine and I can output this information via the serial1 port - I just can't get round this web page display problem.

Any ideas?
You do not have the required permissions to view the files attached to this post.
User avatar
By Mmiscool
#72479 The serial data being received from the device probably dose not end an carage return line feed. With out that it stays in the input command untill it is received.

If you use the regular serial pins on the device or at least the regular serial input pin. Not serial 2 there are several functions to grab characters from the serial buffer with out the need for line termination.