0

My intention is to show for the output of Matlab System a string the type char_T data[ ], that I receive a function in C through coder.ceval

I want to show more specifically the buffer variable, as it would have to declare the buffer variable

matlab
function data = stepImpl(obj)
        buffer = ¿¿ ??;

        if coder.target ('Rtw')
            coder.cinclude('File_Wrapper.h');
            coder.ceval('function',obj.port, coder.wref(buffer)); 
            data = ¿¿¿ string(buffer) ???;
        end
end

this would be the function sent to me by char_T data[ ], I use coder.wref to fill the variable in the following method

void function(uint8_T uartPort, char_T data[])
{
    char buffer[30];
    if (uartPort == 1)
    {
        fgets(buffer, 10, uart1);
    }
    else if (uartPort == 2)
    {
        fgets(buffer, 10, uart2);
    }

    snprintf (data, sizeof(buffer), "%s", buffer);
}

This post dont work for me: Converting a C char array into a Matlab String using Matlab Coder

1 Answer 1

1

What exactly is going wrong with the code you have written? Do you see any error messages, or get answers different than you expect?

I think that you might run into problems with your 'buffer' variable in MATLAB not being large enough to store everything that you are printing into it in your C code. I would recommend initializing it with 'buffer = blanks(10)' to make sure it can hold at least 10 characters (which is the number I think you are reading). Another good option might be to just use 'fread' instead of your custom C code (if that is possible), as that function is supported for MATLAB Coder.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.