taitex

  • *
  • 24
Reading UAVObject from a CC3D USB port
« on: June 13, 2016, 07:24:38 pm »
I want to read UAVObject from my CC3D board. LibrePilot works fine with a USB cable connected to my CC3d. It is using the device "CopterControler Virtual COM Port (COM7)"
I want to do this in my own program too. I have written code in .NET C# that successfully parses the UAVTalk stream and tested this against OPL files generated with LiberPilot.
But when I open the same Virtual Port COM7, I get an IOException: "Device attached to the system is not functioning" with the code:
 var serialPort = new SerialPort( "COM7", 9600, Parity.None, 8, StopBits.One );
 serialPort.Handshake = Handshake.None;
 serialPort.Open();

I've tried various baud rates too.

I've looked at the serialplugin.cpp and port.cpp code from LibrePilot GCS and they don't seem to be doing anything special or different to access the serial port.

Eventually I will be reading this UAVTalk stream from a Optlink device. But I want to get this working directly while I wait for the devices.

Any suggestions or insights would be appreciated.

hwh

  • *
  • 1018
Re: Reading UAVObject from a CC3D USB port
« Reply #1 on: June 13, 2016, 08:13:51 pm »
If GCS is using COM7 instead of it's usual HID port then you must have already reconfigured the CC3d on configuration -> hardware to disable the HID port and enable the VCP for telemetry as shown in the attached picture.  It should be running at 57600 baud.  You should be able to open it in any programming language and get the telemetry.  GCS can't be running at the same time of course since only one program can connect to the com port at a time.

Remember, once you did this the normal GCS connection named "coptercontrol" will connect to GCS but not work since telemetry is no longer going to it.  You have to use the serial connection to configure the cc3d while telemetry is going to the VCP.  You connect via serial, move the usb telemetry back to the hid port and disable the VCP, save, and then reboot the cc3d to get the normal connection back.


taitex

  • *
  • 24
