I am trying to send some data from an micro controller to the PC. The data is 10 bit ADC conversions(e.g numbers from 0-1023) from different ports. I have saved this number as an integer and I would now want to transform this to an ascii string using itoa or a similar function. My problem is that I am having some trouble to find the documentation for the itoa function.
for instance if i receive the number "1011" from the AD conversion. then I can call itoa as follows
itoa(AD_value,ADC_string,10); //itoa("value", char* destination, base)
and the result in ADC_string would be "1 0 1 1 '\0'" e.g 1011;
But say that I instead receive the number 5 from the AD conversion, then the result would be "5 '\0' Null Null Null" instead(If I have understood how itoa works correctly). I would have liked the result to be "0 0 0 5 '\0'" instead. The reason for this is that I would like to place the result in a large string at different places. e.g
large_string[0]=id_PC;
large_string[1]=ADC_string[0]; //start of ascii string of the latest value from a port
large_string[2]=ADC_string[1];
large_string[3]=ADC_string[2];
large_string[4]=ADC_string[3];
and for another port (there exist other stuff in large_string at index 5 & 6)
large_string[7]=ADC_string[0]; //start of ascii string of the latest value from another port
large_string[8]=ADC_string[1];
large_string[9]=ADC_string[2];
large_string[10]=ADC_string[3];
I would in other words like to have following in large_string according to my example above.
large_string[0]=id_PC
// an AD conversion from the first port is stored at index 1-4
large_string[1]='1'
large_string[2]='0'
large_string[3]='1'
large_string[4]='1'
large_string[5]=' '
large_string[6]=' '
// a new AD conversation from the second port is stored at index 7-10
large_string[7]='0'
large_string[8]='0'
large_string[9]='0'
large_string[10]='5'
large_string[11]='\0'
(I do AD conversion at one port at the time, which is the reason that I can reuse ADC_string). large_string shall later be sent to a PC which is the reason why I want to avoid unintended string terminators.
Do anyone have an idea on how this can be implemented in a nice manner?
I am thankful for any suggestions!
Just use snprintf, itoa won't add padding for you :
char tmp_str[4+1];
snprintf(tmp_str, sizeof(tmp_str), "%04d", value);
Related
enter image description here
select from list by index ${locator_var} ${inp_msge_type}
--getting error as expected string, int found
select from list by index ${locator_var} 7
-----not getting any error
${inp_msge_type}----contains 7 from DB query the result is stored in this variable, to avoid hard coding we need to do this
Is there any way to write
Do not add links to screenshots of code, or error messages, and format the code pieces accordingly - use the ` (tick) symbol to surround them.
The rant now behind us, your issue is that the keyword Select From List By Index expects the type of the index argument to be a string.
When you called it
Select From List By Index ${locator_var} 7
, that "7" is actually a string (though it looks like a number), because this is what the framework defaults to on any typed text. And so it works.
When you get the value from the DB, it is of the type that the DB stores it with; and probably the table schema says it is int. So now you pass an int to the keyword - and it fails.
The fix is simple - just cast (convert) the variable to a string type:
${inp_msge_type}= Convert To String ${inp_msge_type}
, and now you can call the keyword as you did before.
I have been trying to screen scrape from IBM's mainframe and I got stuck trying to convert the Row and Col into a position (Function 99). I have tried my best to debug this simple error but I just cannot find what's wrong with it.
Debug.Print hllapi(99, "AR", 6, 53)
My sessions are connected, everything is working great except the Convert Position or RowCol (99) function I am trying to use. It keeps returning a status code of 9999 which indicates that my data string (i.e. "AR") is not uppercased or the letter P/R does not exist in the second character. ("Character 2 in the data string is not P or R or uppercased").
I have been unable to fix this despite trying all sorts of methods.
I have a string (46318g_orchidpinkminisneakpead) Here i want to chop off the part till "_" and give me the result. So my result should be "orchidpinkminisneakpead" now what expression should I use to get this value in ssrs and the chopped string size do differ sometimes it can be 7 char sometimes it can be 8,9 also.
I am building the report using a cube so no changes can be done on the back-end.
Try:
=MID(Fields!YourField.Value,
InStr(Fields!YourField.Value,"_")+1,
LEN(Fields!YourField.Value)
)
In your case,
=MID(
"46318g_orchidpinkminisneakpead",
InStr("46318g_orchidpinkminisneakpead","_")+1,
LEN("46318g_orchidpinkminisneakpead")
)
should produce orchidpinkminisneakpead
Let me know if this helps.
I am doing 2player game and when I get informations from server, it's in format "topic;arg1;arg2" so if I am sending positions it's "PlayerPos;x;y".
I then use split method with character ";".
But then... I even tried to write it on screen "PlayerPos" was written right, but it cannot be gained through if.
This is how I send info on server:
server.write("PlayerPos;"+player1.x+";"+player1.y);
And how I accept it on client:
String Get=client.readString();
String [] Getted = split(Get, ';');
fill(0);
text(Get,20,20);
text(Getted[0],20,40);
if(Getted[0]=="PlayerPos"){
text("HERE",20,100);
player1.x=parseInt(Getted[1]);
player1.x=parseInt(Getted[2]);
}
It writes me "PlayerPos;200;200" on screen, even "PlayerPos" under it. But it never writes "HERE" and it never makes it into the if.
Where is my mistake?
Don't use == when comparing String values. Use the equals() function instead:
if(Getted[0].equals("PlayerPos")){
From the Processing reference:
To compare the contents of two Strings, use the equals() method, as in if (a.equals(b)), instead of if (a == b). A String is an Object, so comparing them with the == operator only compares whether both Strings are stored in the same memory location. Using the equals() method will ensure that the actual contents are compared. (The troubleshooting reference has a longer explanation.)
As I asked in my previous question(Link) about concatenating a multipart string of variable lengths, I used the method answered there by rkhayrov and now, my function looks like this:
local sToReturn = string.format( "\t%03s\t%-25s\t%-7s\n\t", "S. No.", "UserName", "Score" )
SQLQuery = assert( Conn:execute( string.format( [[SELECT username, totalcount FROM chatstat ORDER BY totalcount DESC LIMIT %d]], iLimit ) ) )
DataArray = SQLQuery:fetch ({}, "a")
i = 1
while DataArray do
sTemp = string.format( "%03s\t%025s\t%-7d", tostring(i), DataArray.username, DataArray.totalcount )
sToReturn = sToReturn..sTemp.."\n\t"
DataArray = SQLQuery:fetch ({}, "a")
i = i + 1
end
But, even now, the value of score is still not following the order as required. The max length of username is 25. I've used %025s inside the while loop because I want the usernames to be right-justified, while the %-25s is to make the word UserName centre justified.
EDIT
Current output:
Required Output:
Displaying the list of top 5 chit-chatters.
S. No. UserName Score
1 Keeda 9440
2 _2.2_™ 7675
3 aim 7057
4 KGBRULES 6770
5 Guddu 6322
I think it's because of difference in fonts, but since most of the clients have Windows 7 default fonts(Tahoma/Verdana at 11px), I need optimum result for at-least that.
I think it's because of difference in fonts
It is. string.format formats by inserting whitespace. That only works for a fixed width fonts (i.e. all characters have the same width, including whitespace).
since most of the clients have Windows 7 default fonts(Tahoma/Verdana at 11px)
In what? How are they viewing your output? Do you write it to a textfile, that they then open in the editor of their choice (likely Notepad)? Then this approach will simply not work.
Don't know enough about your output requirements to steer you any futher, but it's worth noting that everyone has a browser so HTML output is very portable.
string.format doesn't truncate - the width of the field is minimum, not maximum. You'll have to truncate the strings to 25 characters yourself with something like DataArray.username:sub(0,25).
I'd remove the tabs from the string.format; and use the justification provided by %25s only. Won't be perfect but will probably be closer.
Use a fixed-width font if you can.