Error sending brick command

HomeForumsMonoBrick Communication LibraryError sending brick command

This topic contains 11 replies, has 2 voices, and was last updated by Author Image Oleg Stepanow 2 years, 7 months ago.

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #4990
    Author Image
    Oleg Stepanow
    Participant

    I`m using test project.
    It works good with nxt, but I have problem with ev3.
    I use usb connection. It connects without errors, but after connection it throws errorrs when I try to send any command. Error is “Error sending brick command”
    What am I doing wrong?
    Ev3 software is H1.03

    • This topic was modified 2 years, 7 months ago by Author Image Oleg Stepanow.
    #4992
    Author Image
    Oleg Stepanow
    Participant

    tried it with E1.03 firmware on my ev3 brick- result is the same.

    #4994
    Author Image
    Anders Søborg
    Key Master

    Hi there

    Please post your code otherwise it is hard to help

    /Anders

    #4996
    Author Image
    Oleg Stepanow
    Participant

    I`m using your TestApplication
    I just entered some traces for debugging.

    Console.WriteLine(1);
    var brick = new Brick<Sensor,Sensor,Sensor,Sensor>(“usb”);
    sbyte speed = 0;
    Console.WriteLine(2);
    brick.Connection.Open();
    Console.WriteLine(3);
    brick.MotorA.On(20);
    Console.WriteLine(4);

    it comes to tracing 3 and after throughs error (when I send command to MotorA)
    I tried different motors and other commands, all the same.
    Before I also had trouble like this http://www.monobrick.dk/forums/topic/fail-to-connect-ev3-via-usb/
    But i fixed it the same way as posted there.

    #4997
    Author Image
    Anders Søborg
    Key Master

    Hi

    Please post the complete code as it is important to know what namespaces you use. It makes a big difference whether you use the NXT or EV3 brick class…

    Anders

    #4998
    Author Image
    Oleg Stepanow
    Participant
    using System;  
    using MonoBrick.EV3;//use this to run the example on the EV3
    //using MonoBrick.NXT;//use this to run the example on the NXT  
    namespace Application  
    {  
        public static class Program
        {
            private static Brick<Sensor, Sensor, Sensor, Sensor> brick;
          static void Main(string[] args)  
          {  
            try
            {
    
                Console.WriteLine(1);  
                brick = new Brick<Sensor,Sensor,Sensor,Sensor>("usb");  
                sbyte speed = 0;
                Console.WriteLine(2);
                brick.Connection.Open();
                Console.WriteLine(3);  
                brick.MotorA.On(20);
                Console.WriteLine(4); 
                Console.WriteLine("333");  
                ConsoleKeyInfo cki;  
                Console.WriteLine("Press Q to quit");  
                do   
                {  
                    cki = Console.ReadKey(true); //press a key  
                    switch(cki.Key){    
                        case ConsoleKey.R:
                           
                            int c = brick.MotorB.GetTachoCount(); 
                            Console.WriteLine("Motor A reverse direction");    
                            brick.MotorA.Reverse = !brick.MotorA.Reverse;    
                        break;                              
                        case ConsoleKey.UpArrow:     
                            if(speed < 100)    
                                speed = (sbyte)(speed + 10);    
                            Console.WriteLine("Motor A speed set to " + speed);    
                            brick.MotorA.On(speed);    
                        break;    
                        case ConsoleKey.DownArrow:     
                            if(speed > -100)    
                                speed = (sbyte)(speed - 10);    
                            Console.WriteLine("Motor A speed set to " + speed);    
                            brick.MotorA.On(speed);    
                        break;    
                        case ConsoleKey.S:     
                            Console.WriteLine("Motor A off");    
                            speed = 0;    
                            brick.MotorA.Off();    
                        break;    
                        case ConsoleKey.B:    
                            Console.WriteLine("Motor A break");    
                            speed = 0;    
                            brick.MotorA.Brake();    
                        break;  
                         case ConsoleKey.T:    
                            int count = brick.MotorA.GetTachoCount();  
                            Console.WriteLine("Motor A tacho count:" +count);    
                        break;  
                        case ConsoleKey.C:    
                            Console.WriteLine("Clear tacho count");    
                            brick.MotorA.ResetTacho();  
                        break;  
                        case ConsoleKey.M:  
                            Console.WriteLine("Enter position to move to.");  
                            string input = Console.ReadLine();  
                            Int32 position;  
                            if(Int32.TryParse(input, out position)){  
                                Console.WriteLine("Move to " + position);  
                                brick.MotorA.MoveTo(50, position, false);  
                            }  
                            else{  
                                Console.WriteLine("Enter a valid number");  
                            }  
                        break;  
                    }  
                } while (cki.Key != ConsoleKey.Q);  
            }  
            catch(Exception e){  
                Console.WriteLine("Error: " + e.Message);  
                Console.WriteLine("Press any key to end...");  
                Console.ReadKey();                
            }  
          }  
        }  
    } 

    as I talled, it`s a code from test application, with just small changes

    #5000
    Author Image
    Anders Søborg
    Key Master

    It seems strange that you are able to have it working with the NXT but not the EV3 – I mean it uses the same USB connection. Have you tried to single step through the program?

    /Anders

    #5001
    Author Image
    Anders Søborg
    Key Master

    What system are you on?

    /Anders

    #5003
    Author Image
    Oleg Stepanow
    Participant

    Im on windows 7 64
    Nothing worked at all untill I rebuilt hidapi.dll to 64 bit platform. Now it`s as I described…

    Got it:
    in usb.cs

    if(bytesWritten == -1)
                            hasError = true;

    seems I steel have problems with hidapi… but with nxt it works good.

    Now im using both nxt and ev3 in one programm with same result. both connect, nxt gets commands, ev3 fails to.

    #5005
    Author Image
    Oleg Stepanow
    Participant

    Aha! You use different connections for NXT and EV3:
    connection = new LibUsb<TBrickCommand,TBrickReply>(LegoUsbConstants.VendorId, LegoUsbConstants.NXTProductId, ReadEndpointID.Ep02, WriteEndpointID.Ep01); that for nxt

    connection = new HidLib<TBrickCommand,TBrickReply>(LegoUsbConstants.VendorId, LegoUsbConstants.EV3ProductId, true); and that for EV3
    So the problem seems to be in HidLib, yes. Sory for bothering you, I will try to fix it someway)

    #5006
    Author Image
    Anders Søborg
    Key Master

    Did you build the application for 32-bit or 64-bit?

    /Anders

    #5012
    Author Image
    Oleg Stepanow
    Participant

    both for 64 bit- hidapi and testApplication

Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.

Posted in

Make a donation