I have in my Default.aspx page a textbox that i want updated after reading a barcode using an Applet that reads the client serial port. To do this, i load a javascript in the Page_Load of the Default.aspx page as follows:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
StreamReader objReader = File.OpenText(Request.PhysicalApplicationPath + @"\Files\serial.htm");
Response.Write(objReader.ReadToEnd());
objReader.Close();
}
}
The value read from the serial port i assign to a hidden field as shown in the serial.htm file below:
<html>
<head>
<title></title>
</head>
<script type="text/javascript">
var ser;
var FMessage;
function plugin0()
{
return document.getElementById('plugin0');
}
plugin = plugin0;
function recv(bytes, size)
{
for (var i = 0; i < size; i++) {
switch (bytes[i]) {
case 13:
document.getElementById('Barcode').value = FMessage;
FMessage = "";
break;
default:
FMessage = FMessage + String.fromCharCode(bytes[i]);
break;
}
}
}
function pluginLoaded()
{
FMessage = "";
ser = plugin().Serial;// Get a Serial object
ser.open("COM6");// Open a port
ser.set_option(9600, 0, 8, 0, 0); // Set port options
ser.recv_callback(recv); // Callback function for recieve data
}
function pluginValid()
{
if(plugin().valid){
alert(plugin().echo("This plugin seems to be working!"));
} else {
alert("Plugin is not working :(");
}
}
</script>
<body onload="load()">
<object id="plugin0" type="application/x-juart" width="0" height="0" >
<param name="onload" value="pluginLoaded" />
</object>
<input id="Barcode" type="Hidden" runat="server" value="" />
</body>
</html>
I wish to update the textbox value on the Default.aspx page with this barcode as shown here:
Default.aspx:
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent" >
<p>
<asp:TextBox ID="BarcodeText" runat="server" ></asp:TextBox>
</p>
</asp:Content>
Thanking in advance