mira lo q pasa es que cuando recibo los datos en visual c# llega todo en una sola cadena todos los datos; osea toda la cadena envia; lo q quiero es q cuando lleguen se puedan separa de nuevo y tome los datos independientemente, que vuelva y aparezca envia[0], envia[1].....envia[4] con el fin de manipular cada uno y poderlos modificar o hacer lo q quiera yo...
a groso modo esto tengo en c# lo q pasa es q no llegan los datos cmo debe ser
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
List<byte> recibido = new List<byte>();
string dato;
string [] dato2= new string[8];
float t;
uint ADCValue1 = 0;
uint ADCValue2 = 0;
byte[] buffer = new byte[16];
bool inicioClick = false;
public Form1()
{
InitializeComponent();
deshabilita_controles();
richTextBox1.Text = "\npresione el boton de conectar puerto serial antes de enviar otro comando";
if (inicioClick == false)
{
return;
}
}
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
int bytes = serialPort1.BytesToRead;
//if (bytes > 16) bytes = 16;
serialPort1.Read(buffer, 0, 8);
dato2[0] += Convert.ToString(buffer[0]);
dato2[1] += Convert.ToString(buffer[1]);
dato2[2] += Convert.ToString(buffer[2]);
dato2[3] += Convert.ToString(buffer[3]);
dato2[4] += Convert.ToString(buffer[4]);
foreach (Byte Bite in buffer)
{
dato += Convert.ToString(Bite) + " ";
}
if (buffer[1] ==0x61 ) { pictureBox1.BackColor = Color.Yellow; }
if (buffer[1] == 0x62) { pictureBox1.BackColor = Color.GreenYellow; }
if (buffer[2] == 0x61) { pictureBox2.BackColor = Color.Yellow; }
if (buffer[2] == 0x62) { pictureBox2.BackColor = Color.GreenYellow; }
ADCValue1 = (uint)buffer[3];
ADCValue2 = (uint)buffer[4];
// Muestra los valores en las barras de progreso.
//progressBar1.Value = buffer[3];
//progressBar2.Value = buffer[4];
//dato = Convert.ToString(buffer[0]);
}
private void button1_Click(object sender, EventArgs e)
{
serialPort1.Open();
recibido.Clear();
inicioClick = true;
habilita_controles();
}
private void button2_Click(object sender, EventArgs e)
{
byte[] mBuffer = new byte[1];
mBuffer[0] = 0x61; //ASCII letra "a".
serialPort1.Write(mBuffer, 0, mBuffer.Length);
dato = "";
resetea();
}
private void timer1_Tick(object sender, EventArgs e)
{
richTextBox1.Text = " el pwm1 esta al: " + dato2[0] + " %\n el pwm2 esta al: " + t + " %" + "\n el adc1 esta al: " + dato2[3] + "\n el adc2 esta al: " + dato2[4];
}
private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
byte[] miBuffer = new byte[1];
// Luego enviamos los datos
// del duty_cicle del PWM1.
miBuffer[0] = Convert.ToByte(pwm.Value);
serialPort1.Write(miBuffer, 0, miBuffer.Length);
t = ((float)pwm.Value * 100)/250;
resetea();
}
private void button3_Click(object sender, EventArgs e)
{
byte[] mBuffer = new byte[1];
mBuffer[0] = 0x62; //ASCII letra "b".
serialPort1.Write(mBuffer, 0, mBuffer.Length);
resetea();
}
private void button5_Click(object sender, EventArgs e)
{
byte[] mBuffer = new byte[1];
mBuffer[0] = 0x64; //ASCII letra "d".
serialPort1.Write(mBuffer, 0, mBuffer.Length);
richTextBox2.Text = " cambio estado pin b1+\nla entrada en bytes es: " + dato;
resetea();
}
private void button4_Click(object sender, EventArgs e)
{
byte[] mBuffer = new byte[1];
mBuffer[0] = 0x63; //ASCII letra "c".
serialPort1.Write(mBuffer, 0, mBuffer.Length);
richTextBox2.Text = " cambio estado pin b0"+"\nla entrada en bytes es: " + dato;
resetea();
}
private void button6_Click(object sender, EventArgs e)
{
byte[] mBuffer = new byte[1];
mBuffer[0] = 0x65; //ASCII letra "e".
serialPort1.Write(mBuffer, 0, mBuffer.Length);
resetea();
}
private void habilita_controles()
{
// Habilita salidas digitales.
button2.Enabled = true;
button3.Enabled = true;
button4.Enabled = true;
button5.Enabled = true;
button6.Enabled = true;
// Habilita controles PWM.
pwm.Enabled = true;
// Habilita entradas digitales.
timer1.Enabled = true;
pictureBox1.Enabled = true;
pictureBox1.BackColor = Color.GreenYellow;
pictureBox2.Enabled = true;
pictureBox2.BackColor = Color.GreenYellow;
}
private void deshabilita_controles()
{
// deshabilita salidas digitales.
button2.Enabled = false;
button3.Enabled = false;
button4.Enabled = false;
button5.Enabled = false;
button6.Enabled = false;
// deshabilita controles PWM.
pwm.Enabled = false;
timer1.Enabled = false;
// deshabilita entradas digitales.
pictureBox1.Enabled = false;
pictureBox1.BackColor = Color.Gray;
pictureBox2.Enabled = false;
pictureBox2.BackColor = Color.Gray;
}
private void button7_Click(object sender, EventArgs e)
{
serialPort1.Close();
recibido.Clear();
inicioClick = false;
deshabilita_controles();
}
private void resetea()
{
dato = "";
dato2[0] = ""; dato2[1] = ""; dato2[2] = ""; dato2[3] = ""; dato2[4] = "";
}
}
}
saludos te cuidas estamos en contacto y en el picc es el siguiente:
#include <16F873A.h>
#use delay(clock=4000000)
#fuses XT,NOWDT,NOPROTECT
#byte puerto_b=6
#use RS232(BAUD=9600, BITS=8 ,PARITY=N, XMIT=PIN_C6, RCV=PIN_C7)
#use fast_io(b)
main() {
float l;
char recibe[2], envia[8];
int8 d, b, k;
int8 valorPWM2=0, valor_adc_1, valor_adc_2;
set_tris_b(0xf0);//puerto B como salida y entrada
setup_adc_ports(all_analog); // Configura canales usados por el ADC.
setup_adc(ADC_CLOCK_internal);
setup_ccp1(CCP_PWM);
setup_ccp2(CCP_PWM);
setup_timer_2(T2_DIV_BY_4, 250, 1);
puerto_b=0;
d=50;
while(true){
if(kbhit()) //prueba si a llegado un caracter
{
recibe[0]=getc();
if(recibe[0]=='a'){if(d==100){d=100;} if(d<100){d=d+1;}l=d;envia[0]=d;
b=d*2.5;set_pwm1_duty(b);}
if(recibe[0]=='b'){if(d==0){d=0;} if(d>0) {d=d-1;}l=d;envia[0]=d;
delay_ms(50);b=d*2.5;set_pwm1_duty(b);}
if(recibe[0]=='c'){output_toggle(PIN_B0);}
if(recibe[0]=='d'){output_toggle(PIN_B1);}
if(recibe[0]!='d'&&recibe[0]!='a'&&recibe[0]!='b'&&recibe[0]!='c'&&recibe[0]!='e'){valorPWM2=recibe[0];set_pwm2_duty(valorPWM2);}
if(recibe[0]=='e'){if(input_state(pin_b4)==0x01){delay_ms(20); envia[1]='a';}else{envia[1]='b';}}
if(recibe[0]=='e'){if(input_state(pin_b5)==0x01){delay_ms(20); envia[2]='a';}else{envia[2]='b';}}
set_adc_channel(0); // Seleccionamos el canal 0 y comenzamos a leer.
delay_us(10); // Esperamos un tiempo para estabalizar el dato leido.
valor_adc_1 = read_adc();
set_adc_channel(1); // Seleccionamos el canal 1 y comenzamos a leer.
delay_us(10); // Esperamos un tiempo para estabalizar el dato leido.
valor_adc_2 = read_adc();
envia[3]=valor_adc_1 ;
envia[4]=valor_adc_2 ;
puts(envia);
delay_ms(100);
}
}
}
ahora si te cuidas estamos hablando vemos pues si me puedes ayudar te lo agradeceria...
miara aqui te envio lo q tengo tanto en visual c# como en picc ahi creo q con eso te daras cuenta de lo q pasa... espero me ayudes Meta te cuidas saludos estamos en contacto
no le pongas cuidado a todo ese codigo q tenvie mas bien ponle cuidado al .rar ahi sabras lo q quiero hacer y cual es mi problema muchas gracias por todo Meta,,,,
un saludo