Usb-serial writing and reading data issue in Debian Gnu/Linux - linux

I'm trying to establish a connection with a gauge, which connects to a PC via usb-serial interface. I managed to do this in Windows 8 via vendor proprietary program, which uses Prolific driver version 3.2.0. In windows I monitored data exchanged between the gauge and the software with a help a of a software "HDD Software Device Monitoring Studio".
Now I want to repeat data exchange I have seen in HDD Software Device Monitoring Studio but this time in the Debian Gnu/Linux without vendor's properietary program for the gauge. To do this in Debian I installed a software "jpnevultor version 2.1.3" which seems to fit my needs, because it is able to write and read data to a serial port.
After installing this program I plugged the gauge to the PC running Debian and issued dmesg|tailcommand, int the output there was a line usb-3-1: pl2303 converter now attached to ttyUSB0so I assummed that pl2303 driver installed on the Debian and successfully identified the gauge and I can access it.
To test if I can send data to the gauge via /dev/ttyUSB0 file I created a text file named hello with the following content
FF 3A 32 34 31 3B 30 3B 30 3B 36 35 34 30 35 0D
this is a byte sequence that I monitored via HDD Software Device Monitoring Studio any time I started data exchange with a gauge via vendor proprietary program.
Now I am trying to feed this byte sequence to a gauge. First of all in Debian I executed following command jpnevulator --tty /dev/ttyUSB0 --read. It put terminal to a pending state, so I am assumming that program is waiting for a data comming from the ttyUSB0.
After then I opened second terminal window and excecute following command jpnevulator --tty /dev/ttyUSB0 -f hello --write to write data from the mentioned file hello with the byte sequence to the /dev/ttyUSB0.
Write command executed normally. But when I switched back to the first terminal window to see if there are bytes that came from the gauge I found that there none like if I didn't send any data to the /dev/ttyUSB0/.
I tried to issue following commands: modprobe -r pl2303; modprobe pl2303 and repeating mentioned write and read commands with no results. I tried setting /dev/ttyUSB0 speed to 9600 via command stty -F /dev/ttyUSB0 ispeed 9600 because , tried to change permissions of /dev/ttyUSB0 to 777 and ran all mentioned command under a root account, but the result were the same - read command didn't return any data. Could you please help me to find out why this is happenning and how can I properly write and read data to /dev/ttyUSB0?

Related

how to give permission to intel realsense camera on Ubuntu

OS:Ubuntu 18.04
camera: Intel realsense D415
I can use cheese to show the compound image of the camera. But when I run
import pyrealsense2 as rs
pipeline = rs.pipeline()
pipeline.start()
It throws out error access failed for 8086:ad6 uid: 1-1-12
Is anyone that knows how to solve this? Thanks!
You need to install Intel Realsense permission scripts located in librealsense source directory.
For that, first, git clone the librealsense to a local folder
git clone https://github.com/IntelRealSense/librealsense
Next, run the following commands to copy the 99-realsense-libusb.rules files to the rules.d folder
sudo cp config/99-realsense-libusb.rules /etc/udev/rules.d/
And, then udevadm control to modify the internal state of the running udev dameon to reload rules. Also, udevadm trigger to request device events from the kernel.
sudo udevadm control --reload-rules
sudo udevadm trigger
Update: I recently faced the Runtime error: backend-v412.cpp:988 - Frames didn't arrived within 5 seconds. Seems like the pipeline is not able to handle the framebuffers, and there is quite a lot of drop in the frames, specifically above 720p, 15 frames/sec.
Any resolutions?
Update 2:
Resolution: As suspected it is a pipelining issue w.r.t the amount of the data the USB port can carry. To prevent frame drop or overload of data through the USB, it has to be connected to a Motherboard that has USB 3.1 Gen 1 specifications. Refer to page 78 of this document https://www.intelrealsense.com/wp-content/uploads/2020/06/Intel-RealSense-D400-Series-Datasheet-June-2020.pdf

Serial port unavaliable arduino

