summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--h.py40
-rw-r--r--index.html222
-rw-r--r--webusb.js479
3 files changed, 741 insertions, 0 deletions
diff --git a/h.py b/h.py
new file mode 100644
index 0000000..ba7d487
--- /dev/null
+++ b/h.py
@@ -0,0 +1,40 @@
+
+import sys
+
+i = int(sys.argv[1],16)
+print(i)
+d1 = i&0x1f
+print("Recepient "+str(d1)),
+if d1 == 0:
+ print(" device")
+elif d1 == 1:
+ print(" interface")
+elif d1 == 2:
+ print(" endpoint")
+elif d1 == 3:
+ print(" other")
+else:
+ print(" Unknown")
+
+d2 = ((i>>5)&0x3)
+print("Request type "+str(d2)),
+if d2 == 0:
+ print(" standart")
+elif d2 == 1:
+ print(" class")
+elif d2 == 2:
+ print(" vendor")
+elif d2 == 3:
+ print(" reserved")
+else:
+ print(" Unknown")
+
+d3 = ((i>>7)&0x1)
+print("Direction "+str(d3)),
+if d3 == 0:
+ print(" Out")
+elif d3 == 1:
+ print(" In")
+else:
+ print(" Unknown")
+
diff --git a/index.html b/index.html
new file mode 100644
index 0000000..41e9ffe
--- /dev/null
+++ b/index.html
@@ -0,0 +1,222 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="webusb.js"></script>
+</head>
+<body>
+
+<h1>My First Web Page</h1>
+<p>My First Paragraph</p>
+
+<p id="demo"></p>
+<div>Device Info Product name <div id="info-product-name"></div>Manufacturer <div id="info-manufacturer"></div> Vendor ID <div id="info-vendor-id"></div> Product ID <div id="info-product-id"></div>
+<div id="info-"></div>
+</div>
+<div>Status: <div id="status"></div></div>
+<button id="request-permission">Request "serial" permission</button>
+<button id="usb-open">Open</button>
+<button id="usb-claim">ClaimInterface</button>
+<input style="display:inline;" id="in-claim" size=1 type="text" value="0">
+<button id="initialisation">Initialisation</button>
+<button id="usb-close">Close</button>
+<button id="usb-reset">Reset</button>
+
+<h1>CP201</h1>
+<button id="usb-conf">Config serial</button>
+<button id="usb-get-line">Get line request</button>
+<button id="vendor-write">Write</button>
+ <input style="display:inline;" id="inw-idx" size=1 type="text" value="0">
+ <input style="display:inline;" id="inw-val" size=2 type="text" value="0">
+
+<button id="vendor-read">Read</button>
+ <input id="inr-idx" size=1 type="text" value="0">
+ <input id="outr-val" size=2 type="text" value="0">
+
+<h1>CH341</h1>
+<button id="ch341-configure">Configure</button>
+<button id="ch341-configure2">Cfg2</button>
+<button id="ch341-get-status2">Get status</button>
+<button id="ch341-set-baudrate">Set baudrate</button>
+<button id="ch341-ep0">EP0 In 32</button>
+<button id="ch341-ep1">EP1 Out 32</button><input style="display:inline;" id="ch341-ep1-in" size=32 type="text" value="0">
+<button id="ch341-ep2">EP2 In 8</button>
+<input style="display:inline;" id="ch341-ep2-out" size=32 type="text">
+<button id="ch341-bulkout">BulkOut</button>
+<button id="ch341-break-ctl">Break Ctrl</button>
+<button id="ch341-set-handshake">Set handshake</button>
+<script>
+
+
+let r;
+let port;
+
+function getBgColors (tab) {
+ // But for now, let's just make sure what we have so
+ // far is working as expected.
+ alert('The browser action was clicked! Yay!');
+}
+
+function setStatus(s){
+ document.getElementById("status").innerHTML=s;
+};
+
+function setInfo(n,v){
+ document.getElementById("info-"+n).innerHTML=v;
+};
+
+document.querySelector('#request-permission').onclick = function() {
+ serial.requestPort().then(selectedPort => {
+ port = selectedPort;
+ setInfo("product-name",port.device.productName);
+ setInfo("manufacturer",port.device.manufacturer);
+ setInfo("vendor-id",port.device.vendorId);
+ setInfo("product-id",port.device.productId);
+ console.log(port);
+ document.getElementById("status").innerHTML="Connected";
+ }).catch(error => {
+ console.log(error);
+ })
+};
+
+document.querySelector('#initialisation').onclick = function(){
+ port.init();
+};
+
+document.querySelector("#usb-open").onclick = function(){
+ port.connect();
+ setStatus("Opened");
+ console.log("Open usb + "+ port.device.productName);
+};
+
+document.querySelector("#usb-claim").onclick = function(){
+ port.claim(document.getElementById("in-claim").value);
+ setStatus("Claimed Interface");
+ console.log("Claim Interface usb + "+ port.device.productName);
+};
+
+document.querySelector("#vendor-write").onclick = function(){
+ var i = document.getElementById("inw-idx").value;
+ var v = document.getElementById("inw-val").value;
+ port.vendorWrite(i,v);
+ setStatus("Write data");
+ console.log("Write idx "+i+" val "+v );
+};
+
+document.querySelector("#vendor-read").onclick = function(){
+ port.vendorRead(0,0);
+ setStatus("Read data");
+ console.log("Close usb + "+ port.device.productName);
+};
+
+document.querySelector("#usb-reset").onclick = function(){
+ port.reset();
+ setStatus("Reset port");
+ console.log("Reset port");
+};
+
+document.querySelector("#usb-conf").onclick = function(){
+ port.reset();
+ setStatus("USB configure");
+ console.log("USB configure");
+};
+
+document.querySelector("#usb-get-line").onclick = function(){
+ port.getLineRequest();
+ setStatus("Get line");
+ console.log("Get line");
+};
+
+document.querySelector("#ch341-configure").onclick = function(){
+ r = port.CH341configure();
+ setStatus("Configure");
+ console.log("Configure");
+};
+
+document.querySelector("#ch341-configure2").onclick = function(){
+ r = port.CH341configure2();
+ setStatus("Configure2");
+ console.log("Configure2");
+};
+/*
+document.querySelector("#ch341-get-status").onclick = function(){
+ var r = port.CH341getStatus();
+ console.log(r);
+ setStatus("Get status");
+ console.log("Get status");
+};*/
+
+document.querySelector("#ch341-get-status2").onclick = async() => {
+ let r = await port.CH341getStatus2();
+ console.log(r);
+ var u8 = new Uint8Array(r.data.buffer)
+ console.log(u8);
+ setStatus("Get status2");
+ console.log("Get status2");
+};
+
+document.querySelector("#ch341-ep0").onclick = async() =>{
+ let r = port.CH341readEP0();
+ //var u8 = new Uint8Array(r.data.buffer)
+ //console.log(u8);
+ console.log(r);
+ setStatus("Endpoint 0");
+ console.log("Endpoint 0");
+};
+
+function str2ab(str) {
+ var buf = new ArrayBuffer(str.length); // 2 bytes for each char
+ var bufView = new Uint8Array(buf);
+ for (var i=0, strLen=str.length; i<strLen; i++) {
+ bufView[i] = str.charCodeAt(i);
+ }
+ return buf;
+}
+
+document.querySelector("#ch341-ep1").onclick = async() =>{
+ data = str2ab(document.getElementById("ch341-ep1-in").value);
+ console.log(data);
+ port.CH341readEP1(data);
+ setStatus("Endpoint 1");
+ console.log("Endpoint 1");
+};
+
+document.querySelector("#ch341-ep2").onclick = async() =>{
+ let r = await port.CH341readEP2();
+ //var u8 = new Uint8Array(r.data.buffer)
+ document.getElementById("ch341-ep2-out").value = document.getElementById("ch341-ep2-out").value + r;
+ console.log(r);
+ setStatus("Endpoint 2");
+ console.log("Endpoint 2");
+};
+
+document.querySelector("#ch341-bulkout").onclick = async() =>{
+ //let r = await port.bulkOut(2);
+ let r = await port.bulkIn(2,1);
+ //var u8 = new Uint8Array(r.data.buffer)
+ console.log(r);
+ setStatus("Bulkout");
+ console.log("Bulkout");
+};
+
+document.querySelector("#ch341-set-baudrate").onclick = async() => {
+ port.CH341setBaudrateLCR();
+ setStatus("Set baudrate");
+ console.log("Set baudrate");
+};
+
+document.querySelector("#ch341-break-ctl").onclick = async() => {
+ port.CH341breakReg();
+ setStatus("Set break reg");
+ console.log("Set break reg");
+};
+
+document.querySelector("#ch341-set-handshake").onclick = async() => {
+ port.CH341setHandshake();
+ setStatus("Set handshake");
+ console.log("Set handshake");
+};
+
+</script>
+
+</body>
+</html> \ No newline at end of file
diff --git a/webusb.js b/webusb.js
new file mode 100644
index 0000000..0f174d4
--- /dev/null
+++ b/webusb.js
@@ -0,0 +1,479 @@
+var serial = {};
+
+function buf2hex(buffer) { // buffer is an ArrayBuffer
+ return Array.prototype.map.call(new Uint8Array(buffer), x => ('00' + x.toString(16)).slice(-2)).join('');
+}
+
+(function() {
+ 'use strict';
+
+ serial.status = 0; //disconnected
+
+ serial.CP210_VENDOR_WRITE_REQUEST_TYPE = 0x40;
+ serial.CP210_VENDOR_WRITE_REQUEST = 0x01;
+ serial.CP210_VENDOR_READ_REQUEST_TYPE = 0xc0;
+ serial.CP210_VENDOR_READ_REQUEST = 0x01;
+ serial.CP210_GET_LINE_REQUEST_TYPE = 0xa1;
+ serial.CP210_GET_LINE_REQUEST = 0x21;
+ serial.CP210_SET_LINE_REQUEST_TYPE = 0x21;
+ serial.CP210_SET_LINE_REQUEST = 0x20;
+ serial.CP210_SET_CONTROL_REQUEST_TYPE = 0x21;
+ serial.CP210_SET_CONTROL_REQUEST = 0x22;
+ serial.CP210_BREAK_REQUEST_TYPE = 0x21;
+ serial.CP210_BREAK_REQUEST = 0x23;
+
+ serial.CH341_REQ_READ_VERSION = 0x5F;
+ serial.CH341_REQ_WRITE_REG = 0x9A;
+ serial.CH341_REQ_READ_REG = 0x95;
+ serial.CH341_REQ_SERIAL_INIT = 0xA1;
+ serial.CH341_REQ_MODEM_CTRL = 0xA4;
+ serial.CH341_REG_BREAK = 0x05;
+ serial.CH341_REG_LCR = 0x18;
+
+ serial.CH341_LCR_ENABLE_RX = 0x80;
+ serial.CH341_LCR_ENABLE_TX = 0x40;
+ serial.CH341_LCR_MARK_SPACE = 0x20;
+ serial.CH341_LCR_PAR_EVEN = 0x10;
+ serial.CH341_LCR_ENABLE_PAR = 0x08;
+ serial.CH341_LCR_STOP_BITS_2 = 0x04;
+ serial.CH341_LCR_CS8 = 0x03;
+ serial.CH341_LCR_CS7 = 0x02;
+ serial.CH341_LCR_CS6 = 0x01;
+ serial.CH341_LCR_CS5 = 0x00;
+
+ serial.CH341_BIT_CTS = 0x01;
+ serial.CH341_BIT_DSR = 0x02;
+ serial.CH341_BIT_RI = 0x04;
+ serial.CH341_BIT_DCD = 0x08;
+
+ serial.CH341_BAUDBASE_FACTOR = 1532620800;
+ serial.CH341_BAUDBASE_DIVMAX = 3;
+
+ serial.CH341 = 0x1;
+ serial.CP201 = 0x2;
+
+ //CH341
+ //https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/usb/serial/ch341.c?h=v5.3-rc1
+ //cp210
+ //https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/usb/serial/cp210x.c?h=v5.3-rc1
+
+ //requestType standard/class/vendor 0=standard, 1=class, 2=vendor, 3=reserved)
+ //recipient device/inteface/endpoint/other 0=device, 1=interface, 2=endpoint,3=other)
+
+ serial.getPorts = function() {
+ return navigator.usb.getDevices().then(devices => {
+ return devices.map(device => new serial.Port(device));
+ });
+ };
+
+ serial.requestPort = function() {
+ const filters = [
+ { vendorId:0x067b, productId:0x2303 }, //cp210
+ { vendorId:0x1a86, productId:0x7523 }, //ch341
+ ];
+ return navigator.usb.requestDevice({ 'filters': filters }).then(
+ device => new serial.Port(device)
+ );
+ }
+
+ serial.Port = function(device) {
+ this.device = device;
+ if ((device.vendorId == 0x067b) && (device.productId == 0x2303))
+ {
+ this.device.t = serial.CP201;
+ }
+ if ((device.vendorId == 0x1a86) && (device.productId == 0x7523))
+ {
+ this.device.t = serial.CH341;
+ }
+ };
+
+ serial.Port.prototype.connect = function(){
+ this.device.open().then(() => {
+ if (this.device.configuration === null) {
+ return this.device.selectConfiguration(1);
+ }
+ }).then(() => this.device.claimInterface(0))
+ .then(() => this.device.selectAlternateInterface(0,0))
+ .catch(error => {
+ console.log("ERROR "+error);
+ })
+ };
+
+ serial.Port.prototype.claim = function(i) {
+ this.device.claimInterface(i)
+
+ .catch(error => {
+ console.log("ERROR "+error);
+ })
+
+ }
+
+ serial.Port.prototype.close = function() {
+ return this.device.close();
+ }
+
+ serial.Port.prototype.reset = function() {
+ return this.device.reset();
+ }
+
+ serial.Port.prototype.disconnect = function() {
+ return this.device_.controlTransferOut({
+ 'requestType': 'class',
+ 'recipient': 'interface',
+ 'request': 0x22,
+ 'value': 0x00,
+ 'index': 0x02})
+ .then(() => this.device.close());
+ };
+
+ serial.Port.prototype.send = function(data) {
+ return this.device.transferOut(4, data);
+ };
+
+ serial.Port.prototype.vendorWrite = function(value,index) {
+ console.log("Write idx "+index+" val = "+value)
+ return this.device.controlTransferOut({
+ 'requestType': 'vendor',
+ 'recipient': 'device',
+ 'request': serial.VENDOR_WRITE_REQUEST,
+ 'value': value,
+ 'index': index,
+ });
+ };
+
+ serial.Port.prototype.vendorRead = function(value) {
+ console.log("Read val="+value);
+ return this.device.controlTransferIn({
+ 'requestType': 'vendor',
+ 'recipient': 'device',
+ 'request':serial.VENDOR_READ_REQUEST,
+ 'value':value,
+ 'index':0,
+ },1);
+ };
+
+ serial.Port.prototype.checkDevice = function() {
+ };
+
+ serial.Port.prototype.patchDevice = function() {
+ };
+
+ serial.Port.prototype.getLineRequest = function() {
+ console.log("Get line request");
+ return this.device.controlTransferIn({
+ 'requestType': 'class',
+ 'recipient': 'interface',
+ 'request':serial.GET_LINE_REQUEST,
+ 'value':0,
+ 'index':0,
+ },7);
+ };
+
+ serial.Port.prototype.setLineRequest = function() {
+ console.log("Set line request");
+ return this.device.controlTransferOut({
+ 'requestType': 'class',
+ 'recipient': 'interface',
+ 'request':serial.SET_LINE_REQUEST,
+ 'value':0,
+ 'index':0,
+ },7);
+ };
+
+ serial.Port.prototype.setControlRequest = function() {
+ console.log("Set control request");
+ return this.device.controlTransferOut({
+ 'requestType': 'class',
+ 'recipient': 'interface',
+ 'request':serial.SET_CONTROL_REQUEST,
+ 'value':0,
+ 'index':0,
+ },7);
+ };
+
+ serial.Port.prototype.breakRequest = function() {
+ console.log("Break request");
+ return this.device.controlTransferOut({
+ 'requestType': 'class',
+ 'recipient': 'interface',
+ 'request':serial.BREAK_REQUEST,
+ 'value':0,
+ 'index':0,
+ },7);
+ };
+
+ serial.Port.prototype.transferIn = function(reqtype,recp,req,val,idx,dataread) {
+ console.log("transferIn");
+ return this.device.controlTransferIn({
+ 'requestType': reqtype,
+ 'recipient': recp,
+ 'request':req,
+ 'value':val,
+ 'index':idx,
+ },dataread);
+ };
+ serial.Port.prototype.transferInfClaIn = function(req,val,idx,dataread) {
+ console.log("transferInfClaIn");
+ this.transferIn("interface","class",req,val,idx,dataread);
+ };
+
+
+
+ serial.Port.prototype.transferOut = function(reqtype,recp,req,val,idx) {
+ console.log("transferOut");
+ return this.device.controlTransferOut({
+ 'requestType': reqtype,
+ 'recipient': recp,
+ 'request':req,
+ 'value':val,
+ 'index':idx,
+ });
+ };
+
+ serial.Port.prototype.transferDevVenOut = function(req,val,idx) {
+ console.log("transferDevVenOut");
+ this.transferOut("vendor","device",req,val,idx);
+ }
+
+ serial.Port.prototype.transferIntClaOut = function(req,val,idx) {
+ console.log("transferIntClaOut");
+ this.transferOut("class","interface",req,val,idx);
+ }
+
+ serial.Port.prototype.bulkOut = async function(ep) {
+ var buf = new ArrayBuffer(1);
+ let r = await this.device.transferOut(ep,buf);
+ console.log(buf);
+ console.log(r);
+ return r;
+ }
+
+ serial.Port.prototype.bulkIn = async function(ep,l) {
+ let r = await this.device.transferIn(ep,l);
+ console.log(r);
+ return r;
+ }
+
+ serial.Port.prototype.EncodeBaudRate = function() {
+ };
+
+ //https://gist.github.com/fe1320e2539ce9afc529f51cce656bae
+ serial.Port.prototype.init = function() {
+ this.vendorRead( 0x8484)
+ .then(() => this.vendorWrite(0x0404 , 0))
+ .then(() => this.vendorRead( 0x8484))
+ .then(() => this.vendorRead( 0x8383))
+ .then(() => this.vendorRead( 0x8484))
+ .then(() => this.vendorWrite(0x0404 , 1))
+ .then(() => this.vendorRead( 0x8484))
+ .then(() => this.vendorRead( 0x8383))
+ .then(() => this.vendorWrite(0 , 1))
+ .then(() => this.vendorWrite(1 , 0))
+ .then(() => this.vendorWrite(2 , 0x24))
+ .then(r =>{ console.log("Done "+r);})
+ .catch(err => {console.log("Error "+err);}); // 2,0x44
+ };
+
+ serial.Port.prototype.CH341controlIn = function(req,val,idx,dataread) {
+ console.log("CH341controlIn");
+ return this.device.controlTransferIn({
+ 'requestType': 'vendor',
+ 'recipient': 'device',
+ 'request':req,
+ 'value':val,
+ 'index':idx,
+ },dataread);
+ };
+
+ serial.Port.prototype.CH341controlOut = function(req,val,idx) {
+ console.log("CH341controlOut");
+ return this.device.controlTransferOut({
+ 'requestType': 'vendor',
+ 'recipient': 'device',
+ 'request':req,
+ 'value':val,
+ 'index':idx,
+ });
+ };
+
+ serial.Port.prototype.CH341configure = function() {
+ //serial.Port.prototype.CH341configure = async() => {
+ console.log("CH341configure");
+ this.device.controlTransferIn({
+ 'requestType': 'vendor',
+ 'recipient': 'device',
+ 'request':serial.CH341_REQ_READ_VERSION,
+ 'value':0,
+ 'index':0,
+ },2).then(res1 => {
+ var v = new Uint8Array(res1.data.buffer);
+ console.log("0x"+buf2hex(v));
+ }).catch(err=>{
+ console.log(err);
+ });
+
+ console.log("CH341_REQ_SERIAL_INIT")
+ var res2;
+ this.device.controlTransferOut({
+ 'requestType': 'vendor',
+ 'recipient': 'device',
+ 'request':serial.CH341_REQ_SERIAL_INIT,
+ 'value':0,
+ 'index':0,
+ }).then(r => {res2=r;}).catch(err => {console.log(err)});
+ //console.log(buf2hex(res2.));
+ console.log(res2);
+ //return res2;
+ };
+
+ serial.Port.prototype.CH341configure2 = async function() {
+ console.log("CH341configure");
+ //40 a4 ff9f 0000 0000 0
+ let r1 = await this.transferDevVenOut(serial.CH341_REQ_MODEM_CTRL,0xff9f,0x0,0x0);
+ console.log(r1);
+ //40 9a 1312 6483 0000 0
+ let r2 = await this.transferDevVenOut(serial.CH341_REQ_WRITE_REG,0x1312,0x6483,0x0);
+ console.log(r2);
+ //40 9a 2518 00c3 0000 0
+ let r3 = await this.transferDevVenOut(serial.CH341_REQ_WRITE_REG,0x2518,0x00c3,0x0);
+ console.log(r3);
+ //40 a4 ff9f 0000 0000 0
+ let r4 = await this.transferDevVenOut(serial.CH341_REQ_MODEM_CTRL,0xff9f,0x0,0x0);
+ console.log(r4);
+ }
+
+ serial.Port.prototype.CH341setHandshake = function() {
+ };
+
+ serial.Port.prototype.CH341getStatus = function() {
+ console.log("CH341getStatus");
+ var res1;
+ this.device.controlTransferIn({
+ 'requestType': 'vendor',
+ 'recipient': 'device',
+ 'request':serial.CH341_REQ_READ_REG,
+ 'value':0x0706,
+ 'index':0,
+ },2).then(r=>{
+ var v = new new Uint8Array(r.data.buffer);
+ console.log(buf2hex(v));
+ }).catch(err=>{
+ console.log(err);
+ });
+ console.log(res1);
+ return res1;
+ };
+
+ serial.Port.prototype.CH341getStatus2 = async function() {
+ var dev = this.device;
+ try {
+ console.log("CH341getStatus");
+ let res = await dev.controlTransferIn({
+ 'requestType': 'vendor',
+ 'recipient': 'device',
+ 'request':serial.CH341_REQ_READ_REG,
+ 'value':0x0706,
+ 'index':0,
+ },2);
+ console.log(res);
+ return res;
+ } catch (err) {
+ console.log(err);
+ }
+ };
+
+ serial.Port.prototype.CH341getStatus2 = async function() {
+ var dev = this.device;
+ try {
+ console.log("CH341getStatus");
+ let res = await dev.controlTransferIn({
+ 'requestType': 'vendor',
+ 'recipient': 'device',
+ 'request':serial.CH341_REQ_READ_REG,
+ 'value':0x0706,
+ 'index':0,
+ },2);
+ console.log(res);
+ return res;
+ } catch (err) {
+ console.log(err);
+ }
+ };
+
+ serial.Port.prototype.CH341readEP0 = async function() {
+ try {
+ console.log("CH341readEP0");
+ let res = this.device.transferIn(2,32);
+ console.log("Res:"+res);
+ return res;
+ } catch (err) {
+ console.log(err);
+ }
+ };
+
+ serial.Port.prototype.CH341readEP1 = async function(data) {
+ try {
+ console.log("CH341readEP1");
+ let res = await this.device.transferOut(2,data);
+ console.log(res);
+ return res;
+ } catch (err) {
+ console.log(err);
+ }
+ };
+
+ serial.Port.prototype.CH341readEP2 = async function() {
+ try {
+ console.log("CH341readEP2");
+ let res = this.device.transferIn(1,8);
+ console.log("Result from EP2");
+ console.log(res);
+ return res;
+ } catch (err) {
+ console.log(err);
+ }
+ };
+
+ serial.Port.prototype.CH341setBaudrateLCR = async function() {
+ var factor = serial.CH341_BAUDBASE_FACTOR / 38400;
+ console.log(factor);
+ var divider = serial.CH341_BAUDBASE_DIVMAX;
+ factor = 0x10000 - factor;
+ var a = (factor & 0xff00) | divider;
+ console.log(a);
+ a = a | 0x80;
+
+ var lcr = serial.CH341_LCR_ENABLE_TX | serial.CH341_LCR_ENABLE_RX | serial.CH341_LCR_CS8;
+ var lcr = serial.CH341_LCR_ENABLE_TX | serial.CH341_LCR_ENABLE_RX | serial.CH341_LCR_CS8;
+
+ this.CH341controlOut(serial.CH341_REQ_WRITE_REG,0x1312,a);
+ this.CH341controlOut(serial.CH341_REQ_WRITE_REG,0x2518,lcr);
+ };
+
+ serial.Port.prototype.CH341breakReg = async function() {
+ var ch341_break_reg = (serial.CH341_REG_LCR << 8) | serial.CH341_REG_BREAK;
+ console.log(ch341_break_reg);
+ let r = await this.CH341controlIn(serial.CH341_REQ_READ_REG, ch341_break_reg, 0, 2);
+ var u8 = new Uint8Array(r.data.buffer);
+ console.log(u8);
+ u8[0] = u8[0] | serial.CH341_NBREAK_BITS;
+ u8[1] = u8[1] | serial.CH341_LCR_ENABLE_TX;
+ console.log(u8);
+ let r1 = await this.CH341controlOut(serial.CH341_REQ_WRITE_REG,ch341_break_reg, u8);
+ console.log(r1);
+ return r;
+ }
+
+ serial.Port.prototype.CH341setHandshake = async function(ctrl) {
+ var mcr = 0;
+ mcr = mcr | serial.CH341_BIT_CTS;
+ mcr = mcr | serial.CH341_BIT_DSR;
+ mcr = ~mcr;
+ //let r1 = await this.CH341controlOut(serial.CH341_REQ_MODEM_CTRL, ~ctrl, 0);
+ let r1 = await this.CH341controlOut(serial.CH341_REQ_MODEM_CTRL, mcr, 0);
+ console.log(r1);
+ return r1;
+ }
+
+})(); \ No newline at end of file