|
Hi ExpertComing,
I'm using System.IO.Ports.SerialPort from the 2.0 Framework.
Not using streamreader/writer.
thanx for the answer,
Jan
|
|
|
|
|
Just keep reading until you get the data. Stop reading when you have the amount of data you need. Discard all the zero's at the beginning that you don't need.
WM.
What about weapons of mass-construction?
|
|
|
|
|
Thanx Willem,
The problem is that i don't know how much it is upfront.
Logic is like this:
a) send request
b) get requested data
c) use requested data in another routine
there is no real end-of-transfer charcter to look for.
Also, after the request the device will not do anything (data-wise) until a new request is sent to the device.
What would be best here?
Something like:
1) send request
2) read data in loop until it has null or timeout?
Did you or anyone else have the same problem to tackle?
Thanx,
Jan
|
|
|
|
|
I used a little more complex protocol on the device I was communicating with.
It's a little problematic when you don't get an end-of-transfer character or something like that.
You could try reading in a loop until you get null. That should work perfectly well in this situation.
WM.
What about weapons of mass-construction?
|
|
|
|
|
Bedankt Willem,
i'm not requesting any source code but what specific subject should i google on for something similar like my 'problems'?
Tanx,
Jan.
|
|
|
|
|
I had this problem myself, I can demonstrate how you make a loop, however I don't know how the comport component of visual studio 2005 works.
byte? data;
while(data != null) {
}
WM.
What about weapons of mass-construction?
|
|
|
|
|
looping it is
Will need to test and see if there is any logic in termination of a stream or some kind of end-character.
Thanks.
|
|
|
|
|
I am trying to name a label using a string.
string labelname = "lbl" + skill;<br />
(Label)labelname.Text = skill;
That is the code, I get an error saying "'string does not conatian a definition for 'text'" The error makes sense, and I know why I am getting it, but how do I tell the system that string labelname is going to become Label labelname?
|
|
|
|
|
You can't. You can't turn one object into another. You need to *create* a label, then set it's Text property.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I have the label created, I just want to use the string to tell which one I want to set the text for.
|
|
|
|
|
Then why are you trying to cast the string to be a label, instead of using the label itself ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Because I am programming dynamically. I have the skills(which is where the variable skill comes from) in a database. I read the skills out of the database, into a variable, create a label, and now I want to set a label to say the skill.
Ex.
string skill = "Attack";
//Create the label
// The label is called lblAttack
I want to make the label say
Attack:
How?
Thanks Christian
|
|
|
|
|
lblAttack.Text = skill;
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Lol!
I don't REALLY know that the label is going to be "Attack", the database may change. I have a foreach statement that goes into the database, and sets an array(the array is where I really store the skill). I need to be able to do this:
lbl(skill).Text = skill;
But in a way that is acceptable, I don't have to do it that way either, just some way that is dynamic.
|
|
|
|
|
ExpertComing wrote:
I don't REALLY know that the label is going to be "Attack", the database may change
Obviously, but I followed your example, and the fact that you tried to cast a string to a label left me thinking this was what you needed to know.
ExpertComing wrote:
lbl(skill).Text = skill;
You can't name your variables locally like that. You CAN set their ID and tag values in this way.
You need to create a new Label ( just look in the InitializeComponent part of an app with a label predefined to see all the stuff you need to set ), then you can set it's text, and it's id/tag properties.
Oh, is this Winforms, or ASP.NET ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
ASP.NET, that is the problem.
|
|
|
|
|
OK - well, you need some sort of placeholder in your page, so you know where the labels will end up. The way to add a control to an ASP.NET page is to add it to the controls collection of the item that is to be it's direct parent.
If all you're doing is showing a bunch of labels, I'd be more included to use a repeater or datagrid, and bind it to your data source. Will that not work for you ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Here is what I have this may show you more...
StringBuilder szMyTable = new StringBuilder();
///The page begining
///Starts the html, body, form and table for the page
szMyTable.Append("");
///Establishes the number of tables, testboxes, and buttons using a FOR statement
foreach (string skill in skills)
{
szMyTable.Append("");
}
//End the page, then send the page to the Redirect
szMyTable.Append("");
szMyTable.Append("<asp:label id="lbl");
szMyTable.Append(skill);
szMyTable.Append("" runat="server" text="\"");
szMyTable.Append(skill);
szMyTable.Append("\"">");
szMyTable.Append(" | ");
Response.Write(szMyTable.ToString());
Response.End();
A datagrid will not work, as I am going to have the szMyTable include Textboxes and Buttons.
|
|
|
|
|
ExpertComing wrote:
szMyTable.Append("<body><form runat=server><table>");
Why are you doing this in an ASP.NET app ? This is a nightmare.
ExpertComing wrote:
szMyTable.Append("szMyTable.Append(skill);
szMyTable.Append(" runat=server Text=\"");
You can't do this, you're generating HTML *after* the controls have been created.
ExpertComing wrote:
A datagrid will not work, as I am going to have the szMyTable include Textboxes and Buttons.
You're treating asp.net as if it was asp. Scrap all this code, it's really working against the framwork. Instead, create a datagrid, which CAN include textboxes and buttons. There's a bit of work in getting the events from dynamically created controls, but it can be done, and that way, you'll use the framework instead of fighting it.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
What is the difference between asp and asp.net?
Both active server pages right?
|
|
|
|
|
No, asp is the old framework, it uses VBSCript and JScript. In ASP, you have to build your result sets using the sort of code you're using. ASP.NET is the framework that gives you access to things like codebehind, code reuse, etc. It's a whole different world. There's not enough money in the world for me to ever take an asp project again.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
But they are both actice server pages, but ASPX is the more efficient one correct?
|
|
|
|
|
They are both an ISAPI filter at the end of the day. Look, ANY framework generates HTML, but that doesn't mean you can do anything you want just writing your own HTML. ASP.NET is named as it is to show that it's the successor of asp. Have you ever used asp ? If you haven't, then I have no idea why you're generating code as you are ( especially putting in body and form tags ), but I promise you, it's the difference between cutting down the tallest tree in the forest with a chainsaw, or with a wet herring.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
No, I myself, have never used asp, although my dad works for Microsoft, and he taught me how to code, he did it that way, so I do. I have never used a datagrid before, can you give me a quick lesson or article to help me out.
Thanks a ton man, you have help me threw some problems before, thanks for all your help.
|
|
|
|
|
ExpertComing wrote:
No, I myself, have never used asp
Half your luck
This[^] is the best site for info on the datagrid.
Here[^] is a good place to start on MSDN.
Christian Graus - Microsoft MVP - C++
|
|
|
|