Re: Reading UAVObject from a CC3D USB port
« Reply #2 on: June 14, 2016, 04:51:06 am »
As usual HWH, you were right. I changed my CC3D config to disable HID and send telemetry to the VCP (before this, I didn't get that VCP meant Virtual Comm Port, duh). Now I am able to successfully Open the serial port.

After a successful Open, I try to Read a byte. But this blocks as no data is available for reading! Perhaps I am not understanding  UAVTalk. Do I have to Write to the port to request object before it will send any?

I've tried this with:
 // 0xAD3C0E06 ACCELSTATE_OBJID 12
 byte[] objReq = { 0x3C, 0x21, 0x0A, 0x00, 0xAD, 0x3C, 0x0E, 0x06, 0x00, 0x00 }; // tried reversing the byte orders of the fields too
 serialPort.Write( objReq, 0, 10 );
...before reading but still reading blocks as it seems CC3D isn't sending anything.


How do I reset LiberPilot to use HID? By default, it connects with CopterControler (HID) when plugged in. I must manually press the Disconnect button. Then select "Serial COM7" and Connect. But when this is done, LiberPilot still does not see the HW; Configuration & Firmware tabs empty, System Settings all disabled, etc.... Just System Data Objects GCSTelemetryStats shows it is trying to write bytes. Where can I reconfigure it back to use HID?

FYI, disconnecting the USB plug while in this mode crashed LiberPilot. Let me know if there is any info yall may want to help debug this?

hwh

  • *
  • 1018
Re: Reading UAVObject from a CC3D USB port
« Reply #3 on: June 14, 2016, 05:56:38 am »
...Do I have to Write to the port to request object before it will send any?...
No, you can send commands but it should have a continuous stream of data coming in.
If connecting to com7 with GCS (assuming that's the correct port) doesn't give you the configuration screens something is wrong with the settings in the cc3d.

...How do I reset LiberPilot to use HID?...
If you disconnect the board, go to the firmware tab, click "upgrade and erase", and connect the board when it says to it will reload the firmware and clear all the settings (including HID) back to the defaults.

taitex

  • *
  • 24
Re: Reading UAVObject from a CC3D USB port
« Reply #4 on: June 15, 2016, 03:26:34 pm »
Under Windows 10, I've used the Device Manager to confirm that the port I'm using is correct. It is the only serial port on the machine that is returned also.
I've tried to read the CC3D, Oplink, and Revoluition. In all cases LibrePilot reads it first. Then I close the application, and run code I showed above to simple read the bytes. It opens the port but blocks on the ReadByte because none are available.
I've looked at the python code from alessiomorale and it also just opens the serial port and reads single bytes. But this code runs on Andriod, not Windows.
The LibrePilot code isn't as straight forward to me as I was not sure it isn't reading from a USB device directly. I ran my code and until I blocked in the debugger while reading the first byte. Then I ran LibrePilot. LibrePilot ran and updated everything from the Revolution board. This tells me that LibrePilot is NOT connecting via the VCP serial driver because it is opened by my program.
Is there a different VCP driver that I should try? The properties for the VCP Revolution show the baud rate at 9600. I try to change it in the properties dialog but the changes don't stick. In my code I open it at 57,600 which I assume will override the driver setting.
There are I think four different HID devices added when I plug in my Revolution.
Has anyone opened the VCP serial port in and read the bytes (not directly via the USB device as LibrePilot seems to)?
I'm using C# and .NET SerialPort class on Windows 10. I've tried everything on a laptop and a desktop.
Any other suggestions as to what might be going wrong with this simple task are appreciated.

hwh

  • *
  • 1018
Re: Reading UAVObject from a CC3D USB port
« Reply #5 on: June 15, 2016, 05:14:50 pm »
To be clear, you made the changes to enable the VCP that I gave you a couple of posts back but you still can't read data from the VCP?   At the same time you can start GCS, use the dropdown in the lower right to connect via COM7 instead of the normal HID port, and GCS works fine?  That doesn't make any sense.

Telemetry is hardcoded to 57600 in 15.09, in next it can be changed.

The python code should run on any platform.

taitex

  • *
  • 24
Re: Reading UAVObject from a CC3D USB port
« Reply #6 on: June 16, 2016, 11:34:47 am »
Yes, made changes you suggested and can't read from the VCP. You misunderstood. I said LibrePilot can not connect with the COM port either. See attachment.
I've tried all these things with Oplink, CC3D, and Revolution. They all fail to deliver any bytes to the VCP when configured and rebooted.
On one of my systems in the Device Manager I tried deleting the Copter Controler VCP driver. When I plugged the CC3D back in, is just created a stander USB Serial driver. But it did not help; still couldn't read in LibrePilot or my code.
Possible that release 15.09 will not send telemetry out the serial USB port or VCP driver not working correctly or Windows 10 has an issue...??? Just guesses.
Has anyone tried running LibrePilot with a VCP connection on 15.09 under Windows 10? If so what was the result?

hwh

  • *
  • 1018
Re: Reading UAVObject from a CC3D USB port
« Reply #7 on: June 16, 2016, 06:54:02 pm »
...Possible that release 15.09 will not send telemetry out the serial USB port or VCP driver not working correctly or Windows 10 has an issue...
15.09 sends telemetry on my Linux system with the settings I posted. I just tested it again.  It works both with 15.09 and the latest next branch of the code. I don't run windows so I can't check windows 10 or any other version.

It's possible Microsoft has a problem with their VCP driver but since it's used by a lot of other things it seems unlikely.

I don't know what else to suggest.  If you had a USB-serial adapter you could try hooking it to main or flexi port and sending telemetry to it.

« Last Edit: June 16, 2016, 07:12:51 pm by hwh »

taitex

  • *
  • 24
Reading COM port in GCS, etc... broken in Windows
« Reply #8 on: June 20, 2016, 03:13:28 pm »
I've spent a week trying to read telemetry data programmatically from the serial port. I've tried it using a CC3D, Revolution, and Oplink. I've tried setting the GCS to read from the COM port but this also fails under Windows 10.
Thinking this may be an Windows 10 problem because it has been reported to work in Linux, I partitioned my HD and install a clean image of Windows 8.1. Did nothing else to the new OS but add LibrePilot. Then I configured to read from the COM port. It also fails.
(Yes, see above, I've configured the devices to send out the VCP).
I believe this configuration rules out the possibility of the wrong drivers. But doesn't rule out the possibility of a problem with anything LibrePilot installs?

Does anybody have LiberPilot reading telemetry from the COM port under Windows (preferably 10) on the latest release 15.09????????

If so, please tell me your configuration for any of the 3 devices I've tried and GCS, etc....
I will try anything you want to get the person familiar with this area information to help debug the GCS, driver, or firmware.


hwh

  • *
  • 1018
Re: Reading UAVObject from a CC3D USB port
« Reply #9 on: June 20, 2016, 11:32:22 pm »
I've polled the developers and no one had any answer. I loaded Windows 10 on an old laptop and confirmed that it also doesn't work for me on Windows.

I created a Jira Issue (bug report) for it  https://librepilot.atlassian.net/browse/LP-341

Re: Reading UAVObject from a CC3D USB port
« Reply #10 on: December 21, 2016, 09:25:19 am »
Hello, I know this post is quite old but I faced exactly the same problem with no luck.
I wanted to ask you if you finally solved the issue, because I'm in a dead end because of this same problem: Telemetry + c# + usb

Thanks in advance.

hwh

  • *
  • 1018
Re: Reading UAVObject from a CC3D USB port
« Reply #11 on: December 21, 2016, 05:51:25 pm »
It was fixed back then.   If you're running the current 16.09 release it should work.

Re: Reading UAVObject from a CC3D USB port
« Reply #12 on: January 02, 2017, 10:03:03 am »
Thanks for the info. I can't find the 16.09 release. Could you help me to find it?
Thanks a lot.

Mateusz

  • *
  • 808
Re: Reading UAVObject from a CC3D USB port
« Reply #13 on: January 02, 2017, 10:15:10 am »
Thanks for the info. I can't find the 16.09 release. Could you help me to find it?
Thanks a lot.

Go to http://www.librepilot.org/ and click on Download it will open wiki https://librepilot.atlassian.net/wiki/display/LPDOC/Downloads