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

Thread: FB in Linux: can somebody help?

  1. #1
    Newbie
    Join Date
    Mar 2009
    Posts
    5

    FB in Linux: can somebody help?

    Hey guys!

    I have been trying to make FB v3 work under Linux but I cannot really get it to do what the specs say it should do. I have written some code using libusb (actually, not all of it is mine, I borrowed some from another post here, thanks) but I cannot make the outputs behave the way they are supposed to. I can turn output 0 on but it will never time out. If I try to turn any other output on before I toggle output zero, nothing happens. In all, the board behaves erratically.

    What is needed to initialize FB? Is there a special string, control transfer, anything I should send before I start sending and receiving the 64 byte messages? libusb is happy and the outputs do turn on and off (after I toggle output 0) so I guess it is a matter of the correct message exchange. My FB is v3 and the firmware is v 5.2 (according to bytes 62/63 of the received data). Please check out the code below.

    (I have not tried MDX under Windows yet, 'cause,... I have no Windows at the moment and cannot really afford to wait for a 300Mb download).

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <libusb.h>

    libusb_device *fusionBrain;
    libusb_device_handle *fusionBrainHandle;
    libusb_device **devs;
    libusb_context *context;
    unsigned char data_recv[64];
    unsigned char data_sent[64];
    unsigned char EP_OUT;
    unsigned char EP_IN;

    int setsingleio(int ionum, int active)
    {
    int actualReceived, actualSent;
    int toggle = 1;
    int enough = 0;
    int i, j;

    if ((ionum < 0) || (ionum > 11))
    {
    return -1;
    }

    for (i=0;i<64;i++)
    {
    data_sent[i]=0;
    }

    data_sent[61] = 0xff;

    while (enough < 5)
    {
    toggle = 1 - toggle; //flip the flop
    if (active)
    {
    data_sent[ionum] = 0b00000101|(toggle<<1);
    }
    else
    {
    data_sent[ionum] = 0b00000000|(toggle<<1);
    }

    printf("Bit: %i, Toggle: %i\n", data_sent[ionum], toggle <<1);

    libusb_bulk_transfer(fusionBrainHandle,EP_OUT,data _sent,64,&actualSent,500);
    libusb_bulk_transfer(fusionBrainHandle,EP_IN,data_ recv,64,&actualReceived,500);

    for(i = 0; i< 8; i++){
    for(j = 1; j<=8; j++){
    printf("%3i ", data_sent[i*8+j-1]);
    }
    printf("\n");
    }
    printf("********* RECEIVED ************\n");
    for(i = 0; i< 8; i++){
    for(j = 1; j<=8; j++){
    printf("%3i ", data_recv[i*8+j-1]);
    }
    printf("\n");
    }
    usleep(300000);
    enough++;
    }
    return 0;
    }


    int main(int argc, char **argv){
    int input, active;
    int i=0;

    libusb_init(&context);
    libusb_set_debug(context,3);
    EP_OUT = 0x01;
    EP_IN = 0x81;

    libusb_device *dev;
    libusb_get_device_list(NULL,&devs);

    while ((dev = devs[i++]) != NULL)
    {
    struct libusb_device_descriptor desc;
    libusb_get_device_descriptor(dev,&desc);
    if ((desc.idVendor == 0x04d8) && (desc.idProduct == 0x000C))
    {
    printf("Found fusion brain v4\n");
    fusionBrain = dev;
    }
    }

    printf("Trying to open...\n");
    if (libusb_open(fusionBrain,&fusionBrainHandle))
    {
    printf("ERROR\n");
    }
    printf("Opened... trying to claim...\n");
    libusb_claim_interface(fusionBrainHandle,0);



    if ( argc <2 ){
    input = 0;
    active = 1;
    } else {
    input = atoi(argv[1]);
    active = atoi(argv[2]);
    }

    if (setsingleio(input,active))
    {
    printf("Error on set\n");
    }

    }

  2. #2
    Fusion Brain Creator
    Join Date
    Mar 2005
    Posts
    2,221
    timers dont work in current firmware.

    nick should be along to help with your other issues

  3. #3
    Fusion Brain Creator 2k1Toaster's Avatar
    Join Date
    Mar 2006
    Location
    Colorado, but Canadian!
    Posts
    10,049
    No special code has to be done. You just send a byte, read a byte. Send a byte, read a byte. That's it.

    Here is the code from MDX: http://www.fusioncontrolcentre.com/M...cationClass.cs

    Also there is already a Linux something around here that should work.
    Fusion Brain Version 6 Released!
    1.9in x 2.9in -- 47mm x 73mm
    30 Digital Outputs -- Directly drive a relay
    15 Analogue Inputs -- Read sensors like temperature, light, distance, acceleration, and more
    Buy now in the MP3Car.com Store

  4. #4
    North of the land of Hey Huns
    Auto Apps:loading...

    Join Date
    Jun 2004
    Location
    Westminster, MD
    Posts
    2,127
    2k1Toaster: yeah some of the code he has was copied/pasted from my program :P

    nousb: Everything looks fine, I've noticed with the FB sometimes I have to send the request several times to get it to actually work, which is why my program has a loop which checks to see if the output was successfully set, and if not it keeps trying until it actually gets set. Perhaps try a similar thing?

  5. #5
    Fusion Brain Creator 2k1Toaster's Avatar
    Join Date
    Mar 2006
    Location
    Colorado, but Canadian!
    Posts
    10,049
    That should not be the case. Are your endpoints configured as mine are in the source?

    Are you keeping the keep alive bit toggling?
    Fusion Brain Version 6 Released!
    1.9in x 2.9in -- 47mm x 73mm
    30 Digital Outputs -- Directly drive a relay
    15 Analogue Inputs -- Read sensors like temperature, light, distance, acceleration, and more
    Buy now in the MP3Car.com Store

  6. #6
    North of the land of Hey Huns
    Auto Apps:loading...

    Join Date
    Jun 2004
    Location
    Westminster, MD
    Posts
    2,127
    Quote Originally Posted by 2k1Toaster View Post
    That should not be the case. Are your endpoints configured as mine are in the source?

    Are you keeping the keep alive bit toggling?
    Ah, it seems I had forgotten about the keep-alive, I'll have to write that in.

    nousb: I should be able to test your code out either tomorrow or Saturday with my V4, I'll let you know how it works for me.

  7. #7
    Newbie
    Join Date
    Mar 2009
    Posts
    5
    Quote Originally Posted by 2k1Toaster View Post
    That should not be the case. Are your endpoints configured as mine are in the source?

    Are you keeping the keep alive bit toggling?
    2k1toaster: yes, everything seems to be the same; I do flip the keep-alive (and it shows in the output) every 300 ms.

    malcom2073: Yes, I did borrow some of your code, thank you, I apologize for not acknowledging you in the original post, I was a bit frustrated and could not find where it came from right away. In any case:

    1) according to the spec I read, you cannot check the status of the outputs as those bytes are simply not used (at least in v3) so I cannot really rely on your trick. In reality, I noticed that if I managed to set an output on, it DOES change in the received bytes as well.

    2) I got the endpoints from the lsusb -v output. they are both listed as interrupt EP but bulk trasfers work equally well (I did try interrupt transfers as well, nothing changed).

    3) I did notice that when I send byte 61 set to 0xff only once, the chip wakes up (well, I can see it returned as 0xff that is) for 500 ms and then the byte is reset to 0x00 so I have to constantly send it in a loop. This is not what the spec is saying.

    4) The most frustrating problem is that I cannot change ANY outputs before I turn output 0 on and off at lest once. I tried loops that lasted for minutes, so it is not a problem of not waiting enough. After out 0 is changed once, I can set and turn off any other output.

    5) In malcom2073's original code you use the same array data_recv to both output and read the input in a loop. I separated the arrays into two, so I do not have to worry about data being overwritten (such as byte 61). I thought this was the problem but that did not fix anything.

    6) finally, is it true that that time-out timers are not functioning in this firmware?

    7) Does the Windows code use the dll supplied by Microchip? And if yes, does this have anything to do with it? I do not think so since I can obviously communicate with the device, it just does not react as expected.

    Can someone actually test my code on a v3 FB? I would appreciate a confirmation of my observations. To compile, just use malcolm's original post, if it does not work, I can help with the compilation part (I had to change a few things in the command line, as well)

    Thanks for all your help, guys.

    Alex

  8. #8
    Fusion Brain Creator 2k1Toaster's Avatar
    Join Date
    Mar 2006
    Location
    Colorado, but Canadian!
    Posts
    10,049
    Well I can say that these anomalies are having to do with either your code or the linux version of the drivers. Using MDX under windows, no outputs need to turn on for any other output to work.

    And we use Microsoft's WinUSB driver. Microchip's driver was extremely buggy and slow when we started so we moved away from it. Microchip actually abandoned their driver as well and they now advocate using Microsoft WinUSB.
    Fusion Brain Version 6 Released!
    1.9in x 2.9in -- 47mm x 73mm
    30 Digital Outputs -- Directly drive a relay
    15 Analogue Inputs -- Read sensors like temperature, light, distance, acceleration, and more
    Buy now in the MP3Car.com Store

  9. #9
    North of the land of Hey Huns
    Auto Apps:loading...

    Join Date
    Jun 2004
    Location
    Westminster, MD
    Posts
    2,127
    Quote Originally Posted by nousb View Post
    malcom2073: Yes, I did borrow some of your code, thank you, I apologize for not acknowledging you in the original post, I was a bit frustrated and could not find where it came from right away.
    No problem, I'm just glad someone found it helpful.

    Quote Originally Posted by nousb View Post
    3) I did notice that when I send byte 61 set to 0xff only once, the chip wakes up (well, I can see it returned as 0xff that is) for 500 ms and then the byte is reset to 0x00 so I have to constantly send it in a loop. This is not what the spec is saying.
    Could this possibly be the keepalive? Perhaps flipping it on and off every other transmission is what 2k1toaster is talking about.

  10. #10
    Fusion Brain Creator 2k1Toaster's Avatar
    Join Date
    Mar 2006
    Location
    Colorado, but Canadian!
    Posts
    10,049
    For V4 boards:






    Code:
    *******************************
    * FUSION BRAIN V4 BYTE STREAM *
    *                             *
    * Deterministic Difference:   *
    *     PID Suffix: E           *
    *                             *
    *******************************
    
    
    **** ID CODE ****
    Version 3a: VID_04D8&PID_000A
    Version 3b: VID_04D8&PID_000B
    Version 3c: VID_04D8&PID_000C
    Version 3d: VID_04D8&PID_000D
    Version 4:  VID_04D8&PID_000E
    
    
    **** STREAM ****
    
    Bytes
      [00-31] Digital Outputs 00 through 15
      [32-57] Analogue Inputs 00 through 12
      [57-59] Not Used Now, Maybe in future
      [60]    Number of Streams to Receive
      [61]    Initialize/Watchdog byte
      [62]    Hardware Version
      [63]    Firmware Version
    
    Bits 0bMxxxxxxL | M = MSB and L = LSB
      Digital Outputs
        2 bytes per output
        [PPPPPPPS][TTTTTTMM]
          P = Value of PWM
            ([7bit Value + 1]/128)% duty cycle
            Details of full period to be determined later
          S = 1bit state
            0 = Off
            1 = on
          T = 6bits of Timer to shutoff --> [Evaluated Units in Seconds]
            If 6'bTTTTTT is 0, then shut off immediately on disconnect
            If 6'bTTTTTT is between 1 and 10 inclusive, then wait [6'bTTTTTT] seconds after disconnect
            If 6'bTTTTTT is 11, then wait 30 seconds after disconnect
            If 6'bTTTTTT is 12, then wait 60 seconds after disconnect
            If 6'bTTTTTT is 13, then wait 90 seconds after disconnect
            If 6'bTTTTTT is greater than 14, then wait ([6'bTTTTTT] * 10) seconds after disconnect
          M = 2bit Output Mode
            2'b00: Normal Full-Off or Full-On Operation Mode
            2'b01: Pulse Width Modulation Operation Mode
            2'b10: Yet to be determined
            2'b11:  Yet to be determined
      Analogue Inputs
        2 bytes per input
        [index][index + 1] = [000000Mx][xxxxxxxL] | M = MSB and L = LSB
      Number of Streams to Receive
        1 byte
        [NNNNNNNN] | N = Number of streams to receive
          If [8'bNNNNNNNN] is 0 (default) then receive 1 byte and send 1 byte
          If [8'bNNNNNNNN] is greater than 0 then receive 1 byte and send 1 byte [8'bNNNNNNNN] times
            Each of these "extra" byte streams received may not coorespond with the details of this byte stream outline
            Each of the "extra" byte streams sent back to the PC may not coorespond with the details of this byte stream
      Initialize/Watchdog Byte
        1 byte
        [000000IF] | F = Flipping Bit and I = Initialize Bit
          F = Instead of flipping a bit in every digital output, flip 1 bit constantly
          I = Needs I high to turn anything on, just like default behaviour of byte[61] now
      Hardware Version
        [MMMMLLLL]
          M = Major Version. Currently Version 4, so MMMM = 0100
          L = Minor Version. Currently Version 0, so LLLL = 0000 
      Firmware Version
        1 byte
        [????????]
          Unknown
    Fusion Brain Version 6 Released!
    1.9in x 2.9in -- 47mm x 73mm
    30 Digital Outputs -- Directly drive a relay
    15 Analogue Inputs -- Read sensors like temperature, light, distance, acceleration, and more
    Buy now in the MP3Car.com Store

Page 1 of 2 12 LastLast

Similar Threads

  1. New Frontend for Windows and Linux
    By gbr in forum Other Cool Front Ends
    Replies: 68
    Last Post: 01-21-2009, 09:55 PM
  2. Linux duck duck goose!
    By rocken in forum Linux
    Replies: 11
    Last Post: 03-12-2006, 12:15 PM
  3. The LOW Risk Linux Adventure...
    By grepzen in forum Software & Software Development
    Replies: 13
    Last Post: 11-08-2004, 10:12 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
  •