Sunday, 24 July 2022

PySerial package is reading serial data before writing?

I am trying to send one byte (128) to a device through serial port and expect to receive back 81 in Hex[space].

Note: The device is automatically transmitting the data it has. Before running Python script, I first tested whether my serial connection is working. First I tested the serial connection with a terminal emulation program called RealTerm: Serial/TCP Terminal.

For program configuration, I set Port baud rate to 115200 and kept everything else to default. I set display as Hex[space].

For testing, I connected the device to PC through serial port (rs232), I first sent 128 and successfully received 82 as response from the device. second, I sent 0x82 and successfully received all stored data in the device.

enter image description here

enter image description here

I tested also to see whether the data is read whenever it is available in buffer but it seems that python is reading before writing.

enter image description here

The Python script is just to send first byte, that is 128. I am expecting to have as output 82.

import serial, struct

rs232 = serial.Serial(
    port = 'COM6', 
    baudrate = 115200, 
    bytesize = serial.EIGHTBITS,
    parity = serial.PARITY_NONE,
    stopbits = serial.STOPBITS_ONE
    )
print(rs232.isOpen)
if rs232.isOpen() == True:
    bytes_to_send = struct.pack('B', 128)
    device_write = rs232.write(bytes_to_send)
    device_read = rs232.read(1)
    print(hex(int.from_bytes(device_read, byteorder='little')) )
else:
    print('rs232 is not open.')
    rs232.close()

The output of the script is: b'\x00'.

I am afraid, I am confusing in data conversion which is why I am not receiving the correct output.



from PySerial package is reading serial data before writing?

Saturday, 23 July 2022

Sanitise unicode pair for filename in javascript?

My web-extension fails to initiate file download for filenames having a pair of emojis with invalid filename error, this seems to be some unicode surrogate pair. Here is the offending filename example:

<a href="https://www.example.com/filestream.xyz"
   download="The New World Order Presentation 👨‍🌾🇳🇱.pdf"
   target="_blank">Download File</a>

As evident from the 'Chrome devtools DOM elements' screenshot below the farmer emoji (https://emojipedia.org/man-farmer/) seem's to be a combination of multiple code-points and is the reason causing the filename to be invalid. How to sanitise the filenames for such situations in javascript?

The Farmer Emoji



from Sanitise unicode pair for filename in javascript?

NodeJS - Find Process Termination Reason

I'm working on an encrypted NodeJS code. The developer has set a license check, but because it is too old and the domain is no longer valid, the license cannot be verified and the program stops working.

I need to figure out what made the program stop working. I tried using the debugger but I think the debugger wrote a function to block it. When I try to debug, I get the following result. Each step creates a different file.

debugger

I need to find where the process was killed. I tried the code below but nothing returns.

process.on('exit', function(code) {
    return console.log(`exiting the code implicitly ${code}`);
});
zsh: terminated  node index.js

Is there anyone have an idea? Thank you.



from NodeJS - Find Process Termination Reason