Trying to upload a code to arduino, but whether in the Arduino IDE or Arduino Create, both return this erro while uploading. Running on Linux Tara(mint 19 cinnamon).
./opt/arduino-builder/arduino-builder -compile -core-api-version 10611 -hardware opt/arduino-builder/hardware -hardware ./opt/cores -tools opt/arduino-builder/tools -tools ./opt/tools -built-in-libraries opt/libraries/latest -logger humantags -fqbn arduino:avr:mega:cpu=atmega2560 -build-cache /tmp -build-path /tmp/716441957/build -verbose -libraries /tmp/716441957/custom -libraries /tmp/716441957/pinned /tmp/716441957/sketch_oct8a
Sketch uses 8280 bytes (3%) of program storage space. Maximum is 253952 bytes.
Global variables use 443 bytes (5%) of dynamic memory, leaving 7749 bytes for local variables. Maximum is 8192 bytes.
Programming with: Serial
Flashing with command:/home/jesus/.arduino-create/arduino/avrdude/6.3.0-arduino9/bin/avrdude -C/home/jesus/.arduino-create/arduino/avrdude/6.3.0-arduino9/etc/avrdude.conf -q -q -patmega2560 -cwiring -P/dev/ttyACM0 -b115200 -D -Uflash:w:/tmp/arduino-create-agent734074237/sketch_oct8a.hex:i
avrdude: ser_open(): can't open device "/dev/ttyACM0": Permission denied
ioctl("TIOCMGET"): Inappropriate ioctl for device
ioctl("TIOCMGET"): Inappropriate ioctl for device
1#
First, check the port in your IDE. In Arduino tools->port
If the port is hidden or you can not move the cursor over this then run this commands in your terminal.If everything ok then skips this and follow the second part.
sudo apt-get install librxtx-java -y
sudo usermod -aG dialout $USER
sudo apt-get install gnome-system-tools
2#
After this again check the first method. If it is not working then run this commands
ls -l /dev/ttyACM*
sudo usermod -a -G dialout <username>
You probably have another program running which is already using this port.
You should close most other programs like putty or another serial monitor app.
Otherwise, try to reconnect the Arduino to the PC.
I know that these ideas below come from using a Teensy, but they may help you.
Sometimes there are the ACM* ports listed in the Arduino IDE. Try looking at the ser ports. I know when I am running my Teensy, sometimes I have them switched and need to select the correct one.
Also, from my experience with the Teensy, you might need to add a udev rule to allow permissions to access the port from non-root user. Here is the link that shows the udev file.
There is no direct way to solve this issue. In addition to it, you are not using an IDE. I will list the things you need to check, I am sure this will solve your problem.
I am not good at Linux environment so I will refer to applications names as window, you go the corresponding application in Linux.
Go to linux device manager and see for your arduino board. It should have proper naming like "arduino uno at port 3", then use the correct port in your command. If this name does not come properly then it means Driver is not available in your machine. So, go to step2.
Find the driver online and install it in your system, I am not sure about the support of linux with arduino, once it is done please repeat step1.
So, I conclude in short that you do not have the proper driver (which is strongly believe) or pointing the wrong port. I am not an expert with the udev rules, but it is definitely an issue you can experience with these kinds of micro-controllers.

Serial Ports Linux vs Windows

