Esta presentación que continuación se da, ¿es como usar Python en comunicación serial, poco a poco empezare a actualizar esta información conforme valla realizando las practicas, hasta llegar hacer un proyecto tal como se puede ver en la imagen.
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.
phyton es ideal para programar con Interfaz grafica??
hoy fui a la libreria y revise los libros sobre phyton... y mas que todo vi solo codigo...
bueno es de esperarse..no?
nunca he tocado VB
lo unico que se... y he ehco programas comunicacondo PICs en Labview(lo unico malo es que es licenciado)
/*
* File: MAIN.c
* Author: george
*
* Created on 4 de agosto de 2013, 07:06 PM
*/
#include<htc.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<plib/usart.h>
#include<plib/adc.h>
/////////////////////////////////////////////////////////////
//Configuracion para trabajar Con oscilador interno de 8Mhz
#pragma config OSCS = OFF, OSC = HSPLL
#pragma config BOR = OFF, BORV = 42, PWRT = ON
#pragma config WDTPS = 128, WDT = ON
#pragma config DEBUG = OFF, LVP = OFF, STVR = OFF
#pragma config CP0 = OFF, CP1 = OFF, CP2 = OFF, CP3 = OFF
#pragma config CPD = OFF, CPB = OFF
#pragma config WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF
#pragma config WRTB = OFF, WRTC = OFF, WRTD = OFF
#pragma config EBTR0 = OFF, EBTR1= OFF, EBTR2= OFF, EBTR3 = OFF
#pragma config EBTRB = OFF
//////////////////////////////
//Frecuencia FOSC 4Mhz x 4 PLL = 16 Mhz/4 = 4Mhz
//////////////////////////////
#define _XTAL_FREQ 4000000
struct{
unsigned flag_rx:1;
unsigned dumy:7;
}flags={0};
char data[25],i;
const char strings[6][20]={">SETOUT0<\r",
">SETOUT1<\r",
">SETOUT2<\r",
">CLEAROUT0<\r",
">CLEAROUT1<\r",
">CLEAROUT2<\r"};
#include "fadc.h"
#include "expander_inputs.h"
void clear_string(){
for(char index=0;index<=sizeof(data);index++){
data[index]=0;
}
}
void get_string_rx(char *s){
do{
while(!DataRdyUSART());
*s=getcUSART();
}while(*s++!='\r');
}
void interrupts_enables(void){
INTCONbits.GIE=1;
INTCONbits.PEIE=1;
}
static void interrupt isr(void){
if(DataRdyUSART()){
flags.flag_rx=1;
get_string_rx(&data);
}
}
void delay(unsigned int t){
while(--t){__delay_ms(1);}
}
void putch(char c){
/*Empty buffer?
*/
while(!TXSTAbits.TRMT) continue;
//load data into register to send
TXREG=c;
}
void periphericals_configuration(void){
TRISC=0x80;
TRISA=0x3F;
//------------------------------------------------------------------
// Configuracion del USART
//------------------------------------------------------------------
OpenUSART(USART_TX_INT_OFF &//Interrupcion por Transmision apagado
USART_RX_INT_ON &//Interrupcion por Recepcion Apagado
USART_ASYNCH_MODE &//Modo Asincronico
USART_EIGHT_BIT &//8-bit de transmision
USART_CONT_RX &//Recepcion Continua
USART_BRGH_HIGH, //Alta velocidad de baudios
51); //para alta Velocidad:
//FOSC (16 x (spbrg + 1))
//spbrg=(FOS/baud*16)-1
//Para baja Velocidad:
//FOSC (64 x (spbrg + 1))
/*---------------------Fin de Conf. USART----------------------------*/
//////////////////////////////////////////////////////////////////////
// Configuracion de ADC ///
//////////////////////////////////////////////////////////////////////
ADCON0=0b11000001;
ADCON1=0b11000000;
/*---------------------Fin de Conf. ADC------------------------------*/
}
void main(void){
periphericals_configuration();
expander_init();
interrupts_enables();
while(1){
if(flags.flag_rx){
flags.flag_rx=0;
printf("%s\r",data);
if(strcmp(data,&strings[i])==0){
if(i==0) PORTCbits.RC0=1;
if(i==1) PORTCbits.RC1=1;
if(i==2) PORTCbits.RC2=1;
break;
}
}
for(unsigned char i=3;i<6;i++){
if(strcmp(data,&strings[i])==0){
if(i==3) PORTCbits.RC0=0;
if(i==4) PORTCbits.RC1=0;
if(i==5) PORTCbits.RC2=0;
break;
}
}
clear_string();
}
//for(unsigned char channel=0;channel<5;channel++){
// printf("ADC[%i]=%i\r\n",channel,read_ADC(channel));
// delay(500);
//}
//printf("EXPANDER_VALUE= %u\r\n",get_signal());
CLRWDT();
}
}
'''
Created on 28/07/2013
@author: george
'''
import queue
import serial_thread
import input_process
if __name__ == "__main__":
serial_configuration={'COM':'COM1',
'BAUD':19200}
var=(serial_configuration.get('COM'),serial_configuration.get('BAUD'))
myqueue=queue.Queue()
input_pro=input_process.input_process(myqueue)
input_pro.start()
serial_process=serial_thread.serial_rec(var,myqueue)
serial_process.open_port()
serial_process.start()
myqueue.join()
'''
Created on 28/07/2013
@author: george
'''
#ncluimos un thread para generar un pedido continuo de la pila
import threading
import serial
#Iniclizamos la clase para tener listo el puerto,baudios y la pila
class serial_rec(threading.Thread):
def __init__(self,com,queue):
self.port=com[0]
self.baud=com[1]
self.queue_process=queue
self.isrunning=1
threading.Thread.__init__(self)
#Funcion que conecta al puerto asignado y a la velocidad requerido
def open_port(self):
self._s=serial.Serial(self.port,self.baud)
return self._s
#Funcion que mantiene Corriendo el proceso de peticion de la pila
#para despues enviarlo al puerto
def run(self):
maps=['>SETOUT0<','>SETOUT1<','>SETOUT2<','>CLEAROUT0<','>CLEAROUT1<','>CLEAROUT2<']
while(self.isrunning):
data=self.queue_process.get()
if data in maps:
self._s.write(bytes(str(data+'\r'),encoding='ascii'))
else:
print('%s Doesnt Exists command'%data)
#Detiene el proceso
def stop(self):
self.isrunning=0
'''
Created on 28/07/2013
@author: george
'''
#Creamos un thread para mantener el pedido de informacion.
import threading
#Clase para inicializar la pila y el thread.
class input_process(threading.Thread):
def __init__(self,queue):
self.queue_process=queue
self.isrunning=1
threading.Thread.__init__(self)
#Funcion para procesar para guardar en la pila los datos
#a mostrar.
def run(self):
while (self.isrunning):
ch=''
print('>SETOUT0< OR >CLEAROUT0<')
print('>SETOUT1< OR >CLEAROUT1<')
print('>SETOUT2< OR >CLEAROUT2<')
ch=input('Which one? ')
self.queue_process.put(ch)
#Detiene la Funcion run()
def stop(self):
self.isrunning=0