Jump to content

Read and write on the same form


Mark Wheeler

Recommended Posts

Here is a niggling problem I have with an embedded web server.The issue i am having is when I submit my form the form data is submitted to the web server, the web server updates a duel port RAM chip and will then read from that duel port RAM. The problem is the action of reading and writing to the duel port RAM causes a delay in data being passed back to and Web Server.If I write for example the value selected in the option list and submit the form the value is written to the server and when the form reloads it attempt to read the values written from the duel port RAM. The problem is that I always get the previously stored value because the Web server updates quicker than the RAM updates. If I hit the submit button twice the value is read back fine.I put in a breakpoint in the ReadReadBlock but it shows the previous read so I know the problem is due to the slow update from the RAM to the Web server.How can I get around the delay between submitting the form and reading the data back when the form loads.Below is my HTML and Javascript and was hoping that something could give me some pointers.Write to server function is<?--#exec cmd_argument='scanf("parameter", "%u", OutWriteword( 0 ))'-->Read from server function is<?--#exec cmd_argument='printf("%i",InReadUword(44))'-->Many thanks

<!DOCTYPE html><head><link rel="stylesheet" type="text/css" href="../css/styles.css" media="screen"><title>BW500</title><script type="text/javascript" src="js/convert.js"></script><script>window.addEventListener('load',ReadReadBlock)</script></head><body><form action="test.html" method="post" id="spa" ><input type="text" id="r_parameter" name="r_parameter"value="<?--#exec cmd_argument='printf("%i",InReadUword(44))'-->"></input><input type="text" id="r_dp" name="r_dp"value="<?--#exec cmd_argument='printf("%i",InReadUword(54))'-->"></input><input type="text" id="r_priindex" name="r_priindex"value="<?--#exec cmd_argument='printf("%i",InReadUword(46))'-->"></input><input type="text" id="r_valueread" name="r_valueread"value="<?--#exec cmd_argument='printf( "%d",InReadUlong(50))'-->"></input><select name="parameter" id="parameter" onChange="WriteWriteBlock()"><option value="911">mA output</option><option value="914">mA input Value</option><option value="918">Speed Frequency</option><option value="940">Load Cell mV</option><option value="943">A/D Reference</option><option value="367">Direct Zero</option><option value="368">Direct Span</option><option value="377">Inital Zero</option><option value="378">Inital Span</option><option value="950">Zero Register</option><option value="951">Span Register</option><option value="341">Days of Service</option><option value="948">Error Log</option></select><select name="pri" id="pri"><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="5">5</option></select><input type="hidden" name="dp" id="dp"></input><input type="submit" value="Submit"></input></form><?--#exec cmd_argument='scanf("parameter", "%u", OutWriteword( 0 ))'--><?--#exec cmd_argument='scanf("priindex", "%u", OutWriteword(2))'--><?--#exec cmd_argument='scanf("dp", "%u", OutWriteword(10))'--></body></html>
function ReadReadBlock(p,pr,d,value_in){p= document.getElementById('r_parameter').value;pr= document.getElementById('r_priindex').value;d = document.getElementById('r_dp').value;value_in= document.getElementById('r_valueread').value;switch (p){case "911": /mA output/document.getElementById('parameter').selectedIndex = 0;document.getElementById("pri").disabled = false;document.getElementById("r_dp").value = 2;d=2;break;case "914": /mA input/document.getElementById('parameter').selectedIndex = 1;document.getElementById("pri").disabled = false;document.getElementById("r_dp").value = 2;d=2;break;case "918": /Speed Input/document.getElementById('parameter').selectedIndex = 2;document.getElementById("pri").disabled = false;document.getElementById("r_dp").value =2;d=2;break;case "940":/Loadcell mV/document.getElementById('parameter').selectedIndex = 3;document.getElementById("pri").disabled = false;document.getElementById("r_dp").value = 2;d=2;break;case "943": /AD Referonce/document.getElementById('parameter').selectedIndex = 4;document.getElementById("pri").disabled = false;document.getElementById("r_dp").value = 0;d=0;break;case "367": /Direct Zero/document.getElementById('parameter').selectedIndex = 5;document.getElementById("pri").disabled = true;document.getElementById("r_dp").value = 0;d=0;break;case "368":/Direct Span/document.getElementById('parameter').selectedIndex = 6;document.getElementById("pri").disabled = false;document.getElementById("r_dp").value = 0;d=0;break;case "377": /Inital Zero/document.getElementById('parameter').selectedIndex = 7;document.getElementById("pri").disabled = false;document.getElementById("r_dp").value = 0;d=0;break;case "378":/Inital Span/document.getElementById('parameter').selectedIndex = 8;document.getElementById("pri").disabled = false;document.getElementById("r_dp").value = 0;d=0;break;case "950": /Zero Register/document.getElementById('parameter').selectedIndex = 9;document.getElementById("pri").disabled = false;document.getElementById("r_dp").value = 0;d=0;break;case "951":/Span Register/document.getElementById('parameter').selectedIndex = 10;document.getElementById("pri").disabled = false;document.getElementById("r_dp").value = 0;d=0;break;case "341": /Days of Service/document.getElementById('parameter').selectedIndex = 11;document.getElementById("pri").disabled = true;document.getElementById("r_dp").value = 0;d=0;break;case "948": /error log/document.getElementById('parameter').selectedIndex = 12;document.getElementById("pri").disabled =false;document.getElementById("r_dp").value = 0;d=0;break;}switch (d){case 0:document.getElementById("r_valueread").value=value_in;break;case 1:document.getElementById("r_valueread").value=value_in/10;break;case 2:document.getElementById("r_valueread").value=value_in/100;break;case 3:document.getElementById("r_valueread").value=value_in/1000;break;}}
Edited by Mark Wheeler
Link to comment
Share on other sites

 

