How to check serial connection between 2 Linux PCs - linux

I need to connect 2 linux PCs via serial port. I used serial connector cable (null modem cable) to connect 2 linux PCs. But now how can I establish the connection I mean how can I test whether they are connected or not. Can anybody Please let me know the procedure.. I have tried screen command and when i run
screen /dev/ttyS0
This command is just opening new screen and i cant do anything on that new screen.
Am using Fedora-20 with kernel version 3.* in one PC and another one with Fedora-27 kernel version is 4.13

Hi finally i found solution to my problem Using this_link.
at both ends tried below steps:
1) yum install minicom
2) Then I configured minicom using minicom -s then using down arrow selected serial port setup
then pressed A from keyborad to change that serial device from
/dev/modem
to
/dev/ttyS0
press enter and chose save as dfl option then exit from minicom
After these configuration steps executed the commands suggested by #Niall Cosgrove
at one end executed cat /dev/ttyS0
at other end executed echo hello > /dev/ttyS0
finally i got hello message from one pc to other end using serial port:)

Related

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.

Problems with serial communicaiton on Raspberry Pi 3

I am trying to establish communication between a Raspberry Pi3 and a digital Sensor that has a RS-232 connection. I have bought a hat that also has a RS-232 port on it and can be connected to the rx and tx pins on the Pi. The Pi has raspbian installed and I am using Python 3 to write the code.
In the tutorials I read it says that i have to configure the Pi first to allow serial communication. I have done following steps:
Step 1:
sudo raspi-config -> Interfacing Options -> Serial -> [login shell accesible over serial? -> no] -> [serial port hardware enabled? -> yes]
Step 2:
sudo nano /boot/cmdline.txt
change line to:
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
Step 3:
sudo nano /boot/config.txt
add lines:
dtoverlay=pi3-miniuart-bt
enable_uart=1
force_turbo=1
Step 4:
sudo apt-get install python-serial
After this setup i wrote a very short program in Python 3 to test it:
import serial
ser = serial.Serial('/dev/ttyAMA0', 9600)
ser.write(bytes(5, 'UTF8'))
The number 5 tells the sensor to change the displayed unit. The code runs without an error message but I dont see the unit of the sensor change. If I connect the RS232 to my laptop with a serial to usb converter and use Putty to monitor the serial port, I also do not see anyting being send.
It would be great if someone can tell me where my problem is. But I would also be happy about any input on how I can find a solution myself.
Many thanks in advance,
Florian
I think Raspberry Pi 3 uses a different device for the serial port. Try
ser = serial.Serial('/dev/ttyS0', 9600)

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.

How to setup serial communication in Processing to /dev/rfcomm0

I am trying to perform serial communication on between Ubuntu 12.04 and a JY-MCU bluetooth serial module connected to an Arduino.
I have created this configuration in /etc/bluetooth/rfcomm.conf
rfcomm0 {
# # Automatically bind the device at startup
bind yes;
#
# # Bluetooth address of the device
device 00:12:11:19:08:54
# # RFCOMM channel for the connection
channel 1;
# # Description of the connection
comment "Linvor Bluetooth Module";
}
I can use putty to communicate with the /dev/rfcomm0 serial port and this works perfectly.
However, despite many attempts I simply cannot see how to create a serial port in Processing that works in any way.
For example :
println(Serial.list());
prints nothing at all.
If I execute:
String portName = "/dev/rfcomm0";
myPort = new Serial(this, portName, 9600);
println(myPort);
I see this in the monitor:
processing.serial.Serial#1712651
But if I then call:
myPort.write('9');
I get an exception:
java.lang.NullPointerException
at processing.serial.Serial.write(Serial.java:572)
...
I can't understand why this fails. I have been following all the instructions from Tom Igoe's "Making Things Talk", but this just does not work the way he says...
Any help would b great!
Thanks,
Bob
Aftert searching high and low, I have made this work.
The key issue is that processing uses the rxtx java library (RXTX-2.1-7) for serial communications.
The RXTX wiki says:
"rxtx tries to detect ports on by scanning /dev for files matching any
of a set of known-good prefixes, such as 'ttyS', 'ttym', and since 2.2
'ttyUSB' and so on. "
And since the bluetooth device is named rfcomm* it cannot be detected.
The trick is to create a sym link to fool rxtx (use a ttyS device that is not yet assigned):
$ sudo ln -s /dev/rfcomm0 /dev/ttyS99
Then, connect:
$ sudo rfcomm connect 0
Connected /dev/rfcomm0 to 00:12:11:19:08:54 on channel 1
Press CTRL-C for hangup
At this point the red led on the JY-MCU becomes solid and processing can detect it:
println(Serial.list());
output is:
[0] "/dev/ttyACM0"
[1] "/dev/ttyS99"
So, serial communication can work.
To summarize, the following process will allow a processing script to communicate via a serial port with a JY-MCU device in a BlueZ linux framework
One time setup:
power up the JY-MCU,
use the following command to get its hardware address, mine is 00:12:11:19:08:54
$ hcitool scan
use that to create the /etc/bluetooth/rfcomm.conf file; you'll note that I chose 0 for the rfcomm device , we need that for connection later:
$ cat /etc/bluetooth/rfcomm.conf
rfcomm0 {
bind yes;
device 00:12:11:19:08:54;
channel 1;
comment "Linvor Bluetooth Module";
}
use BlueMan to pair the JY-MCU.
Every time you want to use the JY-MCU
create the sym link:
$ sudo ln -s /dev/rfcomm0 /dev/ttyS99
connect to the JY-MCU:
$ sudo rfcomm connect 0
Connected /dev/rfcomm0 to 00:12:11:19:08:54 on channel 1
Press CTRL-C for hangup
you can now run a processing script and connect to the JY-MCU with
the code:
String portName = "/dev/ttyS99";
myPort = new Serial(this, portName, 9600);
after running the processing script, be sure to CTRL-C at the
command line to disconnect the JY-MCU.
That should do it!
Ciao,
Bob
Just something popped up in my mind.
I had similar problems that were caused due to channel 1 is already used. If you bind to a channel which already is in use, bad things may happen.
sdptool browse local
Use that command to see which channels are available on your Ubuntu device.

Resources