7 years, 11 months ago.

What is the difference between NXP and STMicro about splitting string using C# Split function.

Hello guys.

I am now trying to get sensor value from mbed devices and display it on PC, using not only NXP1768 and mbed Application Board but also STM32F411 Nucleo Board and IKS01A1.

I am using Visual C# to get data via serial port, and using Split function to divide string which contains sensor data. And I got different results from each of the devices.

In both cases, I confirmed that string "text" contained same format like "285, -127"

When I use NXP1768 with sample code, I can get collect data.

NXP printf("%d,%d\n",x,y);

C# string[] word = text.Split(new char[] { ',' });

txtDataReceived.AppendText(word[0]);

In this case, I can get first data like "285" in word[0].

But in case of STM32, I failed to get first data using same C# code.

STM32 printf("%d,%d\n", temp[0], temp[1]);

C# string[] word = text.Split(new char[] { ',' });

txtDataReceived.AppendText(word[0]);

In this case, Splitter was recognaized, but all element was enterd in word[0]. So, I could get the result like "285 -127".

Of course, I had expected to get the result word[0] = 285 and word[1] = -127.

I also got another result when I used a Nucleo Board STM32L053. I found a result turning every time when program recieved the data like "285" or "285 -127" or "285 -1" etc.

I am not sure where the difference is about this issue.

I used mbed example code and only changed the part of "printf".

add 6/17

Tera Term /media/uploads/Nobunari/teraterm.png

show text /media/uploads/Nobunari/c-text.png

show word[0] /media/uploads/Nobunari/c-word.png

Send code /media/uploads/Nobunari/code.png

Recieve code /media/uploads/Nobunari/code2.png

2 Answers

7 years, 11 months ago.

Just start by checking in a Serial terminal (Teraterm, Putty, etc) what you receive exactly, and how it is different.

In general I believe STM ones still use uARM lib, while NXP LPC1768 uses regular ARM lib which supports more functions, but that shuldn't make a difference on such simple code. So can you post between <<code>> and <</code>> what you run exactly?

Hi Erick and cute minion.

Thank you for your prompt reply.

I used Hello World program on this site for Nucleo Board,

https://developer.mbed.org/components/X-NUCLEO-IKS01A1/

and also used app-board-Bubble-Level on this site for NXP1768.

https://developer.mbed.org/components/mbed-Application-Board/

I changed both codes to minimize output by commenting out extra "printf" functions and changed character format to "%d" and variable to int and add splitter.

For instance,

***********

/ /gyroscope->Get_G_Axes(axes);

axes[0]=1;

axes[1]=3;

/ / printf("LSM6DS0 [gyro/mdps]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]);

printf("%d,%d,\n",axes[0],axes[1]);

wait(1.5);

}

************

Of course,I checked output using serial terminal .

And I used C# program using Microchip sample program

https://github.com/mentatpsi/Microchip

Microchip-master\Microchip-master\USB\Device - CDC - Basic Demo\PC Software Example

I add a Split function in " private void SetText(string text)" like this.

else {

/ / If this function was called from the same thread that

/ / holds the required objects then just add the text.

txtDataReceived.AppendText(text);

string[] word = text.Split(new char[] { ',' });

txtDataReceived.AppendText(word[0]);

}

I confirmed the contents of text and found they were correct. But word[0] was incorrect.

I don't know about detail of this C# sample program, so it could be possible that there are some unrecognized functions which bring this problem.

posted by Nobunari Tanaka 16 Jun 2016
7 years, 11 months ago.

If the PC program is acting differently then it must be receiving different data.

Put a break point on the split command and check the exact contents of the text buffer with each board sending. There may be some non-printable character that's different for some reason. This won't tell you why there is a difference between the two but at least it will tell you exactly what the difference is which is a good starting point..

Thank you Andy for your advice.

I have never used break function since I last used Solaris....

so it would take a loooong time to report about using break function in visual studio.

I am now checking my code, and also searching another way.

If I find a solution, I would report it here.

posted by Nobunari Tanaka 16 Jun 2016

Not a break function a break point. It takes about 5 seconds and is the whole point of using a modern IDE like visual studio.

You click just to the left of a line of code, a red circle will appear. Then run the code in the debug mode (select debug from the pull down at the top of the screen which will either say Debug or Release and click the green play arrow). The program runs up until the point you requested and then pauses. You can then view the contents of a variable by hovering the mouse over it. There are controls to step forward one line at a time or to carry on running.

Because the visual studio debug ability is so vastly superior to the standard mbed system it will be far easier to find and fix the problem on the visual studio side of things rather than making random guesses on the mbed side.

posted by Andy A 17 Jun 2016