I put in a breakpoint in the ReadReadBlock but it shows the previous read so I know the problem is due to the slow update from the RAM to the Web server.

 

You seem to be saying that the embedded web server is not working correctly? That it sends a premature and defective response to the browser?

Edited by davej
Link to comment
Share on other sites

Hi DaveJThanks very much for the reply.The web server is just reading old data in the RAM because the RAM is slow to update the web server hence the delay.On the second time the submit button is pressed the data has been updated in the RAM so the Web server reads the updated data.When I submit the form I do get a responce back in the form that states "Write OK", is it possible to capture that returned status and maybe then I could send the read function to the server with the <?--#exec cmd_argument='printf("%i",InReadUword(44))'--> to get the updated data ?Mark

Link to comment
Share on other sites

HI DaveJI really appreciate your help on this one as my knowledge of HTML is just as a beginer and i'm not really clear on the event handling on the Web server.The Embedded Web server is part of a module called an Anybus S interface from HMS Industrial Networks. The module fits into a piece of your own hardware to allow the hardware to connect to an industrial network, In this case I have the board in a weighing system.the module ishttp://www.hms.se/products/products.asp?PID=94&ProductType=Anybus-SThe actual delay will be from the weighing harware updating the duel port RAM. When the weighing hardware is written to by the Anybus Module (Web Server) it will respond around 800mS later. The delay causses the Web Sever on the Anybus module to refresh before the update from the duel port RAM.When I write to the server and get the "write OK" back in my page can I capture this and trigger a function which I can then send the read command to the Web Server?Once again thanks for your interst and help with this problem.Mark

Link to comment
Share on other sites

Hi Davej

 

Here is a cut down version of my code

The input box on the left is the value read from the server

The input box on the right is the value to be written to the server.

If you enter 200 in the write box and hit sumit the value will be sent to the server

You will see that the read input box will still read the previous value.

Hit the submit button again and you will see the value 200 appear.

 

If you do get a spare moment and would like to take a look at the page on my test module

http://24.235.162.16:1066/testme.html

 

 

 <!DOCTYPE html><head>    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    <title>testme</title></head>    <body>         <form action="testme.html" method="post" id="testme" >                             <input type="text" id="read" name="read"                 value="<?--#exec cmd_argument='printf("%i",InReadUword(44))'-->"></input>             <input type="text" name="write" id="write"></input>                 <?--#exec cmd_argument='scanf("write", "%u", OutWriteword( 0 ))'-->            <input type="submit" value="Submit"></input>     </form>            </body></html> 
Link to comment
Share on other sites

Hi DavejThese commands are used to read and write to the web server.printf is used to display data read from the web server.scanf reads the contents of the nameed input box and writes it to the server.You will see that the Read input box is updated after the second time the submit button is pressed.Mark

Link to comment
Share on other sites

Hi Davejthey just list the funtions in the manual and not much detailI put a call in today so i am awaiting a reply.still trying a few things, i will update thepost when i have something.Thanks for your help on this DavejMark

Link to comment
Share on other sites

The confusing thing to me is that it looks like your server-side language is perhaps c. Well then hopefully they have written some examples showing how to manage sessions or log-ins or do other things that are normally done in a server-side language such as Php?

Link to comment
Share on other sites

  • 1 month later...

HI DavejI have been away for a few weeks and tonight was my first time I have had chance to look at my project.I think I may have narrowed the problem down to the input fields.I think what is happening is that the fields are holding the data from the previous submit, it's like the input fields are being cached in some way but i'm not entirely sure.

 <form action="testme.html" method="post" id="testme" >                             <input type="text" id="read" name="read"                 value="<?--#exec cmd_argument='printf("%i",InReadUword(44))'-->"></input>             <input type="text" name="write" id="write"></input>                 <?--#exec cmd_argument='scanf("write", "%u", OutWriteword( 0 ))'-->            <input type="submit" value="Submit"></input>
I'm not sure if the is a way to get around this.Once again thanks for your help, I did call HMS but not much luck i'm afraidMark Edited by Mark Wheeler
Link to comment
Share on other sites

I guess I'm confused about what the most essential problem is. You have a form which you submit to the embedded webserver board. The form tries to use some c-code to insert some field values into the form. It fails to do so. Does this matter?

 

How do you write code on the webserver to process a form? Is there no documentation? Can you observe the board (perhaps with a debugger?) to see if posting the form produces the desired result? The form below is submitted to an action of testme.html. Is this the file's own name or is it a different file containing different c-code?

 

Does the form still work (produce the desired result) if you strip out the c-code as shown below?

<form action="testme.html" method="post" id="testme" >                    <input type="text" id="read" name="read"/>    <input type="text" name="write" id="write"/>    <input type="submit" value="Submit"/></form>
Link to comment
Share on other sites

  • 1 month later...

Just an update on my problem.

 

I have used Wireshark to look at the data to and from the Web Server and I see the problem but don’t know how to fix it.

 

When the form is submitted

1 submit > data to the web server requesting a parameter

2 response from the server with current data in RAM but this is not the requested parameter but the previous parameter from the last request.

3 submit > data to web server requesting a parameter

4 response from the server with the updated value in RAM from my request in step 1

 

The action between the HMS module has to get the data from the attached I/O and populate the RAM on the HMS module but this cannot happen in one submit of the form.

So it appears the only way is to submit the form twice but I’'m not sure how to do that.

Link to comment
Share on other sites

I would think there would be example code available to demonstrate something simple such as a log-in page. Also isn't there a specific online forum for the owners of these webserver boards? There is another guy who posted yesterday with a similar board and he has no clue regarding what to do with it either. I think it all comes down to the code library and examples that have been written for that particular board. The other conversation is here...

 

http://w3schools.invisionzone.com/index.php?showtopic=50307&hl=

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...