linux OSC/USB write error
Up to Bugs, Known Issues, & Requests
Well, I've got mchelper-v25 far enough along to get it to recognize it when it is plugged in in Sam-BA mode and Programmed. It now also loads the firmware, so it is off to sending OSC messages.
Now when I send an OSC message everything looks good through to PacketUsbSerial::sendPacket and nothing happens. It looks like the write is failing in the following code:
if(port->write(out) < 0)
{
//monitor->deviceRemoved( port->portName() ); // shut ourselves down
return false;
}
else
return true;
Is it correct to assume that the "port->write(out) < 0" is an error condition? If so I'll add a debug statement to that effect. My current guess is that something in the port configuration is not quite setup correctly. That being said, I was able to get it to program the controller using the same device handling code in onUsbDeviceArrived:
if( type == BoardType::UsbSerial)
{
qDebug("BoardType::UsbSerial found");
PacketUsbSerial *usb = new PacketUsbSerial(key);
board = new Board(this, usb, oscXmlServer, type);
usb->open();
board->setText(key);
board->setIcon(QIcon(":icons/usb_icon.gif"));
board->setToolTip("USB Serial Device: " + key);
noUiString = "usb device discovered: " + key;
actionUpload->setEnabled(false);
}
else if(type == BoardType::UsbSamba)
{
qDebug("BoardType::UsbSamba found");
PacketUsbSerial *usb = new PacketUsbSerial(key);
board = new Board(this, usb, oscXmlServer, type);
usb->open();
board->setText("Unprogrammed Board: " + key);
board->setIcon(QIcon(":icons/usb_icon.gif"));
board->setToolTip("Unprogrammed device");
noUiString = "sam-ba device discovered: " + key;
/***
board = new Board(this, 0, 0, type);
board->setText("Unprogrammed Board");
board->setIcon(QIcon(":icons/usb_icon.gif"));
board->setToolTip("Unprogrammed device");
noUiString = "sam-ba device discovered: " + key;
***/
actionUpload->setEnabled(true);
}
Liem, David, and others, do you have any ideas on this issue?
Thanks,
EBo --
It could be an issue in the USB code. All the USB code is from qextserialport, which you can find in the mchelper source tree. Unfortunately, qextserialport hasn't had a release for quite some time, but their cvs repo has some updates that improve things here and there - most of which I've copied over and massaged into working order.
I'm thinking that, since it's used in both mchelper and mcbuilder, that I'll create a separate parallel repo for qextserialport modded to suit our needs. I've updated the mcbuilder version more recently than the mchelper version, so you might do a diff on those to have a look.
Also, generating the qextserialport documentation using doxygen - http://www.stack.nl/~dimitri/doxygen - can be pretty helpful.
Thanks Liam for the reply...
I thought qextserialport was just something you wrote and not an external lib/source. Breaking it into it's own would be great (along with a bunch of the utility stuff in v25/src like the uploader). I'll compare the code between mcbuilder and v25 and read the docs (sorry I missed them). I'll follow up with what I find...
EBo --
Well... I started by copying over the qextserialport source from mcbuilder, hacked in my changes (to recognize the device), and I get the same behaviour:
port->write(out) fails in PacketUsbSerial.cpp. the write function is inherited from QIODevice, and only gives a bool return value of pass/fail. There appears to be no other error information available (if there is it is not in the QIODevice documentation)...
My guess is that the port is set up incorrectly... I'm rebuilding Qt with debugging so I can try to track this down. Any other suggestions appreciated.
EBo --
OK - I just set up SVN to pull qextserialport from a central place for both mcbuilder and mchelper. Try an update in there.
Not sure where you're seeing the bool return value for write()...I see it returning a qint64 value for the number of bytes written or -1 on error. Note that the real work is done in writeData(), called by the Qt base class.
Sorry about the bool/qint64 thing. This was implied in qextserialport's documentation (src/qextserialport/html/index.html) and I missed the change when reading the QIODevice documentation.
Immediate fixes to get it to compiler:
mchelper.pro:
-DEFINES += MCHELPER_VERSION=\"$${MCHELPER_VERSION}\"
+DEFINES += MCHELPER_VERSION=\\\"$${MCHELPER_VERSION}\\\"
to set MCHELPER_VERSION to \"2.5.0\" instead of "2.5.0". Otherwise I get the following error:
src/About.cpp:28:68: error: too many decimal points in number
I also had to add a line to the end of src/qextserialport/posix_qextserialport.h...
Out of curiosity, is it your plan to turn shared/qextserialport/ into a a separate library or to use it as a base for the code in mc*/src/qextserialport/? I would think the former would be less error prone.
Moving on...
To get the usb enumeration working I made the following replacements in src/qextserialport/qextserialenumerator.cpp:
old code:
if(usb_set_configuration( io_handle, 1 ) < 0)
{
usb_close(io_handle);
continue;
}
if(usb_claim_interface( io_handle, 1 ) < 0)
{
usb_close(io_handle);
continue;
}
// if we got this far, we're all good
usb_close(io_handle);
QextPortInfo info;
// set port info...
replaced with:
// EBo -- idVenor=1003, ifProdct=24868 when the MC is in SamBA mode
// idVenor=60163, ifProdct=2336 when the MC is in USBSerial mode
// This is a simple hack to get something to work...
if (!( (usbdev->descriptor.idVendor==1003
&& usbdev->descriptor.idProduct==24868)
|| (usbdev->descriptor.idVendor==60163
&& usbdev->descriptor.idProduct==2336)))
{
usb_close(io_handle);
continue;
}
// EBo -- idVenor=1003, ifProdct=24868 when the MC is in SamBA mode
if (usbdev->descriptor.idVendor==1003
&& usbdev->descriptor.idProduct==24868)
{
if(usb_set_configuration( io_handle, 1 ) < 0)
{
qDebug("usb_set_configuration failed...");
usb_close(io_handle);
continue;
}
if(usb_claim_interface( io_handle, 1 ) < 0)
{
qDebug("usb_claim_interface failed...");
usb_close(io_handle);
continue;
}
productName = "MC Samba";
}
// EBo -- idVenor=60163, ifProdct=2336 when the MC is in USBSerial mode
if (usbdev->descriptor.idVendor==60163
&& usbdev->descriptor.idProduct==2336)
{
productName = "Make Controller Ki";
}
// if we got this far, we're all good
usb_close(io_handle);
// EBo the following hacked from above (OSX)
//dev_path = "";
dev_path = "/dev/bus/usb/";
path = dev_path + usbdev->bus->dirname + "/" + usbdev->filename;
QextPortInfo info;
info.portName = qPrintable(path);
info.friendName = qPrintable(productName);
I also added the following variables to the head of the scanPortsLibUsb function:
QString dev_path, path, productName;
In addition I replaced the following code in arc/UsbMonitor.cpp:
old_code:
if(newSerialPorts.count())
emit newBoards(newSerialPorts, BoardType::UsbSerial);
if(newSambaPorts.count())
emit newBoards(newSambaPorts, BoardType::UsbSamba);
replaced with (to aid in diagnostics):
if(newSerialPorts.count())
{
qDebug("emmiting new serial port");
emit newBoards(newSerialPorts, BoardType::UsbSerial);
}
if(newSambaPorts.count())
{
qDebug("emmiting new samba port");
emit newBoards(newSambaPorts, BoardType::UsbSamba);
}
I also added after the if(!usbSerialList.contains(port.portName)... to handle the device being plugged in Samba mode:
if(!usbSambaList.contains(port.portName) && port.friendName.startsWith("MC Samba"))
{
usbSambaList.append(port.portName); // keep our internal list, the portName is the unique key
newSambaPorts.append(port.portName); // on the list to be posted to the UI
}
I also added a couple of debug messages to src/PacketUsbSerial.cpp::sendPacket:
if(port->write(out) < 0)
{
//monitor->deviceRemoved( port->portName() ); // shut ourselves down
qDebug ("OSC sendPacket error!");
return false;
}
else
{
qDebug ("OSC sendPacket sent");
return true;
}
I also had to change how the src/MainWindow.cpp:
nUsbDeviceArrived handles opening the device in samba mode by replaceing:
old_code:
board = new Board(this, 0, 0, type);
board->setText("Unprogrammed Board");
board->setIcon(QIcon(":icons/usb_icon.gif"));
board->setToolTip("Unprogrammed device");
noUiString = "sam-ba device discovered: " + key;
with code that was formally used by usbserial above:
qDebug("BoardType::UsbSamba found");
PacketUsbSerial *usb = new PacketUsbSerial(key);
board = new Board(this, usb, oscXmlServer, type);
usb->open();
board->setText("Unprogrammed Board: " + key);
board->setIcon(QIcon(":icons/usb_icon.gif"));
board->setToolTip("Unprogrammed device");
noUiString = "sam-ba device discovered: " + key;
Please note that these hacks need to be cleaned up -- in particular the use of hard coded numbers should be set up in #define in an appropriate .h file. Also, we should probably go away from recognising the device from it's name to one that checks a list of vender/product ID's. That way it can be use defined...
With these changes I get the enumerated device list, and it autorecognizes when it is set to samba or programmed mode. It also reolens the device in normal mode when the device is reprogrammed.
Unfortunately I still get the send packet error...
The interesting part for me is that opening the device works for programming, but not for sending the OSC message. Just for a reality check:
* I'm using heavy-1.5.1.bin downloaded from the site instead of my copiled version (to make sure I did not cause it to fail)
* the command to turn on the first appled is "/appled/0/state 1" and there are not other commands I need to run before hand
Suggestions?
EBo --
nUsbDeviceArrived handles opening the device in samba mode by replaceing:
old_code:
board = new Board(this, 0, 0, type);
board->setText("Unprogrammed Board");
board->setIcon(QIcon(":icons/usb_icon.gif"));
board->setToolTip("Unprogrammed device");
noUiString = "sam-ba device discovered: " + key;
with code that was formally used by usbserial above:
qDebug("BoardType::UsbSamba found");
PacketUsbSerial *usb = new PacketUsbSerial(key);
board = new Board(this, usb, oscXmlServer, type);
usb->open();
board->setText("Unprogrammed Board: " + key);
board->setIcon(QIcon(":icons/usb_icon.gif"));
board->setToolTip("Unprogrammed device");
noUiString = "sam-ba device discovered: " + key;
Please note that these hacks need to be cleaned up -- in particular the use of hard coded numbers should be set up in #define in an appropriate .h file. Also, we should probably go away from recognising the device from it's name to one that checks a list of vender/product ID's. That way it can be use defined...
With these changes I get the enumerated device list, and it autorecognizes when it is set to samba or programmed mode. It also reolens the device in normal mode when the device is reprogrammed.
Unfortunately I still get the send packet error...
The interesting part for me is that opening the device works for programming, but not for sending the OSC message. Just for a reality check:
* I'm using heavy-1.5.1.bin downloaded from the site instead of my copiled version (to make sure I did not cause it to fail)
* the command to turn on the first appled is "/appled/0/state 1" and there are not other commands I need to run before hand
Suggestions?
EBo --
Powered by
Ploneboard

