serial port and data sequencing problem...?
-
will i send ":" at the last of 6 values or between each of variable will be ":" 1)value1:value2:value3:value4:value5:value6: like this? 2)value1value2value3value4value5value6: or like this?
-
Like this: value1:value2:value3:value4:value5:value6 You dont need one after value6, but you'll need one in between each of the other values.
-
can i ask you different question? when i programme goes to serialport_datareceived(..) so how can i break this.and i want to call another function how can i do it?
I'm not sure I understand what you are asking. You should be able to call a function from with the data_recieved() function. Like this:
private void seriport_DataReceived(object sender, SerialDataReceivedEventArgs e) { // This method will be called when there is data waiting in the port's buffer string[] data; data = comport.ReadLine().Split(System.Convert.ToChar(":")); FunctionCall(); }
-
I'm not sure I understand what you are asking. You should be able to call a function from with the data_recieved() function. Like this:
private void seriport_DataReceived(object sender, SerialDataReceivedEventArgs e) { // This method will be called when there is data waiting in the port's buffer string[] data; data = comport.ReadLine().Split(System.Convert.ToChar(":")); FunctionCall(); }
-
i mean that must i break this thread?i tried to write serial data in serialport_datareceived();function but i didnt do it. must i use some "invoke" code and "break" like break codes?
-
i mean that must i break this thread?i tried to write serial data in serialport_datareceived();function but i didnt do it. must i use some "invoke" code and "break" like break codes?
-
i ll try:) did u write anything in this function?i mean did u try to write this data do textboxes in serialport_datareceived(..)?i tried but i didnt do it:)
-
yes.i cant remember now. now i try "readline" :).but my variables come very frequently.so must i clear "string[] data" ?my data will come every milisecond
-
yes.i cant remember now. now i try "readline" :).but my variables come very frequently.so must i clear "string[] data" ?my data will come every milisecond
-
Yes, once you parse the recieved data, you can clear the array that holds it. Another option would be to close the port until you need it opened again. To clear the array, I think this should work: Array.Clear(data, 0, data.Length);
-
"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:
try { if (comport.IsOpen) comport.Close(); else { // Set the port's settings comport.BaudRate = int.Parse(Settings.Default.BaudRate.ToString()); comport.DataBits = int.Parse(Settings.Default.DataBits.ToString()); comport.StopBits = (StopBits)Settings.Default.StopBits; comport.Parity = (Parity)Settings.Default.Parity; comport.PortName = Settings.Default.PortName.ToString(); // Open the port try { comport.Open(); } catch { } } } catch (Exception ex) { //no com port may be present log.Write("ERROR: " + ex.Message, "InitializePort"); }
-
Hmm, how are you opening the port? I can run the line where you are getting the error. Here is how I open mine:
try { if (comport.IsOpen) comport.Close(); else { // Set the port's settings comport.BaudRate = int.Parse(Settings.Default.BaudRate.ToString()); comport.DataBits = int.Parse(Settings.Default.DataBits.ToString()); comport.StopBits = (StopBits)Settings.Default.StopBits; comport.Parity = (Parity)Settings.Default.Parity; comport.PortName = Settings.Default.PortName.ToString(); // Open the port try { comport.Open(); } catch { } } } catch (Exception ex) { //no com port may be present log.Write("ERROR: " + ex.Message, "InitializePort"); }
-
Hmm, how are you opening the port? I can run the line where you are getting the error. Here is how I open mine:
try { if (comport.IsOpen) comport.Close(); else { // Set the port's settings comport.BaudRate = int.Parse(Settings.Default.BaudRate.ToString()); comport.DataBits = int.Parse(Settings.Default.DataBits.ToString()); comport.StopBits = (StopBits)Settings.Default.StopBits; comport.Parity = (Parity)Settings.Default.Parity; comport.PortName = Settings.Default.PortName.ToString(); // Open the port try { comport.Open(); } catch { } } } catch (Exception ex) { //no com port may be present log.Write("ERROR: " + ex.Message, "InitializePort"); }
-
my friend my computer will die soon:)second time my computer closed itself. i just want to sequence my 6 datas.
-
my friend my computer will die soon:)second time my computer closed itself. i just want to sequence my 6 datas.
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?
-
my friend my computer will die soon:)second time my computer closed itself. i just want to sequence my 6 datas.
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.