Using sed command to replace newlines

WordPress is always modificating their software to improve speed and try to bring good things to users. Unfortunately the Block editor is not a good these things, at least not for me.

Recently while editing my post about my list of musics ( https://acassis.wordpress.com/2008/10/22/msicas-mais-ouvidas/ ) it placed the new lines between Music (Musica) and Artist (Cantor).

Then it became:

Music: Blablabla

Artist: Blabla

Music: Blablabla2

Artist: Blabla2

I wanted to restore the old organization:

Music: Blablabla
Artist: Blabla

Music: Blablabla2
Artist: Blabla2

Instead editing it be hand I tried to use VIM text editor, but vim recognizes \n as \0. And although there are some other ways to get it working on vim, Ctrl+J etc didn’t work as expected.

Then I remembered that sed -i could do the trick:

I tested this idea:

sed -i 's/\n\nCantor/\nCantor/g' musics.txt

It didn’t work, then searching in the Internet I found this post:
http://www.benjiegillam.com/2011/09/using-sed-to-replace-newlines/

Then the command became:

sed -i ':a;N;$!ba;s/\n\nCantor/\nCantor/g' musicas.txt

Now the order was restored.

Imposto de Renda 2019 no Linux

Tentei instalar o programa de declaração de imposto de renda no Ubuntu 18.04 e tive alguns problemas:

$ chmod a+x IRPF2019Linux-x86_64v1.5.bin 
$ ./IRPF2019Linux-x86_64v1.5.bin 
/tmp/ijtmp_BAA7A551-D3D8-3B70-2DF2-FF72C5CFA51F/bin/xdg-open: 255: /tmp/ijtmp_BAA7A551-D3D8-3B70-2DF2-FF72C5CFA51F/bin/xdg-open: gnome-open: not found

Então instalei a libgnome2-bin para ver se resolvia o problema:

sudo apt install libgnome2-bin

Ao executar novamente notei que não havia instalado o Java 8 no meu computador, então segui estes passos para instalar:

How to Install JAVA 8 on Ubuntu 18.04/16.04, Linux Mint 19/18

Creio que o IRPF deveria ter uma forma mais inteligente de rodar no Linux, imagine uma pessoa leiga tentando instalar isso? Creio que este é um dos problemas que dificultaram o uso do Linux no Desktop.

Fake chip makes me nervous

I was trying to configure the Microchip/Atmel SAMD21 USART to work at 110BPS to use with an old ABNT CODI protocol.

I noticed that the Silabs CP2102 on Linux doesn’t support such low baudate:

$ sudo stty 110 cs8 -parenb -F /dev/ttyUSB0 
stty: /dev/ttyUSB0: unable to perform all requested operations

“Fortunately” I had a FTDI USB/Serial module that accepts this low baudrate. Then after spending many days trying to figure out why the communication at 110 BPS wasn’t working I decided to use the Logic Analyzer and discovered that the FTDI chip wasn’t generating the 110BPS.

Then I realized there are some FTDI fake chips that don’t work correctly at high speed. Now I can confirm they will not work correct at low speed either. Probably these fake chips use a microcontroller instead of a real IP for USB/Serial and they have loss of precision at low and high baudrates.

Then I decided to use two SAMD21 boards to test the communication, the first board will transmit at 110BPS and the second one will received the data at same baudrate. It worked fine.

Then I found a Prolific PL2303 USB/Serial dongle here and decided to test it. And to my surprise the PL2303 worked fine at 110 BPS and I could test it from computer to the board.

In the computer:

$ sudo stty 110 cs8 -parenb -F /dev/ttyUSB0
$ echo "Hello" > /dev/ttyUSB0

In the SAMD21 board:

nsh> dd if=/dev/ttyS0 of=/dev/console bs=1 count=10                             
Hello

This is a good 110BPS waveform:

Note that it wasted 90.752ms to transmit 10 bits, then each bit wasted 9.0752ms to be transmitted. Therefore to transmit 110 Bits it wastes 9.0752 * 110 = 998,272 ms. Nearly 1 second to transmit 110 bits, the error is only 0,17%.

So, never trust on your serial communication if you are using a USB/Serial from China.

Using a chinese ModBus temperature sensor

I’m testing this modbus SHT20 temperature and humidity sensor: https://www.aliexpress.com/item/SHT20-Temperature-Humidity-Sensor-Industrial-Grade-High-Precision-Temperature-Humidity-Transmitter-Monitoring-Sensor-Modbus-RS48/32923628973.html

There is not much information about this device at Aliexpress. Fortunately searching for the string XY-MD01 that was in the board returned this Russian web site: http://www.bizkit.ru/2018/11/14/5789/

It give a little more detail about the device. Also I found other website that used a different temperature sensor, but the modbus address and protocol is almost the same: https://techsparx.com/energy-system/modbus/linux-modbus-usb-rs485.html

The sample application worked correctly. All I did was to change the modbus_get_response_timeout() to include “&old_response_to_sec, &old_response_to_usec” as it was in the comments and changed the temperature division to: “(tab_rp_bits[0] / 10.0)”.

After some tests I got mbpoll working to read data as well:

$ sudo mbpoll -a 1 -b 9600 -r 2 -t 3 -P none /dev/ttyUSB0

It is nice as the Internet save our soul! I hope this post eventually help other people as well.

How to make VirtualBox to recognized USB Devices

By default VirtualBox on Ubuntu will not detect the USB Device. In order to get it working you need to install the Oracle Extended Package and add add your user to vboxusers group.

You can do it running these two commands:

$ sudo apt install virtualbox-ext-pack
$ sudo usermod -a -G vboxusers $USER

After doing it, please restart your computer (just doing logoff worked for me).

ImageMagick not authorized error

I was getting this error:

$ convert -density 150×150 +antialias -negate FILE1.PDF F1.png
convert-im6.q16: not authorized FILE1.PDF’ @ error/constitute.c/ReadImage/412. convert-im6.q16: no images defined F1.png’ @ error/convert.c/ConvertImageCommand/3258.

I found the solution here: https://stackoverflow.com/questions/52861946/imagemagick-not-authorized-to-convert-pdf-to-an-image/52863413#52863413

/etc/ImageMagick-6/policy.xml

policy domain=”coder” rights=”read|write” pattern=”PS”
policy domain=”coder” rights=”read|write” pattern=”EPI”
policy domain=”coder” rights=”read|write” pattern=”PDF”
policy domain=”coder” rights=”read|write” pattern=”XPS”