I am using Win10 and Linux Ubuntu on WSL 2.0.
For testing purposes of some programs, I would like to use the serial port of my PC in "loopback" with Linux running through WSL.
Basically I would like a process on Linux/WSL to be able to send/receive data from a Windows process or vice versa, through serial port, but without any hardware hack.
Of course I have already tried to set the Windows process serial as "COM1" (as indicated by the Windows resource manager) and the Linux port on WSL as "/dev/ttyS1", but apparently it doesn't work.
Is there any way to do this?
Status update
According to other answers, it seems that the addition of product functions has made it possible to use USB devices with WSL2.
Especially in v5.10.93.2, it seems that drivers for two types of USB serial interface chips are built in.
linux-msft-wsl-5.10.93.2
Enable CH341 and CP210X USB Serial drivers
linux-msft-wsl-5.10.60.1
Enable USB over IP support
Enable USB kernel configuration options for interacting with an Arduino over USB
The following is outdated information.
WSL 2.0 does not support serial ports.
Exceptions for using WSL 1 rather than WSL 2
WSL 2 does not include support for accessing serial ports. Learn more in the FAQs or in WSL GitHub repo issue on serial support.
The following options are possible.
Revert to WSL 1.0 and use
Use third-party products
For example, there seems to be something like this.
Windows USB Server
VirtualHere USB Server
Although it is a Japanese article, there is such a trial article.
WSL2でUSBデバイスを認識させる
Also, if you want to communicate between serial ports even if WSL2 cannot recognize USB serial, this method is also available.
Connecting to serial port (com port) over network
And as you can see from the above explanation, if you want to communicate between the processes of each OS, you can simply use a TCP/IP socket instead of the above mechanism.
Run this in PowerShell or CMD to see if you use Version 1:
C:\>wsl -l -v
NAME STATE VERSION
* Ubuntu Running 1
If yes, here's some tested working code to read COM14 from linux command prompt:
#!perl -w
use strict;
$|=1; # autoflush
use Device::SerialPort;
my $port = Device::SerialPort->new("/dev/ttyS14");
$port->baudrate(115200); # Configure below to match your device
$port->databits(8);
$port->parity("none");
$port->stopbits(0);
$port->debug(1);
$port->read_char_time(0); # don't wait for each character
$port->read_const_time(1); # 0.001 second per unfulfilled "read" call
while (1) {
my ($count_in, $str_in) = $port->read(255); # Supposedly must be 255 always
if($count_in) {
print $str_in;
}
}
If you are running WSL2, you can backup, convert or copy your distribution to WSL1 via wsl --export, wsl --import, and wsl --set-version. See this question among others for details.
Related
I have a custom i.MX6Q-based board with working U-Boot and Linux (Ubuntu) setups. The micro and board have support for USB-OTG and one serial port; currently, the serial port serves the console for both U-Boot and Linux. However, we may need to use the serial port for another purpose, but we don't want to lose the console for U-Boot and Linux. Is it possible to use the USB-OTG port for the system console for both U-Boot and Linux?
I've done some research and found a couple of promising articles here and here, though the second article says this tidbit:
Unfortunately it won't work as system console as the gadget driver is loaded as a module, but we can use it for serial console.
I'm not sure I understand this, but it sounds like the method won't meet my needs, which is to use USB-OTG for both U-Boot and Linux system consoles. I did try these methods, but without luck, which may mean that U-Boot and Linux aren't built properly for the desired functionality.
So here are my questions:
Can this work for U-Boot?
Can this work for Linux?
Am I insane for contemplating this path?
For either, any guidance (e.g. tutorials, examples, etc.) would be greatly appreciated.
Thanks!
Can this work for U-Boot?
Yes, at least since U-Boot version 2008.10, the README file has stated:
Define the below if you wish to use the USB console.
CONFIG_USB_DEVICE
Define this to build a UDC device
CONFIG_USB_TTY
Define this to have a tty type of device available to
talk to the UDC device
CFG_CONSOLE_IS_IN_ENV
Define this if you want stdin, stdout &/or stderr to
be set to usbtty.
Note that these configuration symbols are not accessible using the menuconfig, and must be enabled in a configuration file.
Currently at least five boards use this U-Boot capability, based on the occurrence of CONFIG_USB_TTY in files in include/configs/, for example include/configs/ti_omap4_common.h.
This USB configuration requires non-default definitions for the stdin and stdout environment variables. Refer to the README documentation for the details.
Can this work for Linux?
Yes, Linux (at least since version 4.5) can have a serial console on a USB connection, either a USB-to-serial adapter on a host port or a USB serial gadget on a device port (using CDC/ACM).
For instance, in drivers/usb/gadget/Kconfig there's the selection:
config U_SERIAL_CONSOLE
bool "Serial gadget console support"
depends on USB_G_SERIAL
help
It supports the serial gadget can be used as a console.
In the Linux 5.7.8 kernel only two boards have default configurations that use this capability, for example see arch/arm/configs/aspeed_g4_defconfig.
Besides a proper configuration to build the necessary drivers, a serial-gadget console requires (1) the kernel parameter specification (e.g. console=ttyGS0,...), and (2) a login session initiated by a getty command (e.g. in the inittab file).
Am I insane for contemplating this path?
No comment.
Beware that should you encounter a kernel boot issue, the Linux serial-gadget console does not support earlycon nor earlyprintk capability.
Personally I prefer to use a serial link that is persistent regardless of the target board's state. That ensures the terminal emulator program does not complain about lost connections.
Addendum
Unfortunately this Linux console on a USB serial gadget does not display boot messages generated by the kernel (before the login prompt), even if all drivers are statically linked in to the kernel image.
Although the syslog has messages like
console [ttyGS0] enabled
g_serial gadget: g_serial ready
...
gs_open: ttyGS0 ((ptrval),(ptrval))
before the salient Freeing unused kernel memory message, the host side does not receive any console messages until userspace is active.
This shortcoming is also reported in this guide: https://linux-sunxi.org/USB_Gadget/Serial
I'm trying to get a check-scanner to transmit image files to my Mac (the company only provides Windows drivers). I have the technical manual that specifies all the commands that can be sent to the device, and I'm trying the most basic commands first (blink the LED, print serial number, etc.).
I have been able to successfully communicate with the device using "Serial Tools", but I'm trying to use bash for more control of the input/output and to eventually write an automated script.
After reading a few other posts and trying several things, so far I've tried this:
Opening the port with stty command and various flags, for example:
stty -f /dev/tty.usbserial-A5002TeW speed 9600 cs8 cread clocal
stty -f /dev/tty.usbserial-A5002TeW raw speed 9600 -cstopb -parity -echo
Trying to send commands over echo:
echo $'LE 100\cM\cJ' > /dev/tty.usbserial-A5002TeW
--Note that the serial device is connected through a USB adaptor, but responds (at least in Serial Tools) as a regular serial device after I installed the right drivers for it.
--I'm trying to use the \cM\cJ characters because as the device was intended for use by Windows boxes I figured I should use their control codes, I've tried multiple permutations of the code.
The Problem:
No matter what happens, the device never responds (no blinky LED lights, no output, etc) and my bash shell hangs until I stop it (^C). I know I can probably use a Python library, and I might wind up doing that, but I'd like to at least see some basic functionality with the bash shell.
Another option would be to try to get it working under a VM (VirtualBox, Fusion, Parallels, etc.) by installing Windows in the VM on your Mac.
Most cumbersome solution, because you'd have to reboot all the time, dual boot your Mac into windows.
Finally, I have an app on my iPhone from my banking institution that simply uses the camera in the phone to photograph the front and back of a check, and they'll accept it that way. This might be an option.
In the world of printers, particularly the POS ones, there are two common approaches, OPOS and Windows print queues. And there's also the work-around like the virtual serial port. But there seems to be another approach out there too ... the driver is installed but the software seems to be writing directly to the port rather than using the windows spooler.
If you look at the spooler ports when an Epson USB printer is installed for example, there is a ESDPRT001 ... could it be that the POS app is writing to the port directly and bypassing the whole spooler?
According to Epson's product description of OmniLink no driver is required. It is quite possible that the spooler has been outsourced to the powerful onboard computer, which is operating at ~400Mhz. Just a guess.
You don't need a driver for Epson's OmniLink. If your spoolsv.exe isn't working, look into this though.
I'm running a Core Duo Macbook pro and I'm trying to emulate a 3G connection for connected devices via wifi internet connection sharing. I've tried a few options (e.g. speedlimit) but they only impact the macbook's browser and not the connected devices. Are there any other options out there? I'm running leopard as anything more modern overheats the system.
I have a T60 as an alternative, but the intel 3935abg chipset isn't supported by any windows 7 VirtualMiFi tools, and I need to connect Android devices to this network.
I found this very useful tool for testing various types of connection.
Slowy app: http://slowyapp.com/
It has some preset (56K, EDGE, 3G, LTE and DSL) but allows you to set various parameters to limit the network traffic to a specified destination port or interface.
I recommend everyone to try it.
You are in luck - your version of OSX should still support IPFW; so one can do
sudo ipfw pipe 1 config bw 15KByte/s
sudo ipfw add 1 pipe 1 src-port 80
to cut down anything, in above example for port 80. Be sure to make the rule cover the traffic going through your mac. See http://intrarts.com/throttled.html
or http://www.hanynet.com/waterroof/ for friendlier tools.
Beyond Leopard - you want to look at pfctl. http://blog.segment7.net/2009/07/27/bandwidth-limiting-with-pf-and-altq and http://www.openbsd.org/faq/pf/queueing.html are good starts. Note though that by default you cannot use ALTQ (it is not in the default OSX kernel).
I am trying find out how and with which program for OSX (10.5.8) I can configure serial ports? I am trying to establish a wireless connection between two Xbee´s (RF modules) and cannot figure out how to use ZTerm nor screen under Terminal. The setup I am using is: an Arduino+Xbeeshield+Xbee with external power supply, and an xbee on the xbee explorer connected to the Computer via USB.
I am trying to gather information on this through various forums, but most of them cover the configuration issue for PC using X-CTU (which I tried with CrossOver but it doesn´t recognize ny of my ports). According to one source, using screen under Terminal should show me all my serial ports, particularly /dev/tty.KeySerial1 - but it doesn´t show, even though I´ve plugged in both my arduino+xbee shield and the xbee on the explorer.
/dev/tty.KeySerial1 is incorrect.
First step is to get the FTDI USB driver installed if it has not yet been installed. The fastest way to determine if it is installed or not is to connect the XBee Explorer board. Then go look in /dev for a device named tty.usbserial-XXXXXXXX (Xs will be a unique hex ID). If you see multiple devices like this, then you probably have the Arduino plugged in too and you will need to disconnect it to determine what the device name is for the XBee Explorer board.
Once you know the device name, all you need to do is the command "screen /dev/tty.usbserial-XXXXXXXXX 9600". That should do it for you.
You can configure the tty device itself using stty. Be sure to redirect input from the terminal you want to configure, as stty operates on it's input. For instance, to set a serial port to 9600, no parity, 8 data bits, and 1 stop bit, aka "9600N81" in Windows parlance, try:
stty 9600 cs8 -cstopb -parenb < /dev/tty.usbserial-xxxxxxxx
Programmatically, you do this by opening the serial port and using the termios(4) ioctls on the device. See the termios(4) man page for more assistance.