On clicking an OK button I have a string of values, namely:
88,2015,5,17,22,6,53,2015,05,17,22,06,53,0,0,0,0,0,0,0,0
I am going to be sending these to an Arduino via serial, the problem is the format they are in at the moment.
The Arduino is expecting them in the same format (data type) as one would send from the serial terminal window and without a newline character added.
I am currently using Serial.parseint() in my code on the Arduino to receive the values separated by commas and load them into variables. (Which currently is working when I type the following into a serial terminal window:
88,2015,5,17,22,6,53,2015,05,17,22,06,53,0,0,0,0,0,0,0,0)
I could probably do this:
string mystr = "88,2015,5,17,22,6,53,2015,05,17,22,06,53,0,0,0,0,0,0,0,0";
int[] nums = Array.ConvertAll(s.Split(','), int.Parse);
But the I have to take them back to the same format.
How to I set/change the value of mystr to what the Arduino needs?
Not sure I understand, but if you mean you want to convert them back to a comma-separated string, you could do something like this:
string nums = string.Join(",", Array.ConvertAll(s.Split(','), int.Parse));
I've did some conversion functions for a friend some time ago, and He was also using arduino, I'm not sure it is exactly what you need, but maybe it can help
http://blogs.dotnetwork.it/sabrina/en/blog/c-conversioni-dati-che-passione/
The post is originally written in italian, but on the top of the page you can find a combobox to set the translation to english I've checked it and I think is comprehensible.
While learning about Console.ReadLine() in depth, I found something very peculiar.
I wrote following code in Main method in a console application in C#
string str = Console.ReadLine();
Console.WriteLine(str);
Console.WriteLine(str.Trim());
Console.ReadLine();
When I ran the code, I gave input as ctrl+A and pressed enter. I see smileys (not able to post image, as I don't have permission to do it yet).
I want to understand, how is it showing the smiley? Shouldn't it show ^A or empty/blank (empty because when I tried debugging it, it showed string value a " ".)
If you look at that Encoding used by Console then you can see that it is used IBM437.
Now go to page : http://en.wikipedia.org/wiki/Code_page_437
You will find that 1 has Smiley.
When you press ctrl + A , it will traslated into 1.
So you get that smiley.
string str = Console.ReadLine();
Console.WriteLine((int)str[0]); // Integer value of character.
// Console.OutputEncoding ( to get further detail)
Console.ReadLine();
The smiley is just how the console displays U+0001 (start of heading) - and that's the character that apparently is read as input from the console when you type Ctrl-A... a bit like the way that if you type Ctrl-G you get U+0007 (bell).
This isn't really .NET behaviour, so much as the Windows console behaviour (both input and output) - I can reproduce exactly the same behaviour in Java, for instance.
I try to figure out how to send the character "^" (not the CTRL command) to a external text window.
This different codes I have tried:
SendKeys.SendWait("^");
SendKeys.SendWait("(^)");
Sendkeys.SendWait("{^}"); //This should be the right code, but it doesn't work either
None of those would type me the character "^" in a text field.
If I send normal text to the window it appears in the window. The "^" cannot be typed somehow.
I had a look in the MSDN and in the Online Help, but couldn't find anything close to that problem.
Any ideas?
To send the character "^" using SendKeys.SendWait(), you need to think about which keys you're actually pressing. On an en-US keyboard it's Shift & 6, which translates to this:
SendKeys.SendWait("+6");
So whichever key combination you use to generate the "^" character, enter those keys into the SendKeys.SendWait() call.
I want to know if there's something similar to SendKeys.Send("test text {sleep 250} another test text"); in C#.
I know I can use Thread.Sleep but I get the string from the user input, and I won't be able to know how many times I have to sleep.
I don't believe there is a way to have SendKeys.Send() pause mid string.
If your reading the string to send from user input, you'd be better off parsing this string into a list of partial strings to send and pause between.
i.e. using your example, you'd have a list of strings: "text text "," another test test"
and a list of sleep intervals:250
The list of sleep intervals would naturally always be 1 item shorter than the list of string to send.
i have been using SendKeys.SendWait("insert letter here"); to send a letter to an all ready focused application. This works fine. I have aldo been using it like SendKeys.SendWait(letterstosend); to send a string with only letters in. I notice however it wont send a tring that has both letters and numbers in. It focuses the application but sends nothing.
Can anyone advise on how to write a loop to read the first letter in a string and then send it with the SendKeys.SendWait command and then read the second letter and send that etc for thw whole string?
Thanks
SendKeys should definitely handle multiple letters well, however, if you want to send each character you can solve it like this:
string text = "abc123";
foreach(char c in text)
SendKeys.SendWait(c.ToString());
Note that there are several special characters in SendKeys that you might have to escape for this to work properly. More info on MSDN.
This might also have been the problem why your original approach failed.