|
"cause of thread output or an application I/O prossesing was canceled"
i get this warning i didnt get serial datas
i think i must write invoke but how
|
|
|
|
|
Do you get any errors when you open the port? Also, can you post the code within the data_recieved event handler?
|
|
|
|
|
string[] data;
private void serialPort1_DataReceived(object sender,System.IO.Ports.SerialDataReceivedEventArgs e)
{
//problemhere//data=serialPort1.ReadLine().Split(System.Convert.ToChar(":"));
serialPort1.Close();
write();
}
|
|
|
|
|
Hmm, how are you opening the port? I can run the line where you are getting the error. Here is how I open mine:
<br />
try<br />
{<br />
if (comport.IsOpen)<br />
comport.Close();<br />
else<br />
{<br />
comport.BaudRate = int.Parse(Settings.Default.BaudRate.ToString());<br />
comport.DataBits = int.Parse(Settings.Default.DataBits.ToString());<br />
comport.StopBits = (StopBits)Settings.Default.StopBits;<br />
comport.Parity = (Parity)Settings.Default.Parity;<br />
comport.PortName = Settings.Default.PortName.ToString();<br />
<br />
try<br />
{<br />
comport.Open();<br />
}<br />
catch { }<br />
}<br />
}<br />
catch (Exception ex)<br />
{<br />
log.Write("ERROR: " + ex.Message, "InitializePort");<br />
}<br />
|
|
|
|
|
soon before i see blue screen on DOS it must be dangerous error?.now i ll try your code.
|
|
|
|
|
what is the "log" in your programme?
log.write(.....)
i mean this log. i try to write
|
|
|
|
|
You can take that out, its a class I wrote for logging errors.
|
|
|
|
|
my friend my computer will die soon second time my computer closed itself.
i just want to sequence my 6 datas.
|
|
|
|
|
Im not sure what else to tell you without seeing the code as a whole. What I have posted should work. Com ports are pretty easy to work with, just make sure its opened correctly, then read the data and do what you need to do with it.
|
|
|
|
|
i have done it many times.my problem is that:
i have a simulation project in wpf.so my serial datas will will simulate my robot arm s axises.for example:i send from microcontrolor to computer this:
for(;;)
{
delay_ms(1);
putc(value1);
putc(':');
putc(value2);
putc(':');
putc(value3);
putc(':')
putc(value4);
putc(':');
putc(value5);
putc(':');
putc(value6);
}
so i must get datas like this: "value1" for "axis 1","value2" for "axis2" ....
now could i explain my problem?
|
|
|
|
|
Ok, try concatinating all values into one string, then sending that string to the port all at once.
putc(value1 & ":" & value2 & ":" & value3 & ":" & value4 & ":" & value5 & ":" & value6);
Not sure what language you are using to send the information, so may need a different concatenation value. Then, when you recieve the data, you will get the whole string at once, and the Split() command will split all the values so data[0] will hold value1, data[1] will hold value2 and so on.
|
|
|
|
|
Sorry, but I doubt the entire concept of your project.
1)
Reality check: you want to send 6 bytes of data at 9600 Baud ?
with 1 start bit, 1 stop bit, no parity bit, a byte takes 10 bit times (a bit time is
1 second divided by the baudrate), that leads to a maximum of 960 bytes per second
(lets call this 1000 bytes per second, or 1 msec/byte for easier calculations).
Assuming you could send just 6 bytes (i.e. no overhead)
you will need almost 6 msec to transfer the amount of data you want to transfer every msec !?!?
2)
if 9600 Baud is the maximum your serial port (PC or target) can support, you are stuck.
You need more bandwidth, i.e. a higher baudrate, or a different interface hardware all together;
alternatively (and preferably, assuming data is not changing much) you should select some setup
with buffering+compression at the producer side (target), and buffering+decompression
at the consumer side (PC).
3)
you dont need separation characters between the six bytes, they serve no purpose;
you do need something that shows which byte is the first of a series of six.
Lets assume you use 7 bytes: 1 special character indicating "start of data", followed
by 6 data bytes. Your "start of data" value might also occur in one of the data bytes,
and hence you could have a case of mistaken synchronization, but if you test for that
and react properly, it will solve itself after a while (unless you are really unlucky;
to understand assume 5 of the 6 values you need to send happen to also have that special
value: how then can you tell to what channel belongs the one byte that differs ???)
4)
It will not be obvious to get the PC listen to the serial data in real-time; PCs are
not good in real-time stuff, they tend to do a whole lot of things, some in foreground,
some in background, and typically fast enough to satisfy the human user (who tolerates
delays of 10 or 100 msec, and occasionally a full second).
If you need better, you must work with "real-time" priorities, which easily will ruin
the behavior of all other processes unless you get everything correct, not a simple job.
5)
The normal way to connect a device (such as a robot arm) to a computer (such as a PC)
is by having a smarter target that executes intelligent commands, and reports higher-level
results (things like: rotate 20 degrees per second for the next 3 seconds; and "rotation'
done; new position=...". At that pace, you can easily have the PC follow the target.
Compare this with a printer: you send one byte to instruct it to print one character,
the PC does not control the paper movement, the head movement, the ink nozzles, the ribbon,
whatever; and the feedback is "page done" or "out of paper", not "paper has moved another
tenth of an inch".
6)
it is my conviction the requirements and/or the concept of this project exceed your
current technical skills and expertise, especially on PC side (embedded systems are easier
to program, and sending data is easier than correctly receiving it!).
You will need to rethink, and you probably will need much more help than any CodeProject forum
can offer you.
Anyway, I hope some of the above information will help you somehow.
|
|
|
|
|
i didnt do it:(i tried many codes but i didnt i will try more i must do it.thanks All of
|
|
|
|
|
If your micro is sending indivdual characters then in most cases the DataReceived event will be fired the number of times the characters are sent, i.e. you're trying to send 6 characters but by using 6 individual putc s it will fire off 6 DataReceived events. The best way would be to have a buffer to do something like this:
List<byte> buffer = new List<byte>();
private void serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
buffer.Add(serialPort.ReadByte());
if (buffer.Length == 6)
{
YourFunctionCall(buffer.ToArray());
buffer.Clear();
}
} The problem you mentioned in the other thread about Invoke is basically because Windows is using a different thread to receive data from the SerialPort, this is the one which is the owner of the DataReceived event. If you want to update for example some textboxes with teh values you receive you will have to do something like this:
private delegate void UpdateTextBoxes(byte[] values);
private void YourFunctionCall(byte[] values)
{
this.Invoke(new UpdateTextBoxes(this.UpdateTextBoxes));
}
privaet vodi UpdateTextBoxes(byte[] values)
{
this.txt1.Text = values[0].ToString();
this.txt2.Text = values[1].ToString();
} You might want to take a look at my article[^] which looks into this problem.
|
|
|
|
|
if i cant solve this problem i will write 1000000000 messages: ).it s so easy but it s not easy in real application i will try last helper 's codes i wish i can solve
|
|
|
|
|
I would try keeping an internal buffer as in my example because there is no guarantee of how Windows will receive the data, although the serial port has one of the highest IRQs of any hardware if Windows decides to go and do something then it decides to go and do it. I had to do something similar when parsing NMEA data from a GPS receiver, lines would come in a bit at a time.
|
|
|
|
|
i slept yesterday 03:30 at night i cant solve.i m not good at in visual c# so much.i have tried your codes but when i debug project so i see this:
"Visual Studio can not start debugging because the debug target 'C:\my project location\windowsapplication1.exe"' is missing.Please buld the project ........"
but i didnt anything wrong i can go mad soon
|
|
|
|
|
Hi All;
I am building a Windows form with multiple panels. I have a large panel as the base on the form, with a tab control on top of it, docked to fill, and multiple panels on the tab control. The base panel is docked to top of the form, with another panel below it, docked to the bottom. I also have a tool bar, and menu bar docked to the top of the form above the base panel. The problem I am having is that when I resize the form, I get a vertical scroll bar, but no horizontal scroll bar. I have autoscroll set to true, so not sure what the issue is. Do the panels on the tab control, or the tab control itself interfere with the horizontal scrolling?
|
|
|
|
|
Hi,
I have a ParentForm (FormMDI) and tow ChildForm : FormChild1, FormChild2
- Step1 : Open FormChild1 by Menu
FormChild1 f = new FormChild1();
f.MDIParent=this;
f.show();
- On FormChild1 I have a button when clicked it can open FormChild2 but FormChild2 still inside FormMDI.
Thank
Hoangsamac
|
|
|
|
|
hoangsamac wrote: On FormChild1 I have a button when clicked it can open FormChild2 but FormChild2 still inside FormMDI.
OK. It would probably help to see the code that creates your second child form. You showed the code that creates the first child, which apparently works fine. And on which form does this code sit?
|
|
|
|
|
Hi,
In ParentForm:
<br />
Memuitem_clicked(sender,e)<br />
{<br />
FormChild1 f = new FormChild1();<br />
f.MDIParent = this<br />
f.show();<br />
}<br />
My first child (FormChild1) contain a button and event:
<br />
button1_clicked(sender,e)<br />
{<br />
FormChild2 f = new formChild();<br />
f.MDIParent = ???
f.show();<br />
}<br />
In VB.Net,I see can do this
hoangsamac
|
|
|
|
|
Child form creation should really be left up to the parent form, but, to make yours work:
button1_clicked(sender,e)
{
FormChild2 f = new formChild();
f.MDIParent = this.Parent;
f.show();
}
|
|
|
|
|
Thank you very much !,
I did but code is:
f.Parent=this.ParentForm;
hoangsamac
|
|
|
|
|
Bitmap[] bitmaps = new Bitmap[42];
---
single minded; short sighted; long gone;
|
|
|
|
|
Hello everyone,
I try to create an add-in C# for Visual Studio 2005. I want to create a toolbar look like Visual Assist X but I don't know how. And I want to customize right-click-menu of TextEditor in VS 2005.
I have too little ebook C# about add-in. May you introduce or send me some ebooks? Thanks lots.
You're very nice to help me. Thanks lots.
imagic
|
|
|
|