|
If all of that saya you are getting responses, then what kind of data are you expecting? Could it be that all you need to do is add a single '+' character to your code?
textBox1.Text += serialPort1.BytesToRead.ToString();
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
Hi everyone, I got my solution by doing this. If anyone has the same problem you may try this.
serialPort1 = new SerialPort("COM3", 19200, Parity.None, 8, StopBits.One);<br />
serialPort1.ReadTimeout = 1000;<br />
serialPort1.Handshake = Handshake.None;<br />
serialPort1.ReceivedBytesThreshold = 1;<br />
this.serialPort1.DtrEnable = true;<br />
this.serialPort1.Handshake = System.IO.Ports.Handshake.RequestToSend;<br />
this.serialPort1.ParityReplace = (System.Byte)(0);<br />
<br />
if (!serialPort1.IsOpen)<br />
serialPort1.Open();<br />
this.serialPort1.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(this.serialPort1_DataReceived);<br />
byte[] request1 = new byte[] { (byte)'P', 4, 40, (byte)'@' };<br />
serialPort1.Write(request1, 0, request1.Length);<br />
textBox1.Text = serialPort1.BytesToRead.ToString();<br />
this.serialPort1.ErrorReceived += new SerialErrorReceivedEventHandler(serialPort1_ErrorReceived);
|
|
|
|
|
Hi,
please use PRE tags or the "code block" widget (not CODE tags or the "inline code" widget) to show multi-line code; it would preserve formatting, which makes things much more readable.
You can't touch your GUI Controls inside a DataReceived handler; this handler is asynchronous and runs on a ThreadPool thread, not on the main thread, so touching Controls there is forbidden. This[^] tells you more about it.
|
|
|
|
|
I want to create a datagrid inside a property grid,
As follows:
1. Property Name is same and it will have multiple dynamic rows. Each row will have 2 buttons. One to delete & one to fill data.
In datagrid it will be 3 columns, one for value & 2 for buttons.
Is it possible to create such a datagrid inside a property grid?
|
|
|
|
|
Sangeetha23 wrote: Is it possible to create such a datagrid inside a property grid?
Have you considered a UI Type Editor[^]? Or did you want to "embed" this datagrid into the PropertyGrid itself?
I are Troll
|
|
|
|
|
I gave him the same answer in Q&A. Hope he's got the message.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
It would be more fun when someone posted something creative
Would the question already be on SO or MSDN by now?
I are Troll
|
|
|
|
|
Thanks for your reply.
From msdn, i found UITypeEditor provides dropdwon & Modal buttons as uitypeeditoreditstyles. But I was not able to find the way to use both together.
Also the way to add rows dynamically is not clear.
|
|
|
|
|
Can you please provide suggestion to add multiple rows one after another.
Example Property will be "child Blocks". Values can be the multiple child blocks which user will browse one by one with a modal window. After each row getting filled with value one new row has to be added.
|
|
|
|
|
One possibility is to use a BindingSource[^] component as the DataSource for your DataGridView , then you can either have a Collection or DataSet as the DataSource of the BindingSource , or alternatively you can use the BindingSource as the Collection utilising its' Add, Insert, Remove and RemoveAt methods. Either way, all you need to do is programmatically add, delete or whatever, your new rows/child-blocks at the appropriate times. Because you will be using a BindingSource the changes to the collection should be automatically reflected in the DataGridView .
The BindingSource is a much under used component which is incredibly useful.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
C# Problem:
I have a string: " DH#2010-04-30-13:45:33"
Within this string a have certain charactes I want to use, and some I dont want to use:
2010 is my year,04 is my month,30 is my day,13 is my Hour,45 is my Minutes,33 is my Seconds
That string can come to me in many ways but this is the example for now.
I want to spesify the string to be used with another string, like a format guide.
This string is in my textboxbox and looks like this:
"___yyyy-MM-dd HH:mm:ss"
The first 3 underscores tells it to ignore the DH# part (3 Charactors)'
Then it needs to recognize the 2010 as yyyy, then 04 as MM etc.
The string can also be "#04#2010#30#13#45#33#
Then my format string will look like this: "_MM_yyyy_dd_HH_mm_ss_"
or
"DT04042010-134533"
Then my Format string will look like this: "__ddMMyyyy_HHmmss"
The format string I can specify, but the original string comes from a PLC in anyway it likes.
My format string specifies what each charactor in the string represents.
The underscore basicly tells the code to ignore the charactor in that place, in either:
yyyy,MM,dd or etc takes that digit and place it in the format I specify.
So I can use it to place it into the DateTime object.
Please help
|
|
|
|
|
I know of no standard way of specifying a wildcard for parsing DateTime strings, so you would have to remove the unwanted characters explicitly.
This is what you could do:
create a new format string and a new data string skipping the irrelevant characters (i.e. the '_' positions in the original format string), then pass the results to DateTime.TryParseExact
Example:
turn ___yyyy-MM-dd HH:mm:ss into yyyyMMddHHmmss
and DH#2010-04-30-13:45:33 into 20100430134533
[ADDED]
This approach will not work well all the time; IMO it does under these circumstances:
- all fields are numeric
- all fields have 2 digits, except year which needs 4.
[/ADDED]
|
|
|
|
|
Sorry but that won't work for DateTime.TryParse(). It needs the delimiters between date and time components.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
No separators required. I ran a little test:
DateTime dt;
bool OK=DateTime.TryParseExact("20100430134533", "yyyyMMddHHmmss", null, DateTimeStyles.None, out dt);
log("OK="+OK+" dt="+dt.ToString());
result:
15:10:45.819 CPTest.log-57 OK=True dt=30-Apr-2010 13:45:33
so it works just fine for me.
|
|
|
|
|
I ran a test also that failed. Of course I didn't use the expanded version you did
DateTime dt = new DateTime();
if(DateTime.TryParse("20100430134533", out dt))
{
}
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
without any format string, it won't work, however that is not how I understood the OP; AFAICT he wants to explicitly specify the format string in his syntax, so I suggested to modify it and the data itself by basically removing the non-digits.
My approach works fine in some cases, not in all; I now expect problems with:
- single-digit values well as single-letter format specifiers accept one or two digits
- 12-hour notations
- and maybe month names
So a much more elaborate scheme is in order; one must make sure to use a CultureInvariant to avoid problems with time and date separator characters that may have been regionally set to something special (DateTime.Parse treats ":" and "/" in a special way).
|
|
|
|
|
Looks like a good class assignment.
In about three weeks we should see and Urgent, Pleaze help posting.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I do like it as an exercise, as it is a rather open question, the task definition is incomplete ("format could be anything"??) and there probably is no best approach.
BTW: I do like V's approach in another thread branch below.
|
|
|
|
|
The first thing would be to split the sting into date and time components. From there replace the delimiter characters with appropriate separators for the part, / or - for date and : for time. Of course where there is no delimiter you'll have to resort to substring parsing or regex replacement. You'll have teh problem though of trying to determine what format the date is in, mm/dd/yyyy, dd/mm/yyyy, yyyy/mm/dd or any combination. The way to control this is specify the format to use and reject if not in that format.
Once you have the date and time parts, use DateTime.TryParse()
string date = "04/15/2010";
string time = "13:54:32";
DateTime dt = new DateTime();
if(DateTime.TryParse(date + " " + time, out dt))
{
}
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi guys thank you for the reply:
The problem I have is not with putting my string into the DateTime.
I need to pinpoint each character in my original string, to match my Format string.
To extract that values with in the original string. that represents its character in my format string.
eg:
String 1= "#2011-04-30 15:23:22"
String 2= "_yyyy-MM-dd HH:mm:ss"
so that yyyy = 2010, and MM=04 etc.
Then I need to use that values and build my string to put into the DateTime.
But both these 2 strings can be in any order, so if that happens, I can change my format string (String2)
to match that format in String1 and still get the value that correspond to the value I need from String 1.
Hope this clears it up a bit.
Thanks so much for the help up to date.
|
|
|
|
|
As Luc has shown you should be able to parse the strings and use it in DateTime.TryParse
DateTime dt;
DateTime.TryParseExact(string1, string2, null, DateTimeStyles.None, out dt);
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I'm afraid I changed my mind about my approach, see my other reply to you.
|
|
|
|
|
Is it possible to replace every non - numerical character in the string to 1 special character you use for delimeting? then TryParse the string with that format to a date.
V.
|
|
|
|
|
yes, that seems the best so far; provided:
- you choose a special character other than ':' and '/'
- you don't need AM/PM nor month names
public override void Test(int arg) {
test("2010.04.30.13.45.33", "yyyy.MM.dd.HH.mm.ss");
test("2010.04.30.13.4.3", "yyyy.MM.dd.HH.m.s");
test("2010.4.2.3.4.3", "yyyy.M.d.H.m.s");
}
private void test(string data, string format) {
DateTime dt;
bool OK=DateTime.TryParseExact(data, format, null, DateTimeStyles.None, out dt);
log("data="+data.PadRight(20)+"format="+format.PadRight(20)+" OK="+OK+" dt="+dt.ToString());
}
yields
data=2010.04.30.13.45.33 format=yyyy.MM.dd.HH.mm.ss OK=True dt=30-Apr-2010 13:45:33
data=2010.04.30.13.4.3 format=yyyy.MM.dd.HH.m.s OK=True dt=30-Apr-2010 13:04:03
data=2010.4.2.3.4.3 format=yyyy.M.d.H.m.s OK=True dt=02-Apr-2010 3:04:03
|
|
|
|
|
Basically what I was saying "replace the delimiter characters with appropriate separators for the part". I just didn't understand the need to support multiple formats.
I know the language. I've read a book. - _Madmatt
|
|
|
|