JavaScript Scan gun Use (i)

Source: Internet
Author: User

JavaScript Scanning gun Application (i)
Com.js for the main code implementation, the Test.html file is a test page, which includes a call to the method in the Com.js file. The following is the test success code:
Com.js

com.js/** * Initialize the MSCOMM1 object and open the serial port */function Initmscomm () {document.write ("<object id=mscomm1 classid=\" clsid : 648a5600-2c6e-101b-82b6-000000000014\ "codebase=\" MSCOMM32. Ocx\ "type=\" application/x-oleobject\ "style=\" width:100px;height:30px\ ">");d ocument.write ("<PARAM NAME=\" Commport\ "value=\" 1\ "/>");d ocument.write ("<param name=\" databits\ "value=\" 8\ "/>");d ocument.write ("< PARAM name=\ "stopbits\" value=\ "1\"/> ");d ocument.write (" <param name=\ "baudrate\" value=\ "9600\"/> "); document.write ("<param name=\" Settings\ "value=\" 9600,n,8,1\ "/>");d ocument.write ("<param NAME=\" Rtsenable\ "value=\" 1\ "/>");d ocument.write ("<param name=\" dtrenable\ "value=\" 1\ "/>");d ocument.write (" <param name=\ "handshaking\" value=\ "0\"/> ");d ocument.write (" <param name=\ "nulldiscard\" VALUE=\ "0\"/> " );d ocument.write ("<param name=\" parityreplace\ "value=\"? \ "/>");d ocument.write ("<param NAME=\" EOFEnable\ "Value=\" 0\ "/>");d ocument.write ("<param name=\" InputMode\ "value=\" 0\ "/>");d ocument.write ("<param name=\" inbuffersize\ "value=\" 1024\ "/>");d ocument.write (" <param name=\ "inputlen\" value=\ "1\"/> ");d ocument.write (" <param name=\ "outbuffersize\" VALUE=\ "512\"/> ");d ocument.write (" <param name=\ "sthreshold\" value=\ "0\"/> ");d ocument.write (" <param NAME=\ "RThreshold\" Value=\ "1\"/> ");d ocument.write (" </OBJECT> "); if (mscomm1.portopen==false) {try{mscomm1.portopen=true;} catch (ex) {alert ("COM1 Port Open failed:" +ex.message);}}} var mscomm_scan_value = "";//Serial Response event function Mscomm1_oncomm (callbackfunction) {switch (mscomm1.commevent) {Case 2:// Receive event if (Mscomm_scan_value = = "") {Mscomm_scan_value = mscomm1.input;//timed Read cache information settimeout ("Getmscommscanvalue (" + callbackfunction+ ")", 300);} Break;default:alert ("Event raised!" +mscomm1.commevent);}} function Getmscommscanvalue (callbackfunction) {//Read the remaining information in the cache while (Mscomm1.inbuffersize > 0) {mscomm_scan_value + = MSComm1.Input;} Executes the function that the page passes over Callbackfunction (mscomm_scan_value);//empties the current read information Mscomm_scaN_value = ""} 



Test.html



After several unsuccessful attempts, the contents of the test are as follows:
1. Add the test.html file in the
<script type= "Text/javascript" for= "MSComm1" event= "OnComm" >
The MSCOMM1 control calls the Mscomm1_oncomm () function Every OnComm event is encountered
Mscomm1_oncomm (Mscommcallback)
The </script> section code is adjusted to:
<script type= "Text/javascript" >
Window.onload = function () {
Mscomm1.oncomm = mscomm1_oncomm;//Implementation of the closure by alternative means
}
</script>

2. Call the Initmscomm method in the JavaScript code of the page head, add the object tag objects to a div in the page, the page prompts to load the ActiveX control, but cannot bind the OnComm event response.

3. A response event with a status of 7 o'clock cannot be used when the mscomm1.commevent is 7 to indicate the end of the receive, but only when the status of 2 is received.

4. When the Initmscomm method is called, and mscomm1.commevent for 2 of the case, the Judge MSComm1.InBufferCount for the 0 O'Clock event response, may be a buffer and other reasons (specifically unclear), will lead to inbuffercount more than 0 of the situation, so there is no way to use, the final use of the first implementation, determined Completes the read operation of the cached content when it gets the method.

My goal is to implement the load of the object, the binding of the response event, and the receive end execution response event operation through a method call. Because I am not proficient in JavaScript, so I can not achieve the desired goal, if there is a better solution, I hope you can leave me a message.

Related documents Download: Http://www.posunitech.cn/download_list/columnsId=60&FrontColumns_ navigation01-1362972848243firstcolumnid=36&frontcolumns_navigation01-1362972848243secondcolumnid=60& &downloadcategoryid=1&ismode=false.html

JavaScript Scan gun Use (i)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.