Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: DCDC-USB on Linux

  1. #1
    licensed to kill - FKA kev000
    Auto Apps:loading...
    tripzero's Avatar
    Join Date
    Aug 2006
    Location
    16.40618, 120.61106
    Posts
    2,494

    DCDC-USB on Linux

    I'm trying to write some code to read voltage and ignition from the dcdc-usb powersupply from minibox. I"m using libusb 1.0 and I'm a little lost in this protocol. I seem to be able to write to it but I'm unable to read from it. I wonder if I'm sending the write message. For my test, I'm just writing a simple test for now, setting up the device, writing a "Get all values" command and then trying to read a response. Here's my code:

    Code:
    #define DCDCUSB_GET_ALL_VALUES			0x81
    #define DCDCUSB_RECV_ALL_VALUES			0x82
    #define READENDPOINT 				0x81
    #define WRITEENDPOINT				0x01
    
    unsigned char* message = new unsigned char[1];
    	message[0] = DCDCUSB_GET_ALL_VALUES;
    	int transfered=0;
    
    	int result = libusb_interrupt_transfer(psudev, WRITEENDPOINT, message, 1, &transfered, TIMEOUT);
    
    	qDebug()<<"result:"<<result<<" transfered:"<<transfered;
    
    	if(result == 0) //success
    	{
    		unsigned char *buffer = new unsigned char[500];
    		result = libusb_interrupt_transfer(psudev, READENDPOINT, buffer, 500, &transfered, TIMEOUT);
    
    		qDebug()<<"result:"<<result<<" transfered:"<<transfered;
    
    		QByteArray reply = QByteArray::fromRawData((const char*)buffer, transfered);
    
    		if(reply.size() && reply.at(0) == DCDCUSB_RECV_ALL_VALUES)
    		{
    			double val = reply.at(3)*(float)0.1558;
    			m_voltageIn = QString("%.2f").arg(val).toDouble();
    
    			val = reply.at(4)*(float)0.1558;
    			m_ignition = QString("%.2f").arg(val).toDouble();
    
    			val = reply.at(5)*(float)0.1170;
    			m_voltageOut = QString("%.2f").arg(val).toDouble();
    		}
    
    		delete buffer;
    	}
    Here's some links to the window's source code and a "text test": http://resources.mini-box.com/online...SB-Pro-src.zip

    Am i missing anything obvious?
    Former author of LinuxICE, nghost, nobdy.
    Current author of Automotive Message Broker (AMB).
    Works on Tizen IVI. Does not represent anyone or anything but himself.

  2. #2
    Newbie kshots's Avatar
    Join Date
    Mar 2007
    Location
    florida
    Posts
    48
    Nagging suspicion: reply.at(0) is signed, and you're comparing it to a byte with the MSB set. I do not see your sample output in your post, but that's what strikes me.

    EDIT: Don't you compile with -Wall set?

  3. #3
    licensed to kill - FKA kev000
    Auto Apps:loading...
    tripzero's Avatar
    Join Date
    Aug 2006
    Location
    16.40618, 120.61106
    Posts
    2,494
    Output is:

    result: 0 transfered 1

    result: -7 transfered 0
    "operation timed out"



    I tried switching to bulk transfers but with the same result. I don't have -Wall turned on and yes there are a bunch of warnings. I'll try to clean it up a bit, but i doubt it'll solve my issue with not being able to read frmo the device at all.
    Former author of LinuxICE, nghost, nobdy.
    Current author of Automotive Message Broker (AMB).
    Works on Tizen IVI. Does not represent anyone or anything but himself.

  4. #4
    Newbie kshots's Avatar
    Join Date
    Mar 2007
    Location
    florida
    Posts
    48
    Ok... one other thing comes to mind

    How do you know that data is immediately available after sending the request? What if it takes some time? Can you run a select() on libusb to let you know that data is available? Can you do send a "wait forever" command to libusb by using '0' for the timeout?

  5. #5
    licensed to kill - FKA kev000
    Auto Apps:loading...
    tripzero's Avatar
    Join Date
    Aug 2006
    Location
    16.40618, 120.61106
    Posts
    2,494
    Quote Originally Posted by kshots View Post
    Ok... one other thing comes to mind

    How do you know that data is immediately available after sending the request? What if it takes some time? Can you run a select() on libusb to let you know that data is available? Can you do send a "wait forever" command to libusb by using '0' for the timeout?
    yes, passing 0 as the timeout will force it to wait forever. and no, that doesn't work. My only guess is that my command is wrong, or missing something. If i set up the usb device wrong, i shouldn't be able to even write to it should i?
    Former author of LinuxICE, nghost, nobdy.
    Current author of Automotive Message Broker (AMB).
    Works on Tizen IVI. Does not represent anyone or anything but himself.

  6. #6
    Newbie kshots's Avatar
    Join Date
    Mar 2007
    Location
    florida
    Posts
    48
    Well, you apparently _did_ write to something. You may have the receive endpoint wrong, though... How do you know what you're sending is correct? Did you use a USB-sniffer of some sort with the windows drivers for the thing?

  7. #7
    licensed to kill - FKA kev000
    Auto Apps:loading...
    tripzero's Avatar
    Join Date
    Aug 2006
    Location
    16.40618, 120.61106
    Posts
    2,494
    Code:
    void HIDDcDcUsb::GetAllParams()
    
    {
    
    	sendMessage(DCDCUSB_GET_ALL_VALUES, 0);
    
    }
    
    bool HIDDcDcUsb::sendMessage(unsigned char cType, unsigned int len, ...)
    
    {
    
    	HArray hArray(len + 1);
    
    	hArray.getBuf()[0] = cType;
    
    
    
    	va_list args;
    
    	va_start(args, len);
    
    	unsigned int cnt = 0;
    
    #ifdef _WIN32	
    
    	unsigned char i = va_arg(args, unsigned char);
    
    #else
    
    	unsigned char i = va_arg(args, unsigned int);
    
    #endif
    
    	while (cnt<len)
    
    	{
    
    		hArray.getBuf()[1+cnt] = i;
    
    		cnt++;
    
    		if (cnt < len)
    
    #ifdef _WIN32			
    
    		 	i = va_arg(args, unsigned char);
    
    #else
    
    			i = va_arg(args, unsigned int);
    
    #endif
    
    	}
    
    	
    
    	va_end(args);
    
    
    
    	m_nError = -1;
    
    	if (Write(&hArray))
    
    	{
    
    		if ((cType == DCDCUSB_MEM_READ_OUT)||(cType == DCDCUSB_MEM_ERASE)||(cType == DCDCUSB_MEM_WRITE_OUT))
    
    		{
    
    			int tmout = 0;
    
    			while (m_nError == -1)
    
    			{
    
    				Sleep(A_SLEEP);
    
    				tmout++;
    
    				if (tmout > A_TIMEOUT) return false;
    
    			}
    
    		}
    
    		return true;
    
    	}
    
    	else return false;
    
    }
    
    bool HIDDcDcUsb::Write(HArray* mesg)
    
    {
    
    	m_lockWrite.lock();
    
    	bool b = m_pParent->Write(mesg);
    
    	m_lockWrite.unlock();
    
    
    
    	return b;
    
    }
    
    ///m_pParent is an HIDDevice:
    
    bool HIDDevice::Write(HArray* mesg)
    
    {
    
    	
    
    #ifdef _WIN32
    
    	DWORD	BytesWritten = 0;
    
    	ULONG	Result;
    
    #else
    
    	long	BytesWritten = 0;
    
    	long	Result;
    
    #endif
    
    
    
    	unsigned short send = m_hidDescriptor->GetOUTLength(mesg->getBuf()[0]);
    
    	//if (mesg->length() == 1) send = 1;
    
    
    
    	unsigned char* buf = new unsigned char[send];
    
    	memset(buf, 0, send);
    
    	memcpy(buf, mesg->getBuf(), mesg->length());
    
    
    
    #ifdef _DEBUG
    
    	if (buf[0]!=0x81)
    
    	{
    
    		TRACE("TX[%d]:",send); 
    
    		for (unsigned int i=0;i<send;i++)
    
    			TRACE("%02X ",buf[i]);
    
    		TRACE("\n");
    
    	}
    
    #endif
    
    
    
    #ifdef _WIN32
    
    	Result = WriteFile 
    
    		(m_WriteHandle, 
    
    		buf, 
    
    		send, 
    
    		&BytesWritten, 
    
    		NULL);
    
    #else
    
    	Result = write(m_WriteHandle, buf , send);
    
    	BytesWritten = Result;
    
    #endif
    
    
    
    	if (Result <= 0)
    
    	{
    
    		DWORD err = GetLastError();
    
    #ifdef _DEBUG
    
    		TRACE(">>>TX[ERR=%d(%d)]\n",err,send); 
    
    #endif
    
    		if (err == ERROR_DEVICE_NOT_CONNECTED)
    
    		{
    
    			if (m_bOpened)
    
    			{
    
    				m_bOpened = false;
    
    				if (m_pParser) 
    
    					m_pParser->Disconnected();
    
    			}
    
    		}
    
    
    
    		delete buf;
    
    		return false;
    
    	}
    
    	else
    
    	{
    
    		delete buf;
    
    		return true;
    
    	}
    
    	return true;
    
    }
    Former author of LinuxICE, nghost, nobdy.
    Current author of Automotive Message Broker (AMB).
    Works on Tizen IVI. Does not represent anyone or anything but himself.

  8. #8
    Newbie kshots's Avatar
    Join Date
    Mar 2007
    Location
    florida
    Posts
    48
    I can't read much of that... this board's code tags seem to be broken, the horizontal scroll bar is all the way at the bottom of the box

  9. #9
    licensed to kill - FKA kev000
    Auto Apps:loading...
    tripzero's Avatar
    Join Date
    Aug 2006
    Location
    16.40618, 120.61106
    Posts
    2,494
    Quote Originally Posted by kshots View Post
    Well, you apparently _did_ write to something. You may have the receive endpoint wrong, though... How do you know what you're sending is correct? Did you use a USB-sniffer of some sort with the windows drivers for the thing?
    I got the send and receive endpoints from lsusb -v.
    Former author of LinuxICE, nghost, nobdy.
    Current author of Automotive Message Broker (AMB).
    Works on Tizen IVI. Does not represent anyone or anything but himself.

  10. #10
    Newbie
    Join Date
    Oct 2010
    Posts
    13
    G'Day tripzero,
    Did you get this working?
    Rgds,
    Ben

Page 1 of 2 12 LastLast

Similar Threads

  1. HFP for Linux Bluetooth Hands Free
    By samr7 in forum Linux
    Replies: 105
    Last Post: 04-25-2012, 06:45 AM
  2. New Frontend for Windows and Linux
    By gbr in forum Other Cool Front Ends
    Replies: 68
    Last Post: 01-21-2009, 09:55 PM
  3. Linux on USB Drive
    By blkwrx in forum Linux
    Replies: 6
    Last Post: 03-26-2006, 10:19 PM
  4. Will this layout with a remote USB hub work?
    By NoPistonPC in forum General Hardware Discussion
    Replies: 14
    Last Post: 08-21-2005, 04:24 PM
  5. USB devices that power off in Linux
    By pkg in forum Linux
    Replies: 6
    Last Post: 07-11-2005, 06:07 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •