You are reading a single comment by @user106712 and its replies. Click here to read the full conversation.
  • Using hubSerial.available() - rather than hubSerial.data('on') - to chunk the input stream seems to make some difference (fewer errors) at 4800 baud. But no difference at 2400 (mostly good) or 9600 (bad transmission). See code below (both .available and .on('data') fragments are included:

    var d0 = console.log;
    var debug = console.log;
    
    var hubSerial = new Serial();
    var usbSerial = new Serial();
    
    function onInit() {
    	hubSerial.setup(4800, { // problematic when baud rate=9600
    		rx: NodeMCU.D5,
    		tx: NodeMCU.D6
    	});
    	usbSerial.setup(9600, {
    		rx: NodeMCU.D9,
    		tx: NodeMCU.D10
    	});
    
        usbSerial.on('data', function (data) {
            try {
                hubSerial.print(data);
            } catch (e) {
                d0("failed to send on hub's data");
            }
        });
      
        //*
    	hubSerial.on('framing', function (data) {
    		d0("framing error");
    	});
    	
    	setInterval(() => {
    		let n = hubSerial.available();
    		if (n > 0) {
    			//d0(n);
    			let d = hubSerial.read(0);
    			usbSerial.print(d);
    		}
    	}, 200);
        //*/
    
    	/*
    	hubSerial.on('data', function (data) {
    		try {
             // d0(data.length);
    			usbSerial.print(data);
    		} catch (e) {
    			d0("failed to send on usb's data");
    		}
    	});
    	//*/
    }
    
About

Avatar for user106712 @user106712 started