Skip to content

RTS being set high on port connection #195

@Faller9249

Description

@Faller9249

I'm using the API to make a connection with a UART to USB adapter, the CP2102, and everytime I make a fresh connection with it, by fresh I mean disconnecting the USB cable entirely, the RTS(Request To Send) pin gets set high, even with flowcontrol disabled(set to 'none'), and that is a very big problem for me as the RTS pin of the chip is being used for a very important purpose and this kind of behavior isn't very suited for our application. The code for the actual application is proprietary to the company I work at, but below is a simple code that has the same problem.

<div class="serial-scale-div">
	<button class="btn" id="connect-to-serial" onclick="init()">Connect with Serial Device</button>
</div>
<select id="baudrate">
  <option>9600</option>
  <option>19200</option>
  <option>38400</option>
  <option>57600</option>
  <option>115200</option>
  <option>230400</option>
  <option>460800</option>
  <option>500000</option>
  <option>921600</option>
  <option>1000000</option>
</select>
<button id="get-serial-messages">Get serial messages</button>

<div id="serial-messages-container">
	<div class="message"></div>
</div>

<script>
"use strict";
const connect = document.getElementById('connect-to-serial');
const getSerialMessages = document.getElementById('get-serial-messages');
var port=null;
var reader=null;

getSerialMessages.addEventListener('pointerdown', async () => {
  getSerialMessage();
});


async function getSerialMessage() {
	document.querySelector("#serial-messages-container .message").innerText += await serialScaleController.read();		  
}

async function init() {
	console.log("iniciando");
	if ('serial' in navigator) {
		try {
			if (port){
				port.close();
				reader.releaseLock();
			}
			console.log(navigator.serial);
			port = await navigator.serial.requestPort();
			console.log(document.getElementById("baudrate").value);
			await port.open({ baudRate: parseInt(document.getElementById("baudrate").value)});
			let decoder = new TextDecoderStream();
			port.readable.pipeTo(decoder.writable);
			const inputStream = decoder.readable;
			reader = inputStream.getReader();
			let signals = await port.getSignals();
			console.log(signals);
			readLoop();
		}
		catch (err) {
			console.error('There was an error opening the serial port:', err);
		}
	}
	else {
		console.error('Web serial doesn\'t seem to be enabled in your browser. Try enabling it by visiting:');
		console.error('chrome://flags/#enable-experimental-web-platform-features');
		console.error('opera://flags/#enable-experimental-web-platform-features');
		console.error('edge://flags/#enable-experimental-web-platform-features');
	}
}

async function readLoop(){
	while (port.readable) {
		const { value, done } = await reader.read();
		document.getElementById("serial-messages-container").innerHTML += value;
		// Do something with |value|...
    }
}
</script>

I've tested a couple of things already:

  • calling the setSignals() method before and after the open() method
  • calling the setSignals() method with requestToSend as true and false, dataTerminalReady as well just to be sure
  • setting flowcontrol to 'none' and to 'hardware'
  • making the code synchronous instead of asynchronous

I don't know if I'm missing some critical piece of code or if I'm using something wrong. I've even tried reading the Blink implementation C code to try and understand if there was a problem in the abstraction layers or something like that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions