Follow along with the video below to see how to install our site as a web app on your home screen.
Nota: This feature currently requires accessing the site using the built-in Safari browser.
Hola META Haber si puedo explicarme bien de lo que necesito se trata del interfaz que tiene 4
pulsadore t,b,a,l ese lo hice y me funciona bien pero el programa del pic no es igual el prog es el
2 que puse.Si te fijas en el prog veras que tiene 4 pulsadores para que se pueda acionar desde
el pic y desde el pc por eso es muy ynportante que cada pulsador tenga una lucesita encima
a continuacion paso a esplicate los datos que tienen que enviar cada cosa yo lo escriba como
sea ten presente que todo se tramsmite ascii datos que tiene que manda el interfaz.
1º pulsador 000A 1ª lucesita recibira 000A y debe encenderse con 000a apagarse
2º pulsador 000B 2ª lucesita recibira 000A y debe encenderse con 000b apagarse
3ª pulsador 000C 3ª lucesita recibira 000C y debe encenderse con 000b apagarse
4º pulsador 000D 4ª lucesita recibira 000D y debe encenderse con 000d apagarse
[COLOR=Blue]using[/COLOR] System;
[COLOR=Blue]using[/COLOR] System.Collections.Generic;
[COLOR=Blue]using[/COLOR] System.ComponentModel;
[COLOR=Blue]using[/COLOR] System.Data;
[COLOR=Blue]using[/COLOR] System.Drawing;
[COLOR=Blue]using[/COLOR] System.Linq;
[COLOR=Blue]using[/COLOR] System.Text;
[COLOR=Blue]using[/COLOR] System.Windows.Forms;
[COLOR=Blue]using[/COLOR] System.IO.Ports;
[COLOR=Blue]namespace[/COLOR] Puerto_Serie
{
[COLOR=Blue]public[/COLOR] [COLOR=Blue]partial[/COLOR] [COLOR=Blue]class[/COLOR] Form1 : Form
{
[COLOR=Green]// Utilizaremos un string como buffer de recepcion[/COLOR]
[COLOR=Blue]string[/COLOR] Recibidos;
[COLOR=Blue]public[/COLOR] Form1()
{
InitializeComponent();
[COLOR=Green]// Abrir puerto mientra se ejecute la aplicación[/COLOR]
[COLOR=Blue]if[/COLOR] (!serialPort1.IsOpen)
{
[COLOR=Blue]try[/COLOR]
{
serialPort1.Open();
}
[COLOR=Blue]catch[/COLOR] (System.Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
[COLOR=Green]// Ejecutar la funcion Recepcion por disparo del Evento 'DataReived'[/COLOR]
serialPort1.DataReceived += [COLOR=Blue]new[/COLOR]
System.IO.Ports.SerialDataReceivedEventHandler(Recepcion);
}
[COLOR=Green]// Al recibir los datos[/COLOR]
[COLOR=Blue]private[/COLOR] [COLOR=Blue]void[/COLOR] Recepcion([COLOR=Blue]object[/COLOR] sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
[COLOR=Green]// Acumular los carácteres recibidos a nuestro 'buffer' (string)[/COLOR]
Recibidos += serialPort1.ReadExisting();
[COLOR=Green]// Invocar o llamar al proceso de tramas[/COLOR]
[COLOR=Blue]this[/COLOR].Invoke([COLOR=Blue]new[/COLOR] EventHandler(Actualizar));
}
[COLOR=Green]// Procesar los datos recibidos en el buffer y extraer tramas completas[/COLOR]
[COLOR=Blue]private[/COLOR] [COLOR=Blue]void[/COLOR] Actualizar([COLOR=Blue]object[/COLOR] s, EventArgs e)
{
[COLOR=Green]// Asignar el valor de la trama al textBox[/COLOR]
richTextBox1.Text = Recibidos;
}
}
}
[COLOR=blue]private[/COLOR] [COLOR=blue]void[/COLOR] textBox1_TextChanged([COLOR=blue]object[/COLOR] sender, [COLOR=#2b91af]EventArgs[/COLOR] e)
{
[COLOR=blue]char[/COLOR][] charNum;
[COLOR=blue]if[/COLOR] (textBox1.Text.Length > 0)
{
[COLOR=blue]string[/COLOR] Str = textBox1.Text;
charNum = Str.ToCharArray();
[COLOR=blue]switch[/COLOR] (([COLOR=blue]int[/COLOR])charNum[0])
{
[COLOR=blue]case[/COLOR] 65: [COLOR=green]// 'A'[/COLOR]
[COLOR=blue]case[/COLOR] 66: [COLOR=green]// 'B'[/COLOR]
[COLOR=blue]case[/COLOR] 67: [COLOR=green]// 'C'[/COLOR]
[COLOR=blue]case[/COLOR] 68: [COLOR=green]// 'D'[/COLOR]
[COLOR=blue]case[/COLOR] 69: [COLOR=green]// 'E'[/COLOR]
[COLOR=blue]case[/COLOR] 70: [COLOR=green]// 'F'[/COLOR]
[COLOR=#2b91af]MessageBox[/COLOR].Show([COLOR=#a31515]"Mayuscula"[/COLOR] + charNum[0]);
[COLOR=blue]break[/COLOR];
[COLOR=blue]case[/COLOR] 97: [COLOR=green]// 'a'[/COLOR]
[COLOR=blue]case[/COLOR] 98: [COLOR=green]// 'b'[/COLOR]
[COLOR=blue]case[/COLOR] 99: [COLOR=green]// 'c'[/COLOR]
[COLOR=blue]case[/COLOR] 100: [COLOR=green]// 'd'[/COLOR]
[COLOR=blue]case[/COLOR] 101: [COLOR=green]// 'e'[/COLOR]
[COLOR=blue]case[/COLOR] 102: [COLOR=green]// 'f'[/COLOR]
[COLOR=#2b91af]MessageBox[/COLOR].Show([COLOR=#a31515]"Minuscula"[/COLOR] + charNum[0]);
[COLOR=blue]break[/COLOR];
}
}
}
Hola meta mira con detalle lo queexplico a continuacion yo te e puesto un pulsador y una luz porque sabiendo como es el codigo de uno se sabe el de todos 1ºPULSADOR ENVIA 000A 1 LUZ RECIBE 000A PARA ENCENDERSE,RECIBE 000a PARA APAGARSE
2ºPULSADOR ENVIA 000B 2º LUZ RECIBE 000B PARA ENCENDERSE,RECIBE 000b PARA APAGARSE
3º PULSADOR ENVIA 000C 3 LUZ RECIBE 000C PARA ENCENDERSE,RECIBE 000c PARA APAGARSE
4º PULSADOR ENVIA 000D 4 LUZ RECIBE 000D PARA ENCENDERSE,RECIBE 000d PARA APAGARSE
5 PULSADOR ENVIA 001A 5 LUZ RECIBE 001A PARA ENCENDERSE ,RECIBE 001a PARA APAGARSE
6 PULSADOR ENVIA 001B 6 LUZ RECIBE 001B PARA ENCENDERSE RECIBE 001b PARA APAGARSE
Ten presente que la lucesita tiene que cambiar con el mensaje que reciba del pic
Esto lo e pensado asi por dos motivos 1 si hay un fallo en la comunicacion la luz no te engaña
2º todos los pic tienen el mismo programa solo hay que cambiar la combinacion de porta,0,1,2
para que los mensajes cada uno se haloje en su sitio por eje pic 1 000+ A,B,C,D PIC 2 001+A,B,C,D
3 PIC 010+,A,B,C,D 4 PIC 110+ A,B,C,D 5 PIC 001+ A,B,C,D, 6 PIC 101+A,B,C,D, 7 PIC 110+A,B,C,D
8 PIC 111+A,B,C,D
Esto es asi porque suponiendo que tu tienes una instalacion con x pic y se estropea uno lo puedes
sustituir por otro porque todos son iguales solo hay que ponerle la direccion adecuada con los
interruptores de porta,0,1,2
hata ahora pepe
Hola meta si anbos pulsadores hacen lo siguiente:e si pulsas el pulsador del interfaz pc .siempre mandara
000A cuando sicha señal llege al pic y si este esta apagado,se encendera y mandara al pc 000A si por el
contrario el pic esta encendido,se apagara y mandara al pc 000a
¿Con el botón desde la Interfaz del PC al PIC siempre envía 000A?
el pulsador del pic hace lo mismo,hay que aprobecha que cuando el pc reciba 000A encienda la luz del pulsador
y cuando el pc reciba 000a la luz del pulsador del pc se apague. depueste mado los esquemas hasta
ahora pepe
Mejor encárgate de la programación del PIC.
Claro que hay un lio porque no lo especifico bien la luz del PC recibe 000A para encenderse y 000a para apa-
garse sin enbargo el pic siempre recibe 000A y el se encarga de hacer la inversion
private void button_000A_Click(object sender, EventArgs e)
{
byte[] mBuffer = new byte[4];
mBuffer[0] = 0x0; // Es el número 0.
mBuffer[1] = 0x0;
mBuffer[2] = 0x0;
mBuffer[3] = 0x41; // Es la letra A.
serialPort1.Write(mBuffer, 0, mBuffer.Length);
// También puedes enviarlo así:
// byte[] mBuffer = Encoding.ASCII.GetBytes("000A");
// serialPort1.Write(mBuffer, 0, mBuffer.Length);
}
Private Sub button_000A_Click(sender As Object, e As EventArgs)
Dim mBuffer As Byte() = New Byte(3) {}
mBuffer(0) = &H0 ' Es el número 0.
mBuffer(1) = &H0
mBuffer(2) = &H0
mBuffer(3) = &H41 ' Es la letra A.
serialPort1.Write(mBuffer, 0, mBuffer.Length)
' También puedes enviarlo así:
' byte[] mBuffer = Encoding.ASCII.GetBytes("000A");
' serialPort1.Write(mBuffer, 0, mBuffer.Length);
End Sub