7

I am running a certain application on Ubuntu (16.04) in VirtualBox, while VirtualBox is running on Windows 10 (host).

In Simulink (running on my host), I have a simulation where at the last stage, I gather some values. I want to output these values over a serial connection at a certain baud rate to the application that is running on VirtualBox (i.e. QGroundControl station).

So first part of my question - VirtualBox:

In VirtualBox, I enabled the serial port and chose a host pipe in port mode, as shown in:

Enter image description here

In the picture you can see that COM6 is used, but I used COM1 and COM2 instead. I got the same result for both.

I am not that used to working with VirtualBox, so I don't really know if this means I have now created a connection between my host and guest or if I still need to activate or connect them in any way?

Second part of my question - Simulink:

In Simulink, I want to output my values using a serial send (because I think that is the easiest way? If there is a better way, please tell me), but if I want to select a port, no ports are shown, as you can see in:

Enter image description here

What do I need to do/change in VirtualBox/Simulink to get my COM port to show up?

Last part - MATLAB:

Because in Simulink, no COM ports were shown. I wanted to check for available ports in MATLAB, but apparently all my ports are closed:

>> info = instrhwinfo('serial')

info =

  HardwareInfo with properties:

     AvailableSerialPorts: {0x1 cell}
           JarFileVersion: 'Version 3.8'
    ObjectConstructorName: {0x1 cell}
              SerialPorts: {0x1 cell}

Access to your hardware may be provided by a support package. Go to the Support Package Installer to learn more.

If I try to open one of my ports by using the fopen()-command, I get this message:

Error using serial/fopen
Open failed: Port: COM1 is not available. No ports are available.
Use INSTRFIND to determine if other instrument objects are connected to the requested device.
Using "INSTRFIND" shows that all ports are closed.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Lis
  • 75
  • 1
  • 1
  • 5
  • From your picture it looks like you haven't selected a COM port using the [Serial Configuration](http://www.mathworks.com/help/instrument/serialconfiguration.html) block, which is why nothing is selectable in the `Serial Send` block. Can you confirm whether or not you've done that? – Phil Goddard Jun 09 '16 at 16:03
  • The view is the same in the serial configuration block. No port is shown at all. But I will change the picture in order to make it clearer, thank you for noticing. – Lis Jun 09 '16 at 16:29

1 Answers1

12

First of all, VirtualBox won't create a serial port for your host. So you have to create two virtual COM ports on the host using some other software and bridge these two ports virtually. Then use one port to connect to Simulink and other must be setup in such a way that VM COM port uses this port.

For creating a virtual COM port on Windows I will be using com0com from Faking an RS232 Serial Port. You can use any software you like.

After installing com0com, open setuppg.exe from C:\Program Files (x86)\com0com.

Enter image description here

Now click apply. Now you will have COM9 and COM10 bridged (it's like COM9 and COM10 are internally connected).

Next we need to connect COM9 port in Host to COM1 port in Guest OS for that open Oracle VM VirtualBox Manager and open the settings of your required virtual machine. Now, select Serial Ports and setup like shown below and click OK.

Enter image description here

NOTE: Windows provides legacy names only for COM ports 1 through to 9. For all other COM ports you must use the full device naming convention under Windows. So if you decide to use COM10 instead of COM9, using COM10 at Path/Address won't work. Instead you have to use \\.\COM10.

Now start your virtual machine, and your ports are ready. Now ports will be shown in Simulink and connect to COM10 in this scenario and in the virtual machine, connect your QGroundControl station to COM1.

Simulink <--> COM10 (Host)

COM10 (Host) <--> COM9 (Host) >> Connected using com0com

COM9 (Host) <--> COM1 (Guest) >> Connected by Oracle VM VirtualBox

COM1 (Guest) <--> QGroundControl station

Community
  • 1
  • 1
Rijul Sudhir
  • 1,964
  • 1
  • 12
  • 18
  • Thank you, I am going to try this immediately – Lis Jun 10 '16 at 09:40
  • That worked for me! Only in the last part of your explanation, I think you may have switched COM9 and COM10, is that possible? Thank you for the help! – Lis Jun 10 '16 at 11:03
  • I don't seems to find any mistakes. Where is it ? – Rijul Sudhir Jun 10 '16 at 15:53
  • I am not sure but it seems more logic to do this: `Simulink COM9(Host) COM9(Host) COM10(Host) >>Connected using com0com COM10(Host) COM1(Guest) >>Connected by Oracle VM VirtualBox COM1(Guest) QGroundControl station` Because COM10 is the one in the VM. – Lis Jun 10 '16 at 17:46
  • Sorry about that. I forgot to change the image. It is because, windows provides legacy names only for COM ports 1 through to 9. For all other COM ports you must use the full device naming convention under windows. So if you put `COM10` at `Path/Address`, it wont work. Instead you have to use `\\.\COM10` – Rijul Sudhir Jun 11 '16 at 06:31