I'm developing a program that sends a file from one computer to another between a RS232 serial port.
I can test it on the school computers just fine, but I would like to be able to test it at home. So I'm trying to connect 2 virtual machines between a virtual serial port in vmware fusion, but I don't understand how to configure it.
I've installed the 2 virtual machines and added a serial port to each one (in the settings). But the only available option is to name the file that the serial port will use. This name will be used how?
I'm working with the /dev/ttyS1 port, can I still use it normally, and somehow redirect the output to the file that was configured?
So, it was easy. You have to use the same file in each virtual machine. When you try to save the same file on the second vm it warns you that the file already exists, just say you want to replace it. Go into the share settings of each virtual machine and add the folder where the file is stored on your computer, and give it read and write permissions. In my case is the same folder where I keep the vm files. Now I just have to open the file and exchange info between the 2 vm's. I had to comment a few things in my code (it's not a real serial port)but at least I can simulate it well enough.
Related
I'm developing a project on an embedded Linux device in C, which uses those two USB drivers on the same USB cable:
g_printer(Linux USB Printer Gadget Driver)
g_serial(Linux Gadget Serial Driver)
When the user selects USB Virtual COM Mode, the program will:
Check whether the device file /dev/g_printer0 is opened, if yes, close the opened file descriptor.
Check whether the g_printer is installed by using system("lsmod | grep g_printer > /dev/null");, if yes, use system("rmmod g_printer); to uninstall it.
Check whether the usb_f_printer is installed by using system("lsmod | grep usb_f_printer > /dev/null");, if yes, use system("rmmod usb_f_printer); to uninstall it.
Install the g_serial by using system(modprobe g_serial);
Open device file /dev/ttyGS0
When the user selects USB Printer Mode, the program will do almost the same steps as above, but uninstall g_serial first and then install g_printer(also the closed and opened device files are different).
But the whole Linux system crashed at step 3 when it switches from USB Printer Mode to USB Virtual COM Mode, the log shows:
rmmod: can't unload module 'usb_f_printer': Resource temporarily unavailable
In addition, this Linux kernel is customized, after the system boots, the g_printer is automatically installed by the kernel, but the /dev/g_printer0 is not opened yet, so at this time, if I switch to USB Virtual COM Mode by using the steps above, it works with no errors(and the system won't crash of course), so it means I have another weird way to let the user switch between those two modes, that is when user wants to switch the mode, the system won't switch it immediately but save this selection in the configuration file, then it reboots the system, after the reboot, the program will check the configuration file to decide whether switches to USB Virtual COM Mode or just open /dev/g_printer0 to be ready for use. But this is too weird :(.
I can't kill this process because this is the only process running in this device, and also I can't exec another process to do this USB communication stuff because it's kind of wasting memory and computing resources.
So I have two questions:
Is there any way for the user to switch those two modes without rebooting the Linux system?
Does it means, once a process opens the /dev/g_printer0 device file, this driver can't be uninstalled but only reboot the system or kill the process? (even if I have already closed the opened device file)
I installed MicroStack in Ubuntu for the virtual machine. My instance floating IP is 10.20.20.238. I want to access my instance from Windows cmd,only can ping 172.21.10.13, but can't ping 10.20.20.238,so I want to change the 10.20.20.1 network to my own network. What should I do?enter image description here
Stackoverflow is about code development, not IT management. serverfault.com would be a more appropriate forum, or perhaps superuser.com.
microstack "fakes" the external network. It's not really external, but only exists on br-ex, the external bridge. It doesn't look like you can create a microstack cloud with a different external network CIDR, but you can try adding a subnet to the external network, inserting ens33 in br-ex and adding IP address 172.21.10.13 to br-ex . I have not tried this.
However, if your only requirement is to access the instance from the PC, you can create a tunnel or add a route. What makes sense in your case depends on the virtual machine hypervisor you are using (yours seems to be VMware - I can't comment on that) and the operating system on which this hypervisor runs.
I am trying to figure out from C code in linux if an interface is configured as static or uses dhcp.
I know I can open and parse the /etc/network/interfaces file, but I would prefer something cleaner, like the function getifaddrs() that I use to get the IP address and the mask. Because what if the interface is configured as dhcp in /etc/network/interfaces file but later on the user changes it to static from the command line? I would get a wrong answer.
Is there any way for asking the kernel about the static/dhcp current state of an interface?
The kernel (the Linux part of e.g. GNU/Linux) doesn't decide, it doesn't (and shouldn't) care, it just gets told which network addresses go with which interfaces by whatever configuration system the OS is using. OpenWRT's not GNU, it operates differently
DHCP IP address adquisition is usually managed by distribution scripts or network manager services configured by host. At low level they could use dhclient daemon...
In Debian, dhclient daemon creates the file
/run/dhclient.${interface}.pid
so, you could test when the interface is being set by dhclient.
In not fully managed network environment you should also read that file and test if the process ID is still alive.
I'm trying to learn how to write C code that will read from the serial port in Linux. I've found what seems to be a good tutorial here.
I want to be able to test this code, so I think I need either a serial port, or a way to write to the serial port while the code from above is reading.
I'm running Ubuntu 10.04 as a virtual machine on my Mac using virtualbox. My idea was to set up a virtual serial connection and write from the host to the guest. Hopefully something as simple as cat "Hello World" > /tmp/fake_serial in a host terminal, and for that to be read by the program in the link above.
Is this possible? I've tried adding a serial port using virtual box and when I try to do the above command I get an error saying I can't write to a socket.
The second option I thought of was using something like minicom inside the guest OS, to connect to say /dev/ttyS1 and write messages for my code to read at the same time. Again, assuming that the baud rates and other settings are OK, would this be possible?
I don't have a lot of experience working with serial ports, so I'd appreciate any suggestions about the best way to do this. Thanks in advance.
So to get this working I just added another Ubuntu VM on VirtualBox, and connected the two together via a virtual serial port. My main, original VM, which I use for a lot of developing will be referred to as VM1. The new VM, with a small hardrive that will only be used for sending messages to VM1 will be called VM2. These are both Ubuntu 10.04 VMs.
In VirtualBox go to Settings for VM1, go to ports, and change the settings as follows:
Now go to VM2, and select settings, ports, then change as follows:
Now first you need to start VM1. When that's booted then boot VM2. Now you can open a terminal in VM1, and type screen /dev/ttyS0 38400 (you may need to run sudo apt-get install screen before this works). Then go to VM2, open a terminal, and type echo "Hello" > /dev/ttyS0.
You should see Hello appear in the terminal open in VM1. When you're done running screen press ctrl-a k to kill it, otherwise if you try to do other stuff with the serial port you may get an error message saying that the port is busy.
When I had to do some serial port testing from my real to virtual machine I ended up doing a "loop back" type testing. I took two USB-Serial converters and a RS232 F-F adaptor and connected my machine to itself. Then in VirtualBox under Settings->USB you can route one of the two USB-Serial converters to be "owned" by your VirtualBox.
Once you plug in the converters one will register with the Mac and one with the Ubuntu "computer" then you can do serial communication as normal between the two machines.
You may also be able to emulate a virtual serial port using a pty ("pseudo-teletype" device), but I'm not positive on that one since I believe the ability to do that was locked down in newer kernels.
I ran into a similar situation running a QNX guest using VirtualBox 5.0.10 on an Ubuntu 14.04 host.
My solution seems general enough to apply to the above-mentioned case.
I configured the guest VM in the same way that Kells1986 setup his VM1:
Under the "Serial Ports"/"Port1" tab:
check "Enable Serial Port"
set "Port Number" to "COM1"
set "IRQ" to "4"
set "I/O Port" to "0x3F8"
set "Port Mode" to "Host Pipe"
uncheck "Connect to existing pipe/socket"
set "Path/Address" to an accessible file-system path (e.g. "/home/safayet/vmSerialPipe")
According to the VirtualBox manual:
You can tell VirtualBox to connect the virtual serial port to a
software pipe on the host. ... On a Mac, Linux or Solaris host, a local domain socket is used ... On Linux there are various tools which can connect to a local domain socket or create one in server mode. The most flexible tool is socat and is available as part of many distributions.
A domain socket is an IPC mechanism on UNIX systems similar to a pipe.
I connected to the "pipe" end of the virtual serial port on the Ubuntu host using the socat command:
socat - UNIX-CONNECT:/home/safayet/vmSerialPipe
Is there any class or library for the Silverlight 4 print directly to parallel port (LPT1)?
Once you have an OOB Silverlight app with Elevated Trust that can access the local file system, you can make an attempt and dumping data to the parallel port with the file system apis. The name of the LPT device will be \\.\LPTx where x is the dos lpt port number that was mapped by windows. You can find this in the registry under HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\PARALLEL PORTS . On my machine it has the key
\Device\Parallel2 maped to \DosDevices\LPT3 so on I would use the file name "\\.\LPT3" to access the prallel port as if it was a file. Just to be clear that is 2 slashes, a dot then another slash before the port name.
Not unless your Silverlight app is a OOB with Elevated Trust and the client has installed on it some COM component that can manipulate the parallel port.
So basically: No.