|
mkalantri wrote: In my project they asked to use MSN but it's settings
Is ur question is complete?
Cheers!!
Brij
|
|
|
|
|
Dear all,
I had been using serial communication for my device to talk to the PC. But these days, I have decided to replace the serial com with usb and I have bought a serial to usb converter for that. But I don't actually know how to interface that converter with my C# code. Previously I worked with C# code for interfacing with HID class device, but the present device I am using seems not to be configured as HID. I tried with it's product and vendor ID to communicate with it from my previous hid software but failed.
Please provide me some suggestions regarding this. If you have any code samples or link, please share
with Thanks....
|
|
|
|
|
If your USB to serial converter is properly installed it will appear to your application as a serial port (that's exactly what it's for). You shouldn't need to change anything in your code except the COM port number.
A serial port is not an HID.
Phil
The opinions expressed in this post are not necessarily those of the author, especially if you find them impolite, inaccurate or inflammatory.
|
|
|
|
|
Hi guys,
I am doing a per thread singleton, I want to know if the objects are the same or not by comparing the addresses of the references. How do I print the address of a reference?
Thank you in advance!
|
|
|
|
|
I'm not sure that you can, although C# does support pointers in general, you're better off making sure your objects have a unique Id you can compare.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
I guess I'll just implement the GetHashCode method for my class. Thank you for your reply!
|
|
|
|
|
If you just want to check if two objects refer to same location in memory, then use the Object.Equals method.
C isn't that hard: void (*(*f[])())() defines f as an array of unspecified size, of pointers to functions that return pointers to functions that return void
"Always program as if the person who will be maintaining your program is a violent psychopath that knows where you live." - Martin Golding
|
|
|
|
|
Hi, thanks for your answer! I dun think I can use Object.Equals . Because I want to know the object deleted in the Uninitialize() is not the same; I do not have 2 objects to compare in the Uninitialize() , Uninitialize() can be called multiple times, each time for each thread for my per thread singleton. Your answer is useful to me in the future, anyway. Thanks again!
|
|
|
|
|
Wong Shao Voon wrote: I want to know if the objects are the same or not by comparing the addresses of the references.
if (object.ReferenceEquals(object1, object2)) ...
Wong Shao Voon wrote: How do I print the address of a reference?
You could get a pointer to the object, convert the pointer to an IntPtr, which you can convert to an Int64, and display the value. However, you either would have to keep the object pinned (which is bad for memory management), or continuously update the display to show any changes, as the garbage collector can move the object at any time.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks for reminding me that the addresses do change, due to GC.
|
|
|
|
|
How to create a jagged array of multiple data-type data?
Hallo everyone,
I need a little help in creating an array that holds this kind of data:
It should be a dynamic two dimensional array similar to a dataset in a database.
All rows of a column have the sama data type.
int | string | System.Drawing.Color | System.Drawing.Rectangle(=Struct) | 1 | "TEST1" | Color.Black | {,,,,} | 2 | "TEST2" | Color.Blue | {,,,,} | 3 | "TEST3" | Color.Green | {,,,,} | 4 | "TEST4" | Color.Red | {,,,,} |
With "dynamic" I mean that I don't need to specify the size of the array and that I can add as many rows as I like.
Even at creation time of the array I don't know how many rows it will get.
To realize this I'd like to use Lists.
I had something like this in my mind:
public object[] [] AxisLabelItems = new object[4] [] {<br />
new List<Int32>(), <br />
new List<String>(), <br />
new List<System.Drawing.Color>(),<br />
new List<System.Drawing.Rectangle>()};
but that doesn't work: "Implicit conversion from List to object not possible"
Any suggestions?
Thanks.
PS: Why are there all the new lines above the html-table? They belong to the table somehow..?? (If I mark these lines the fields of the table get marked too.)
I've just used:
<table border="1">
<tr>
<th> </th>
</tr>
<tr>
<td> </td>
</tr>
</table>
|
|
|
|
|
You seem to be half way there. Why not use lists of lists insead of arrays?
|
|
|
|
|
It looks like a list of structs to me, or maybe a list of some class. No arrays involved.
|
|
|
|
|
You are not thinking object oriented enough. You don't use a jagged array for something like that, you use a list of custom objects.
Create a class:
public class AxisLabel {
public int Id { get; private set; }
public string Name { get; private set; }
public Color Color { get; private set; }
public Rectangle Rectangle { get; private set; }
public AxisLabel(int id, string name, Color color, Rectangle rectangle) {
Id = id;
Name = name;
Color = color;
Rectangle = rectangle;
}
}
Create a list of objects:
List<AxisLabel> axisLabelItems = new List<AxisLabel>();
Add in item to the list:
axisLabelItems.Add(new AxisLabel(1, "TEST1", Color.Black, new Rectangle(1,2,3,4)));
LightIceStorm wrote: Why are there all the new lines above the html-table?
Because you have <br /> tags between the rows and cells in the table. As they don't belong there, they are displayed outside the table, in this case the browser chose to display them before the table.
[Edit]
Corrected some encoding in the code.
Despite everything, the person most likely to be fooling you next is yourself.
modified on Monday, December 15, 2008 6:06 PM
|
|
|
|
|
Guffa wrote: public int Id { get; private set; }
Cool externally read only properties - learn something every day. Thanks
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hallo Guffa,
thank you for your reply.
Unfortunately there is a little problem with:
Guffa wrote: List axisLabelItems = new List();
I get following error for the "new List" (translated):
"The use of type "System.Collections.Generic.List<t>" (generic) makes the 1-type-argument necessary."
Any ideas?
By the way: To prevent the creation of the <br /> tags, I have to use just 1 line for the whole HTML section, because every \r\n in the textbox gets converted to the <br /> tag.
|
|
|
|
|
LightIceStorm wrote: Unfortunately there is a little problem with:
Guffa wrote:
List axisLabelItems = new List();
That's because of the backwards way that this forum handles html in the messages. Instead of encoding everything except the few html tags that makes sense to use, it allows any html code and tries to remove the most dangerous code...
I just forgot to encode some code. This is how it should look:
List<AxisLabel> axisLabelItems = new List<AxisLabel>();
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hello,
Actually I'm not sure if a Picture Box is the right control for my need, but I'm just guessing it is. I'm new to C#, so haven't got much of an idea. I'm using MS Visual C# 2005.
Here is my problem.
I read data from a file which contains text lines seperated by a return. Then according to the data lines, I need a verticle bar (deciding what this control is upto me, and I'm guessing it is a Picture Box) be filled with different colors.
For example let's say this is the text file.
A
B
C
A
Then, in the C# Form, on whatever that control I need four color lines be displayed according to the text. So, if we assign colors as follows:
A - Red
B - Yellow
C - Green
Then the color lines should be displayed like
Red
Yellow
Green
Red
I think you get the drift.
Please note that there could be any number of text lines in the text file, but the control height I use need to be remained the same. So, according to the number of lines in the text file, height of each color strip in the control should differ.
Please help me with this.
Thanks in advance.
|
|
|
|
|
The big issue that many people have is that they mistake the picture box for a lot of things that it isn't. Your best bet for what you want, is to draw the image yourself in your paint handler, then draw your lines, etc.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Thanks for the reply mate.
Could you please show me how?
|
|
|
|
|
Just to give you an idea, you can create a custom control inherited from System.Windows.Forms.Control and hook to its Paint event, like this:
this.Paint += new PaintEventHandler(CustomComponent_Paint);
Then, draw your stuff in your PaintEventHandler:
void CustomComponent_Paint(object sender, PaintEventArgs e) {
Brush brush = new SolidBrush(Color.Red);
Pen pen = new Pen(brush);
Rectangle rect = new Rectangle(0,0,100,100);
e.Graphics.FillRectangle(brush, rect);
}
You can get the colors you need and create different color brushes for any of you cases
Regards,
Lev
|
|
|
|
|
I recently started looking into C# as I needed a solid language that can use windows COM for iTunes interactions. With C# 2008 I thought that XML would be a breeze, this is not the case. I am loading an xml file from the net and I simply want to retrieve one field(<tx>) from the document but I cannot find a simple way of doing this.
A sample xml document:
<start>
−
<sg>
<cs>dc583ca591</cs>
<id>532800</id>
<ar>Switchfoot</ar>
<tt>The Shadow Proves the Sunshine</tt>
<al>Nothing Is Sound</al>
−
<tx>
Sunshine,[br] free limited API lyricsfly.com temporary weekly access [br] won't she be my mother?[br]
Sunshine, come and help me sing[br]
My heart is darker than these oceans[br]
My heart is frozen underneath[br]
[br]
We are crooked souls trying to stay up straight[br]
Dry eyes in the pouring rain[br]
Where the shadow proves the sunshine[br]
The shadow proves the sunshine[br]
[br]
Two scared little run aways[br]
Hold fast till the break of daylight[br]
Where the shadow proves the sunshine[br]
The shadow proves the sunshine[br]
[br]
O Lord, why did you forsak... *** Your access it restricted to 30% of content. Please get permanent user ID key for 100% at lyricsfly.com/api/ *** [br] Lyrics delivered by lyricsfly.com [br]
</tx>
</sg>
</start>
The code that I have written so far:
String URLString = "http://lyricsfly.com/api/api.php?i=de5abbf415fd84ca6-temporary.API.access&a=" + track.Artist + "&t=" + track.Name;
XmlTextReader reader = new XmlTextReader(URLString);
Thanks in advance, Luke.
|
|
|
|
|
|
If you are using .NET 3.5 then I'd use the new System.Linq.Xml classes.
Also, you need to get the HTTP content - And you have to provide a safe way of generating the URL.
To generate your URL, use something like this as it will ensure that any characters in the Artist and Name properties are correctly encoded for use in a URL.
string url = string.Concat(
"http://lyricsfly.com/api/api.php?i=de5abbf415fd84ca6-temporary.API.access&a=",
HttpUtility.UrlEncode(track.Artist),
"&t=",
HttpUtility.UrlEncode(track.Name));
Now, to get the data you need to get it from the internet. To do this you need to do something like this:
string data;
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (Stream stream = response.GetResponseStream())
{
StreamReader reader = new StreamReader(stream);
data = reader.ReadToEnd();
}
HttpWebRequest and HttpWebResponse are in System.Net namespace.
Now, to convert that data into an XML object graph you can use:
XElement doc = XElement.Parse(data);
From this point onwards you can use LINQ syntax to query the XML, or you can do it yourself.
For example, to get all the Songs (I presume that's what element "sg" is) you can do this:
IEnumerable<XElement> = doc.Elements("sg");
To get the lyrics of the first song, this should work:
string lyrics = doc.Element("sg").Element("tx").Value;
Does this help?
|
|
|
|
|
Yes, thank you so much. I could not find this anywhere.
|
|
|
|
|