I am having issues with my pyserial program on Ubuntu 16.
I am trying to send a break command to a hardware device using pyserial. I wrote a python script that:
Sets the port/baud/parity/bytesize/...
Opens the port
Sends a break command
Reads the return message from the device.
I run the script on my Ubuntu 16.04 machine and I get zero response, it just hangs or eventually timeouts. I copy the same script to my Windows machine, change the port (from /dev/ttyUSB0 to COM#) and my script works perfectly, gets a response from the device immediately.
When I run the script on Ubunutu I have to give permissions to the port (sudo chmod 666 /dev/ttyUSB), or I get permission denied errors when opening the port. Not sure if this matters.
Does anyone have any insight on what might be going on? I know Windows and Linux handle serial/com ports differently but I am a newbie to both Linux and serial so not sure if I am missing something.
I am using this USB to Serial cable (http://www.ugreen.com.cn/product-681-en.html) and I had to install some drivers. I connected the serial read/write pins and tested to make sure data is going through (which it is) so I know that works.
import serial
ser = serial.Serial()
ser.port = '/dev/ttyUSB0' # or COM12 on windows
ser.baudrate = 9600
ser.parity = serial.PARITY_NONE
ser.bytesize = serial.EIGHTBITS
ser.stopbits = serial.STOPBITS_ONE
ser.open()
ser.send_break(duration=0.9)
print(ser.read(10))
First off, you need to have proper permissions for accessing serial ports. It can be done by including your user into the group dialout:
sudo usermod -aG dialout <user>
You need to restart the system to complete it.
To avoid of some information to remain in buffers, you may need to clear read and write buffers before serial port operations:
pyserial 3.0:
ser.reset_input_buffer()
ser.reset_output_buffer()
pyserial 2.7 or earlier:
ser.flushInput()
ser.flushOutput()
Don't forget to close a port after all operations being done. Hope this helps.
First forget about your app and focus on the port troubleshooting, use putty in serial mode for sending a few terminal chars using this port. Use a jumper for conecting DB9 pin 3 to pin 2(rx and tx) an validate that you receive an echo of each character you type.

Trouble locating my serial ports using bash on Windows 10

I want to be able to read from serial ports on my computer and write to a file. Inside /dev (using Bash shell on Windows 10) I can't seem to locate my USB serial ports (I have tty, tty0, tty1, and that's it for tty).
Is it located somewhere else, or even accessible through the bash shell? I just want to be able to know how to access it at this point.
In device manager, COM4 shows up under ports when I plug in my USB. I also ran the command wmic path Win32_SerialPort in the Windows command prompt and it said "No Instance(s) Available." So I'm very confused as to how I can view my Serial Ports and why they aren't showing up in certain instances.
Any clarification on how serial ports work, especially with USB, would be greatly appreciated, as I am pretty new with this stuff.
Soon, Windows will officially support serial on the Windows Subsystem for Linux (WSL). The COM_n_ ports will be available at /dev/ttyS_n_
Mapping:
COM1 >> /dev/ttyS0
COM2 >> /dev/ttyS1
...
COM192 >> /dev/ttyS191
A good functional description can be found here:
https://blogs.msdn.microsoft.com/wsl/2017/04/14/serial-support-on-the-windows-subsystem-for-linux/
NOTE: At time of writing this feature is only available on the insider builds.
I have the same problem. Apparently you still can`t use serial ports in Bash on Ubuntu on Windows (BoUoW).
You can do basic read and write operations using socat. I used Cygwin to create a socat server that sees my serial ports. I had problems with DTR and RTS pins though.
With socat you can create virtual serial ports or forward a serial port over TCP. (And much more.)
In Cygwin serial ports are listed under /dev/ as ttyS*.
For example COM3 is /dev/ttyS2 and COM4 is /dev/ttyS3.
Start the server in Cygwin with
socat -d -d -d TCP4-LISTEN:2022,reuseaddr,fork /dev/ttyS3
Start the client on BoUoW with
socat PTY,link=/tmp/vmodem0 TCP:localhost:2022
This will create a virtual serial port in BoUoW at /tmp/vmodem0 that is connected to COM4 on your machine.

How to display linux printk() messages in virtual console (tty1)

I'm trying to solve problem with linux printk() messages (Linux raspberrypi 3.6.11+ #87 PREEMPT Fri Feb 7 00:17:11 CET 2014 armv6l GNU/Linux).
What I have is a kernel module which implements unlocked_ioctl function from struct file_operations. When I call this function from user space with specified cmd=CMD_PRINTK, the following code is executed:
case CMD_PRINTK:
{
printk(KERN_EMERG "TEST KERN_EMERG\n");
printk(KERN_ALERT "TEST KERN_ALERT\n");
printk(KERN_CRIT "TEST KERN_CRIT\n");
printk(KERN_ERR "TEST KERN_ERR\n");
printk(KERN_WARNING "TEST KERN_WARNING\n");
printk(KERN_NOTICE "TEST KERN_NOTICE\n");
printk(KERN_INFO "TEST KERN_INFO\n");
printk(KERN_DEBUG "TEST KERN_DEBUG\n");
}
What I was expecting is that amount of displayed messages will depend on second value of
root#raspberrypi:/mnt/raspberrypi/linux/linux/mod# *cat /proc/sys/kernel/printk*
7 **4** 1 7
But what I observe is only the first message "TEST KERN_EMERG\n" which is printed by syslogd btw on every virtual terminal (pts/1...)
In kernel command line I've specified the console as tty1
root#raspberrypi:/mnt/raspberrypi/linux/linux/mod# *cat /proc/cmdline*
dma.dmachans=0x7f35 bcm2708_fb.fbwidth=1824 bcm2708_fb.fbheight=984 bcm2708.boardrev=0x3 bcm2708.serial=0xf8900c76 smsc95xx.macaddr=B8:27:EB:90:0C:76 dwc_otg.lpm_enable=0 **console=/dev/tty1** root=/dev/nfs nfsroot=192.168.1.102:/home/borys/rpi_rootfs ip=192.168.1.103:192.168.1.102:192.168.1.1:255.255.255.0:rpi:eth0:off rootfstype=nfs
I tried to use minicom to connect to /dev/tty1 but still I cannot observe any messages displayed there.
I tried to kill syslogd but it didn't help.
At the moment I think that I don't understand something about virtual terminals. I had setup with STLinux platform and console specified as serial port (/dev/ttyAS0) and I was able to connect with serial cable from my host computer and I saw all printk() messages.
Can someone explain how to display kernel printk() messages in virtual terminal via minicom connection?
Is it possible at all?
Will it be possible to control printk() messages verbosity then?
Updated: 05.05.2014
My colleague found first mistake in my cmdline. It should be
**console=tty1**
not
**console=/dev/tty1**
because filesystem is not available at the moment of cmdline parsing. After this change I can see debugs in virtual terminal and using
dmesg -n x
as suggested by oakad below, I can change its verbosity.
This is almost but not certainly what I wanted actually. The one thing which I'm still missing is the connection to vitural terminal tty1 via minicom.
Currenlty I can see kernel logs only on the screen connected to my raspberry pi or via serial interface ttyAMA0.
Additionally when I run my test on PC I can see kernel debugs if I switch to virtual console via Alt+Ctrl+n where n is the number of virtual console.
What I would like to have is for example:
ssh session to raspbery pi in which I start minicom and specify tty1 as a port.
The same in case of PC I would like to start xterm (/dev/pts/n) in which I start minicom and specify tty1 as a port.
Unfortunatelly both, in case of rasberry Pi and in case of PC I cannot see kernel debugs in such minicom session. In case of raspberry Pi I tried to send file from minicom and I saw it was working - file content was displayed in display connected directly to rasberry pi. Unfortuanatelly logs from rasberry to minicom are not transferred or are stucked somewhere. Does anyone could tell me if such method for kernel logs display is possible at all?
You can set your console "verbosity" level with dmesg -n x, where x is the name of the "minimal" message priority you want printed out to the console. Try saying dmesg -n debug to see everything on the console, KERN_DEBUG messages included.

Resources