linux - guardar - Puerto serial;no puedo leer lo que escribo
exportar datos de arduino a txt (0)
No puedo leer lo que envío al puerto serie, cuando genero datos aleatoriamente, y deseo enviarlo a través de COM1, y leer desde COM2 con dos hilos de tiempo real diferentes, utilicé funciones RTAI.
Digamos, envío ''H'' ''E'' ''L'' ''L'' ''O algunos bytes aleatorios y 0x01; sin embargo, no puedo leer ''H'' ''E'' ''L'' ''L'' ''O'' byte y 0x01. Leo valores diferentes a los que envío a través del puerto serie. cual puede ser la razon? 1-) Estoy usando un cable de módem nulo entre COM1 y COM2 2-) He publicado guiones de escritor y lector secuencialmente. 3-) Transmisión de puerto serie (lado de escritura) da un error para rt_sperr, muy probablemente desbordamiento o error completo de búfer. 4-) Hice una réplica de este proyecto en el espacio de usuario, y encontré un mensaje RECURSO TEMPORAL NO DISPONIBLE, está relacionado con el tamaño del puerto serie, si es así podría sugerirme un lugar para leer acerca de cómo ajustar el tamaño del búfer del puerto serie. ¿Hay alguna acción que me sugieras que tome? Mejor
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/version.h>
#include "rtai.h"
#include "rtai_sched.h"
#include "rtai_sem.h"
#include "rtai_serial.h"
#ifndef _P1003_1B_VISIBLE
#define MCL_CURRENT 0x0001
#define MCL_FUTURE 0x0002
#define _P1003_1B_VISIBLE
#endif
#if ! defined(RT_LOWEST_PRIORITY)
#if defined(RT_SCHED_LOWEST_PRIORITY)
#define RT_LOWEST_PRIORITY RT_SCHED_LOWEST_PRIORITY
#else
#error RT_SCHED_LOWEST_PRIORITY not defined
#endif
#endif
#define TASK_PRIORITY 1
#include <linux/errno.h>
#include <asm/io.h>
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,4,0)
MODULE_LICENSE("GPL");
#endif
#define TICK_PERIOD 10000000
#define STACK_SIZE 1024
#define BAUD 115200
#define NUMBITS 8
#define STOPBITS 1
#define TWOPWR31M1 2147483647
static RT_TASK simulator_task;
static RTIME simulator_period_ns = 31857600;
static RTIME now;
static SEM eben;
static inline long next_rand(long rand)
{
const long a = 16807;
const long m = TWOPWR31M1;
const long q = 127773;
const long r = 2836;
long lo, hi;
hi = rand/q;
lo = rand - hi*q;
rand = a*lo - r*hi;
if (rand <= 0) {
rand += m;
}
return rand;
}
static inline long irandu(unsigned long range)
{
static long seed = 783637;
const long m = TWOPWR31M1;
seed = next_rand(seed);
return rtai_imuldiv(seed, range, m);
}
void generate_rn(int mean, int std, unsigned int *x){
unsigned int a=0, b=0;
unsigned long rand_num=0;
unsigned long rand_max = 100;
int fp, ret;
a=mean-2*std;
b=mean+2*std;
rand_num = irandu(rand_max);
*x = a + ((b-a)*rand_num)/rand_max;
}
void simulasyon(long int arg)
{
unsigned int unit_data=0 ;
unsigned int size = 367;
unsigned char mydata[size];
int min=0, max=0;
int rand_num=0;
int rand_max = 100;
int std=1;
int i;
int ierr;
mydata[0] = ''A'';
mydata[1] = ''S'';
mydata[2] = ''C'';
mydata[3] = ''I'';
mydata[size-1] = 0x01;
while(1){
for(i = 4 ; i < size-1 ; i ++){
generate_rn(i, 1, &unit_data);
mydata[i] = unit_data;
}
//ierr= rt_sem_wait(&eben);
rt_spclear_tx(COM1);
ierr= rt_spwrite_timed(COM1,(void *)mydata, size,
DELAY_FOREVER);
//if(ierr=-1){printk("succes/n");}
rt_task_wait_period();
}
return;
}
int init_module(void)
{
RTIME simulator_period_count;
RTIME timer_period_count;
int retval;
int res;
int mutx;
res=rt_spopen(COM1, BAUD, NUMBITS, STOPBITS,RT_SP_PARITY_NONE,
RT_SP_NO_HAND_SHAKE, RT_SP_FIFO_DISABLE);
if(res) {
printk("Error: rt_spopen/n");
switch(res) {
case -ENODEV:
printk("No device %d/n", res);
break;
case -EINVAL:
printk("Invalid val %d/n", res);
break;
case -EADDRINUSE:
printk("Address in use %d/n", res);
break;
default:
printk("Unknown %d/n", res);
break;
}
do_exit(0); }
//rt_typed_sem_init(&eben, 0, BIN_SEM);
rt_spclear_tx(COM1);
rt_set_periodic_mode();
simulator_period_count = nano2count(simulator_period_ns);
timer_period_count = start_rt_timer(simulator_period_count);
retval = rt_task_init(&simulator_task,
simulasyon,
0,
1024,
RT_LOWEST_PRIORITY,
0,
0);
if (0 != retval) {
if (-EINVAL == retval) {
printk("periodic task: task structure already in use/n");
} else if (-ENOMEM == retval) {
printk("periodic task: can''t allocate stack/n");
} else {
printk("periodic task: error initializing task structure/n");
}
return retval;
}
retval = rt_task_make_periodic(&simulator_task,
rt_get_time() + simulator_period_count,
simulator_period_count);
if (0 != retval) {
if (-EINVAL == retval) {
printk("periodic task: task structure is invalid/n");
} else {
printk("periodic task: error starting task/n");
}
return retval;
}
return 0;
}
void cleanup_module(void)
{
int retval;
retval = rt_task_delete(&simulator_task);
if (0 != retval) {
if (-EINVAL == retval) {
printk("periodic task: task structure is invalid/n");
} else {
printk("periodic task: error stopping task/n");
}
}
//rt_stop_timer();
//rt_busy_sleep(10000000);
rt_spclose(COM1);
//rt_sem_delete(&eben);
return;
}
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/version.h>
#include "rtai.h"
#include "rtai_serial.h"
#include "rtai_sched.h"
#include "rtai_fifos.h"
#include <rtai_sem.h>
#define BAUD 115200
#define NUMBITS 8
#define STOPBITS 1
#define TASK_PRIORITY 1
#define TICK_PERIOD 10000000
#define STACK_SIZE 1024
#if ! defined(RT_LOWEST_PRIORITY)
#if defined(RT_SCHED_LOWEST_PRIORITY)
#define RT_LOWEST_PRIORITY RT_SCHED_LOWEST_PRIORITY
#else
#error RT_SCHED_LOWEST_PRIORITY not defined
#endif
#endif
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,4,0)
MODULE_LICENSE("GPL");
#endif
static RTIME tick_period_ns = 31857600;
static SEM eben;
struct rt_task_struct rt_task1;
static void task_read (long int arg)
{
int i=0;
unsigned char cha[367];
unsigned char mydata[362];
unsigned int max_data_len=367;
unsigned int max_mydata_len=362;
int ierr;
while(1){
rt_spclear_rx(COM2);
//ierr= rt_sem_wait(&eben);
rt_spread_timed(COM2, (char *) cha , max_data_len, DELAY_FOREVER);
for (i=0;i<367;i++){
//ierr=rt_sem_signal(&eben);
//printk("ch[%d], %d/n", i, ch[i]);
}
if (cha[0]==''A'' && cha[1]==''S'' && cha[2]==''C'' && cha[3]==''I'' && cha[size]==0x01 )
{
for (i=0;i<362;i++)
{
mydata[i]=cha[i+4];
rtf_put(0, (char *)mydata, max_mydata_len); //PUTTING DATA IN FIFO
}
rt_task_wait_period();
}
return;
}
int init_module(void)
{
int res;
int retval;
RTIME tick_period_get;
RTIME tick_period_count;
res=rt_spopen(COM2, BAUD, NUMBITS, STOPBITS, RT_SP_PARITY_ODD, RT_SP_NO_HAND_SHAKE, RT_SP_FIFO_DISABLE);
if(res) {
printk("Error: rt_spopen/n");
switch(res) {
case -ENODEV:
printk("No device %d/n", res);
break;
case -EINVAL:
printk("Invalid val %d/n", res);
break;
case -EADDRINUSE:
printk("Address in use %d/n", res);
break;
default:
printk("Unknown %d/n", res);
break;
}
do_exit(0);
}
rt_spclear_rx(COM2);
retval = rtf_create(0,4096);
if (retval) {
printk("could not create RT-FIFO /dev/rtf0/n");
return retval;
}
rtf_reset(0);
rt_set_periodic_mode();
tick_period_get = nano2count(tick_period_ns);
tick_period_count = start_rt_timer(tick_period_get);
rt_typed_sem_init(&eben, 0, BIN_SEM);
retval=rt_task_init(&rt_task1, task_read, 0, 1024, RT_LOWEST_PRIORITY,0,0);
if (0 != retval) {
if (-EINVAL == retval) {
/* task structure is already in use */
printk("periodic task: task structure already in use/n");
} else if (-ENOMEM == retval) {
/* stack could not be allocated */
printk("periodic task: can''t allocate stack/n");
} else {
/* unknown error */
printk("periodic task: error initializing task structure/n");
}
return retval;
}
retval = rt_task_make_periodic(&rt_task1, rt_get_time() + tick_period_get, tick_period_get);
if (0 != retval) {
if (-EINVAL == retval) {
/* task structure is already in use */
printk("periodic task: task structure is invalid/n");
} else {
printk("periodic task: error starting task/n");
}
return retval;
}
return 0; }
void cleanup_module(void)
{
//rt_sem_delete(&eben);
stop_rt_timer();
rtf_destroy(0);
rt_task_delete(&rt_task1);
rt_spclose(COM2);
return;