|
Hello,
I'm using the serial port control from .net 2.0 and an usb to serial(3 wires configuration) converter in order to communicate with a logic analyzer. The device makes a print screen, and I query it to send it over serial to my pc. If the image displayed on the device contains more information, such as fonts and various colors, I have some problems. Here is my scenario:
-The device sends the image in pcl format.
-I receive the bytes in the datareceived event and write them with a binary writer on to the disk. I've tried writing each time the event fired, as well as setting a threshold of 50000 (the image is about 30000) and a timer (I thought the operation with the disk made me lose some data) in order to write the entire buffer, after the transfer is made.
-I can appreciate if the data is correct by using a pcl to image converter, which displays the original image.
-For certain images, the converter fails to display the source, in that parses the image on 2 pages, an it displays a string of characters that it couldn't interpret from the file. (it displays it on the image).
-I know that the image is sent correctly because I used matlab to make the transfer, and it got the image ok.
-i've started modifying this solution:
http://msmvps.com/blogs/coad/archive/2005/03/23/SerialPort-_2800_RS_2D00_232-Serial-COM-Port_2900_-in-C_2300_-.NET.aspx[^]
I've read there are some problems with the serial port control, and used this to avoid it:
http://msdn.microsoft.com/en-us/magazine/cc301786.aspx[^].
I've written a small c program, which I wanted to include in my c# code, it sends the command, but when I poll portAddress + 5(the status register), it returns 0 or 0x60, but never a 0x01.
I've written a c++ (createfile,readfile) to communicate with the device, the device does not respond.
Yes,this is a school project, yes I'm on a tight schedule and i really need some help. Thank you.
P.S.I'm not doing it in matlab, because I want to continue extending the program in order to provide a virtual lab, accessible via internet.
For code requests, situations I have missed to ilustrate, please ask and debate.
My later edit: the pc sees the serial port on com12, due to the adapter and it seems that in c++ i have to write \\\\.\\com12 if com>10 as parameter for createfile. In c#, getports() return the com12 though.
Cosmin.
modified on Tuesday, February 3, 2009 2:19 PM
|
|
|
|
|
I've solved the problem. I found out that the issue was in the protocol I was using. As I've said before, I was using a 3 wire serial setup for communicating, and the device accepted xonxoff protocol or none. I thought it was best to use xonxoff, but it seems that the pc misinterprets some characters and I changed it over to none. Although there's no control over the communication, the image is sent correctly now.
Cosmin.
|
|
|
|
|
private delegate void _Post_Result(object[] data);
private void Post_Result(object[] data)
{
if (lvThreads.InvokeRequired)
{
_Post_Result upd = new _Post_Result(Post_Result);
this.lvThreads.Invoke(upd, new object[] { data });
}
else
{
ListViewItem lvitem = (ListViewItem)data[0];
this.lvThreads.Items[lvitem.Text].SubItems[1].Text = Convert.ToString(data[1]);
}
}
I am getting this error "Parameter count mismatch" in the bold line...
|
|
|
|
|
don234564 wrote: Parameter count mismatch
The error message always tells you the problem.
In this case, the number of parameters passed to the method is incorrect.
I don't know that method you're using, though, so I can't help you with that.
Kristian Sixhoej
"You can't undo the past... but you can certainly not repeat it." - Bruce Willis
|
|
|
|
|
Looks alright to me, I have to say. What is lvThreads?
Regards,
Rob Philpott.
|
|
|
|
|
don234564 wrote: new object[] { data }
data already is an object array, why create a new array holding this one array as its sole element?
BTW: there is no need to create the delegate over and over again, you can move the statement
_Post_Result upd = new _Post_Result(Post_Result); elsewhere (e.g. as a class member) and execute it only once.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Friday, June 10, 2011 11:38 AM
|
|
|
|
|
I think I must be missing something here - I can't see what's wrong with the code.
You create a new array holding the array as it's only element because that's the signature Control.Invoke expects. The array represents individual parameters, the fact there's only one and that it is itself an array is irrelevant.
But then, I think it should work so don't listen to me...
Regards,
Rob Philpott.
|
|
|
|
|
im confused either where im getting this wrong... anyone can try the code?
|
|
|
|
|
yes data is already an array. parameter in control.invoke refers to the number of parameters you pass this through in that case "upd" which is refered to Post_Results which contains only 1 param so thats the reason why you have to place the data into another array.
|
|
|
|
|
Never run into this situation but could you try what happens if you define the delegate as public.
Also as others pointed out, I don't see a reason to create a new array.
|
|
|
|
|
You have to create a new array because the outer array is the array of parameters TO PASS TO the called function, and the inner array IS the first parameter OF the called function. Since the called function takes an array as its first parameter...
|
|
|
|
|
Wouldn't casting work in this situation?
this.lvThreads.Invoke(upd, (object[])data);
|
|
|
|
|
I suspect that the exception is not being thrown here:
don234564 wrote: this.lvThreads.Invoke(upd, new object[] { data });
but somewhere here:
don234564 wrote: ListViewItem lvitem = (ListViewItem)data[0]; this.lvThreads.Items[lvitem.Text].SubItems[1].Text = Convert.ToString(data[1]);
And what you're actually experiencing is one of the whole panoply of wonders associated with multi-threading.
|
|
|
|
|
I have not actually found out whats really causing this but I re design my code and somehow got this to work.
here's what i'm using now.
private delegate void _Post_Result(object data);
private void Post_Result(object data)
{
if (lvThreads.InvokeRequired)
{
upd = new _Post_Result(Post_Result);
this.lvThreads.Invoke(upd, new object[] { data });
}
else
{
lvitem = (ListViewItem)data;
this.lvThreads.Items[lvitem.Index].SubItems[1].Text =
Convert.ToString(Convert.ToInt32(lvitem.SubItems[1].Text) + 1);
}
}
|
|
|
|
|
speech to text using neural networks in c#
any one knows about that plz send
|
|
|
|
|
You won't get that type of help here. If you get stuck on a specific problem, then come back. These types of posts will be scorned, so try not to do that. If you want code with no work whatsoever, go to this site[^].
|
|
|
|
|
I 'Scorn' upon your post
My opinion is... If someone has already posted an answer, dont post the SAME answer
|
|
|
|
|
Lol, 5 for being funny, 1 for making fun of me. 5 for the smiley. 5+1+5/3 = 3.66~ rounded up to 5.
|
|
|
|
|
LOL, i demand a recount!!! The scorn was in-leauge with you, and aimed at the OP, they really need to learn
P.S should it be 5.0 + 1.0 + 5.0 / 3.0 if you want it to equal 3.66?
P.P.S Nevermind, i missed you already made that joke with the rounding lol
My opinion is... If someone has already posted an answer, dont post the SAME answer
|
|
|
|
|
Scorn, I think you'll find is a noun, not a verb.
Regards,
Rob Philpott.
|
|
|
|
|
Certainly. Please send your credit card details, home address, phone number and photocopies of your signature to ExiledPrince@NigeriaMail.com. The next instant, all of your code will appear on your screen; you'll have to move out of the way though - my CodeRay is blocked by dense objects
Incidentally, a simple google search would have thrown up results regarding some of the new classes in the .Net Framework 3.5 running in Windows Vista; namely those of speech recognition. Then, you 'simply' integrate that with your own neural network
|
|
|
|
|
char a = 'A';
char b = 'B';
a = a + b;
a += b;
I thought they r both exactly the same thing. Can someone tell me whats the difference.Pl.
|
|
|
|
|
i think...
a = a + b;
is trying to assign a string (a + b) to a char (a)
where as..
a += b;
is taking them to be int values and adding 65 + 66 (ASCII values) and setting a to be 131
Atleast this is my understading
My opinion is... If someone has already posted an answer, dont post the SAME answer
|
|
|
|
|
5'ed, I think that's correct but without looking it up I can't be sure. That makes the most sense.
|
|
|
|
|
The meaning of + operator depends on the types added together.
"A char can be implicitly converted to ushort, int, uint, long, ulong, float, double, or decimal. However, there are no implicit conversions from other types to the char type"
For chars the + is adding the integers together that are used for representing a single char. So in your first line the result is an int.
The second line contains automatically assignment so the result type cannot change (since you don't have an intermediate result) thus the operation results to a char. In the line having an error you must do casting explicitely to the intermediate result.
|
|
|
|