Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js code inside Javascript of Asp.Net

Very New to Node.js...

I am working on reading a barcode from a COM Port of a R232 Barcode Scanner.
I have found a Node.js call serialport and installed it. I can successfully read the barcode scan, from within a node.js command window, using the example from the installation.

My next step is to see if I can integrate this barcode scan within my ASP.net Web Forms application. I am hosting my application in IIS not looking to change that. Also trying to avoid using ActieX or Java Applets or Silverlight. Also trying to keep it browser based vs native Windows Desktop Application. At the moment don't have the time to convert to Asp.Net MVC.

This is now where I am confused.

1) Node.js can create its own web server and serve its own html content without the need of IIS. So that leads me to believe these two technologies cannot co-exist within the same project/web server instance. Is this true?

2) What I want to do is in the javascript of my Web Forms Application, make the call to read the serial port and populate an input textbox with the results. I don't want to start piecing this together if this is not possible, and I don't think it is. Looking for verification on my hypothesis.

e.g.

<!-- HTML FORM -->    
<input type="textbox" id="txtBarcode" />


<!-- Javascript Section -->
<!-- Bind some event for the input textbox -->
<script>

   function ReadScan(){
   var com = require("serialport");

   var serialPort = new com.SerialPort("COM4", {
       baudrate: 9600,
       parser: com.parsers.readline('\r\n')
     });

   serialPort.on('open',function() {
     console.log('Port open');
   });

   serialPort.on('data', function(data) {
      //I don't think will work here....
     $('#txtBarcode').val(data);
   });
}


</script>

3) I think what I am trying to do is treat node.js as just another web Javascript library like knockout.js or jQuery. Can I treat Node.js this way or no?

like image 709
foop Avatar asked Apr 15 '26 13:04

foop


1 Answers

Node.js can create its own web server and serve its own html content without the need of IIS.

Yes.

So that leads me to believe these two technologies cannot co-exist within the same project/web server instance. Is this true?

No.

You can use Node to generate content without it running a web server. e.g. you could write something that confirms to the CGI specification. (This would be pretty inefficient and I wouldn't recommend it, but it is possible).

You can run a webserver with Node on a different port and then proxy requests to it from IIS.

I think what I am trying to do is treat node.js as just another web Javascript library like knockout.js or jQuery. Can I treat Node.js this way or no?

No.

Node.js is a program that executes JavaScript. It isn't a library written in JavaScript.

Even if it was, if you could use it like Knockout or jQuery then it would run inside the browser and not have access to the serial ports connected to the server (or to those connected to the computer running the browser, since JS in the browser is heavily sandboxed).

I am working on reading a barcode from a COM Port of a R232 Barcode Scanner.

What I want to do is in the javascript of my Web Forms Application, make the call to read the serial port and populate an input textbox with the results

For that to make sense, you'll need to have the bar code reader connected to the computer running the browser.

That sort of hardware usually operates by emulating a keyboard. You should be able to install its standard keyboard driver, put the focus on the input in the web page and just start using it. No programming needed.

(Optional programming: Writing client side JS to recognise when the input has been populated and submit the form automatically).

like image 61
Quentin Avatar answered Apr 18 '26 04:04

Quentin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!