United Kingdom
Asked — Edited
Resolved Resolved by ptp!

Sdk Uart Question

Hi i am having problems using the Uart 0 with the sdk c# on my ez-b v4 i am writing a standalone app as well as a plugin for my inmoov bot, as i only have one ez-b v4 (limited funds) i am using an stm32F429 discovery board i had lying around to operate the additional servos and neopixel ring. The F429 disco board is working fine and i can send a simple command from the ez-b the protocol is just 4 bytes [0xFE][command byte][servonum byte][value byte] and works fine at 115200 F429 recieves the commands without any problems but i then send back either the same 4 bytes to acknowledge a set command or with a changed value byte if requesting a value from the F429 i have the following code set up in C# to wait for the response but it always returns the same value of 239 0xef in both my standalone version and the plugin version the F429 is sending correctly as i have connected it to an arduino , Nulceo stm32F746 and Nucleo stm32F401 and they all receive the 4 bytes correctly. i suspect i am doing something wrong as the _ezb.Uart.UARTExpansionAvailableBytes always seems to return 4086 once i send it data from the F429 I have been struggling with this for a couple of days now so any help would be appreciated am i using the right command to read the data?

private byte[] waitforresponse(int port) { // start timeout timer timeoutTimer.Enabled = true; TimedOut = false; // here to debug uart rx problem // bytes = 0 first time though the loop int bytes = _ezb.Uart.UARTExpansionAvailableBytes(port); while ((_ezb.Uart.UARTExpansionAvailableBytes(port) < 4) && (TimedOut == false)) {

            Application.DoEvents();
        }
        timeoutTimer.Enabled = false;
        // here to debug uart rx problem
        // bytes = 0 first time though the loop

        bytes = _ezb.Uart.UARTExpansionAvailableBytes(port);
        if (TimedOut == false)
        {
            // original code return 4 bytes all with 239 0xEF
            //byte[] data = _ezb.Uart.UARTExpansionRead(port, 4);
           
            // added this for debug 
            // reads 4086 bytes all of the same value 239 0xEF
            byte[] data = _ezb.Uart.UARTExpansionReadAvailable(port);
            return data;
        }
        else
        {
            return null;
        }
    }

ARC Pro

Upgrade to ARC Pro

Get access to the latest features and updates before they're released. You'll have everything that's needed to unleash your robot's potential!

United Kingdom
#9  

Hi Ptp unfortunatley things didn't go according plan at the hospital so haven't been able to look at it at all today. thanks for the code i'll put it into my 401 tomorrow.

United Kingdom
#10  

sorry forgot to answer your questions i tried my code in nucleo f407 , discovery f429 and nucleo f746 i'll put the init code up tomorrow for each

PRO
Synthiam
#11  
  1. Is this a stand-alone app using the SDK or an ARC skill plugin?

  2. Do not ever ever ever use Application.DoEvents. Your code may be using a System.Windows.Forms.Timer instead of System.Timers.Timer.

Use the System.Timers.Timer, which will run in a separate thread. However, beware that you will need to use an Invoke for a System.Timers.Timer thread to modify any GUI Application thread objects

United Kingdom
#12  

Hi DJ the standalone app is using the SDK still learning c# more used to c Timer changed and doevents disposed of to use system timer.

United Kingdom
#13  

Thanks Ptp for all your help. i took your code and built it in the Mbed online compiler and worked as advertised (slight typo ) which i corrected uploaded the bin file and worked great. i then exported it from Mbed online to Keil and same horror story so went back to my code this time using the online compiler and it worked without the error. after a bit of investigation and numerous exports i tracked it down when the exported project is exported it enables optimisation level 3 in one of the command line compiler options set it to level 0 or disabled and everything works not sure why they turn optimisation on as it never works and cause more problems than its worth. Many thanks again for your help. And thanks DJ for your rip with the timer. I'll post the app and plugin once they are finished i've got all the servo mapping done now just need the last few parts to finish printing and i can put the functionality in.