The invention discloses a
serial port communication method based on a browser. The method comprises the following steps: requesting a user to authorize to access a
serial port device through a navigator.series. Request Port (); the method comprises the following steps: creating a
serial port control type instance by constructing a function constructor, and configuring indexes, a
baud rate, a data bit, a stop bit and a check bit parameter; calling an openPort () method to open a serial port, and introducing configuration parameters to establish connection; the method comprises the following steps of: acquiring a flow reader through a port.readable. GetReader (), establishing a read-write lock, analyzing return data according to a read type parameter, judging the type of a sent instruction according to the write type parameter, automatically converting
instruction data, acquiring the flow reader through the port.readable. GetReader (), establishing the read-write lock, analyzing the return data according to the read type parameter, and calling the port.relayLock () to release the read-write lock after the data is received and transmitted; and instantiating the serial port control component in the
Web page, and dynamically managing the connection state and the data flow. According to the invention, serial port communication can be realized only by opening the browser without installing extra
software; pure front-end implementation is realized, and a back-end
server or a local program is not needed; and the method accords with the modern Web standard and has strong future compatibility.