|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Senior Member
Iscritto dal: May 2002
Città: Massa Carrara
Messaggi: 589
|
Prog. per testare la seriale:
Ciao,
come da oggetto sto cercando un programmino che serva per testare la porta seriale. Su windows usavo wincomm che era mooolto utile. io ho un mio prog che comunica con un dispositivo collegato alla seriale che gira con windows ora mi servirebbe un prog di test che abbia la possibilita' di mandare "certi" byte a sta seriale. grazie per l'aiuto. |
![]() |
![]() |
![]() |
#2 |
Senior Member
Iscritto dal: Jan 2001
Città: Milano
Messaggi: 5707
|
cat quello_che_vuoi > /dev/ttySx
dove l'ultima x e' il nuemro della seriale (0, 1, ecc....) |
![]() |
![]() |
![]() |
#3 |
Senior Member
Iscritto dal: Apr 2000
Città: Roma
Messaggi: 15625
|
minicom?
__________________
0: or %edi, %ecx; adc %eax, (%edx); popf; je 0b-22; pop %ebx; fadds 0x56(%ecx); lds 0x56(%ebx), %esp; mov %al, %al andeqs pc, r1, #147456; blpl 0xff8dd280; ldrgtb r4, [r6, #-472]; addgt r5, r8, r3, ror #12 |
![]() |
![]() |
![]() |
#4 |
Senior Member
Iscritto dal: May 2002
Città: Massa Carrara
Messaggi: 589
|
ok ma,
cat 0xA0 0x00 0x00 > /dev.... funziona? |
![]() |
![]() |
![]() |
#5 |
Senior Member
Iscritto dal: Apr 2000
Città: Roma
Messaggi: 15625
|
echo -e "\xxx\yyy\zzz...." > /dev/ttyS0
dove xxx, yyy, zzz sono numeri in ottale Ah man ![]() ![]() nb usa setserial per impostare la velocità della porta
__________________
0: or %edi, %ecx; adc %eax, (%edx); popf; je 0b-22; pop %ebx; fadds 0x56(%ecx); lds 0x56(%ebx), %esp; mov %al, %al andeqs pc, r1, #147456; blpl 0xff8dd280; ldrgtb r4, [r6, #-472]; addgt r5, r8, r3, ror #12 |
![]() |
![]() |
![]() |
#6 |
Senior Member
Iscritto dal: May 2002
Città: Massa Carrara
Messaggi: 589
|
minicom mi crea un caos((()))
perche' cerca di comunicare con il modem mentre a me servirebbe solo mandare certi byte e attenderne altri. non esiste qualcosa di piu' semplice? grazie comunque. |
![]() |
![]() |
![]() |
#7 |
Senior Member
Iscritto dal: Apr 2000
Città: Roma
Messaggi: 15625
|
appunto, echo -e
__________________
0: or %edi, %ecx; adc %eax, (%edx); popf; je 0b-22; pop %ebx; fadds 0x56(%ecx); lds 0x56(%ebx), %esp; mov %al, %al andeqs pc, r1, #147456; blpl 0xff8dd280; ldrgtb r4, [r6, #-472]; addgt r5, r8, r3, ror #12 |
![]() |
![]() |
![]() |
#8 |
Senior Member
Iscritto dal: May 2002
Città: Massa Carrara
Messaggi: 589
|
ho settato la seriale,
provo a fare l'echo e forse funziona, ma non posso vedere se c'e' risposta da parte del dispositivo con wincomm ricevevo i byte mandati dal dispositivo verso il pc... cioe' mi servirebbe un prog sia che spedisce, sia che riceve dati. grazie. |
![]() |
![]() |
![]() |
#9 |
Senior Member
Iscritto dal: Apr 2000
Città: Roma
Messaggi: 15625
|
Da un'altra console:
cat /dev/ttyS0 > file il problema è che i dati letti dalla seriale non sono stringhe (presumo), ma numeri binari...quindi devi armarti di santa pazienza e esaminare il file ricevuto con un editor binario, come khexedit. Scriverti un programmino in c di poche righe?
__________________
0: or %edi, %ecx; adc %eax, (%edx); popf; je 0b-22; pop %ebx; fadds 0x56(%ecx); lds 0x56(%ebx), %esp; mov %al, %al andeqs pc, r1, #147456; blpl 0xff8dd280; ldrgtb r4, [r6, #-472]; addgt r5, r8, r3, ror #12 |
![]() |
![]() |
![]() |
#10 |
Senior Member
Iscritto dal: May 2002
Città: Massa Carrara
Messaggi: 589
|
sto propio scrivendo questo diavolo di programmino.
ora ho trovato un pdf che spiega apparentemente molto bene tutte le strutture da inizializzare. il problema e' che non riesco a leggere cio' che mi manda la scheda mia scheda. sicuramente riesco a comunicare perche' ho trovato un'istruzione che mi fa accendere un led e quando la eseguo questo si accende. ti riporto un po' del codice. (e' possibile che sto compiendo una semplice stupidaggine sulla read xche' non conosco bene il c++) #ifdef HAVE_CONFIG_H #include <config.h> #endif #include <iostream.h> #include <stdlib.h> #include <stdio.h>/* standard inp /out definitions*/ #include <string.h>/*string function*/ #include <unistd.h>/*UNIX standard functions definitions*/ #include <fcntl.h> /*File control efinitions*/ #include <errno.h> /*Error number definitions*/ #include <termios.h>/*POSIX terminal control def*/ int ioctl(int fd, int request, ...); int cisei(int fd) { cout << "CISEI----" << endl; char buffer[2];//input buffer char *bufptr; //Current char in buffer int nbytes; //n of byte to read //int tries; //n of tries so far bufptr=buffer; //goto ablett; buffer[0]=0xa0; buffer[1]=0X00; buffer[2]=0X00; nbytes=write(fd, bufptr,3); cout << "*A0 00 00 -" << nbytes << endl; goto esci; buffer[0]=0x71; buffer[1]=0X00; buffer[2]=0X01; nbytes=write(fd, bufptr,3); cout << "*71 00 01 -" << nbytes << endl; ablett: buffer[0]=0x60; buffer[1]=0X00; buffer[2]=0X00; nbytes=write(fd, bufptr,3); cout << "*lettore 60 00 00 -" << nbytes << endl; goto esci; buffer[0]=0x30; buffer[1]=0X00; buffer[2]=0X00; nbytes=write(fd, bufptr,3); cout << "*tastiera 30 00 00 -" << nbytes <<endl; buffer[0]=0x10; buffer[1]=0X00; buffer[2]=0X00; nbytes=write(fd, bufptr,3); cout << "*tastiera 10 00 00 -" << nbytes << endl; //*bufptr='\0'; esci: cout << "buffer dopo" << endl; cout << int(buffer[0]) << endl; cout << int(buffer[1]) << endl; cout << int(buffer[2]) << endl; cout << "CISEI---USCITA" << endl; } /* open port 1 return il descrittore del file in successo o -1 se errore */ int leggiporta(int fd) { cout << "LEGGIPORTA----" << endl; char buffer[255];//input buffer char *bufptr; //Current char in buffer int nbytes; //n of byte to read //int bytespresent;//n° di bytes presenti nel buffer di input //int tries; //n of tries so far cout << "buffer prima" << endl; cout << int(buffer[0]) << endl; cout << int(buffer[1]) << endl; cout << int(buffer[2]) << endl; cout << int(buffer[3]) << endl; bufptr=buffer; //ASPETTA FINO A CHE NEL BUFFER CI SIA ALMENO 3 CARATTERI //nbytes=ioctl(fd , FIONREAD , &bytespresent); nbytes=read(fd, bufptr,3); cout << "nbytes read" << endl; cout << nbytes << endl; //*bufptr='\0'; cout << "buffer dopo" << endl; cout << int(buffer[0]) << endl; cout << int(buffer[1]) << endl; cout << int(buffer[2]) << endl; cout << int(buffer[3]) << endl; cout << "LEGGIPORTA----USCITA" << endl; } int settaporta(int fd) { cout << "SETTAPORTA----" << endl; struct termios options; tcgetattr(fd , &options); options.c_cflag &= ~PARENB; //NO PARITY options.c_cflag &= ~CSTOPB; //NO STOP options.c_cflag &= ~CSIZE; //mask the character size bits // options.c_cflag |= CRTSCTS; //abilita il controllo di flusso hardware options.c_cflag |= CS8; //select 8 data bits cfsetispeed(&options, B9600); cfsetospeed(&options, B9600); options.c_cflag |= (CLOCAL | CREAD); options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); options.c_iflag &= ~(IXON | IXOFF | IXANY); //non usare controllo software di flusso options.c_oflag &= ~OPOST; //chosing raw output options.c_cc[VMIN] = 0; options.c_cc[VTIME] = 2; tcsetattr(fd,TCSANOW,&options); cout << "SETTAPORTA----USCITA" << endl; } int open_port(void) { int fd; fd=open ("/dev/ttyS0",O_RDWR|O_NOCTTY|O_NDELAY); // fd=open ("/dev/ttyS1",O_RDWR|O_NOCTTY); if (fd== -1) { perror("open port: Unable to open /dev/ttyS0 -"); } else fcntl(fd, F_SETFL, 0); //fcntl(fd, F_SETFL, FNDELAY); return (fd); } int main(int argc, char *argv[]) { int z; argc=argc; argv=argv; int fd; int retx; cout << "Hello, World!" << endl; fd = open_port(); cout << "open_port() - " << fd << endl; cout << "fd - " << fd << endl; retx = settaporta(fd); retx = cisei(fd); scanf("%d",&z); // if z==1 retx = leggiporta(fd); close (fd); return EXIT_SUCCESS; } praticamente la read mi restituisce -1 come se non leggesse niente. help me........ |
![]() |
![]() |
![]() |
#11 | |
Senior Member
Iscritto dal: Apr 2000
Città: Roma
Messaggi: 15625
|
Quote:
__________________
0: or %edi, %ecx; adc %eax, (%edx); popf; je 0b-22; pop %ebx; fadds 0x56(%ecx); lds 0x56(%ebx), %esp; mov %al, %al andeqs pc, r1, #147456; blpl 0xff8dd280; ldrgtb r4, [r6, #-472]; addgt r5, r8, r3, ror #12 |
|
![]() |
![]() |
![]() |
#12 |
Senior Member
Iscritto dal: May 2002
Città: Massa Carrara
Messaggi: 589
|
caspita,
in pratica passo alla read un file descriptor sbagliato perche' viene modificato in qualche modo. ma io non faccio niente per modificarlo: se noti fd viene passato alla funzione cisei che scrive sulla seriale a0 00 00 chiedendo alla mia scheda ci sei? la scheda dovrebbe rispondere a0 00 11(ci sono) ora dove sbaglio nella funzione cisei? dal momento che fd viene usato solo per scrivere sulla seiale non dovrebbe essere modificato giusto? da notare che se nella read metto 3 al posto di fd(che sarebbe il n° di file) la read mi funziona e mi restituisce propio a0 00 11. grazie. |
![]() |
![]() |
![]() |
#13 |
Senior Member
Iscritto dal: May 2002
Città: Massa Carrara
Messaggi: 589
|
caspita
ho trovato che l'errore si verifica quando ppasso il parametro alla int leggiporta(int fd); cioe' quando chiamo retx=leggiporta (fd); fd vale 3 ma quando sono dentro la funzione fd vale -1073744072 potrebbe essere un errore del compilatore? ho provato a cambiare fd in fdx all'interno della funzione quindi main.. retx=leggiporta(fd); ... int leggiporta(int fdx); { cout << fdx <<endl; } e fdx non e' 3 bensi -107... come mai? grazie. |
![]() |
![]() |
![]() |
#14 |
Senior Member
Iscritto dal: Apr 2000
Città: Roma
Messaggi: 15625
|
Mi puzza di "buffer overflow"...buon debugging
![]() Comincia col compilare con -Wall, in modo da esaminare tutti i warning del compilatore... (comincia anche a togliere le cose inutili...quella scanf("%d", &z) innanzitutto)
__________________
0: or %edi, %ecx; adc %eax, (%edx); popf; je 0b-22; pop %ebx; fadds 0x56(%ecx); lds 0x56(%ebx), %esp; mov %al, %al andeqs pc, r1, #147456; blpl 0xff8dd280; ldrgtb r4, [r6, #-472]; addgt r5, r8, r3, ror #12 |
![]() |
![]() |
![]() |
#15 |
Senior Member
Iscritto dal: May 2002
Città: Massa Carrara
Messaggi: 589
|
ok il codice fa schifo.....
![]() cosa vuol dire compilare con Wall? io sto usando kdevelop 2.2.1. |
![]() |
![]() |
![]() |
#16 |
Senior Member
Iscritto dal: Jul 2002
Messaggi: 4334
|
Vuol dire passare al gcc l'opzione -Wall, ossia stampa tutti i warning.
Per kdevelop non so, prova a cercare in qualche finestra dove sono le opzioni per il gcc. |
![]() |
![]() |
![]() |
#17 |
Senior Member
Iscritto dal: Apr 2000
Città: Roma
Messaggi: 15625
|
Progetto->opzioni->opzioni del compilatore->flags and warnings->seleziona -Wall e -Werror dall'elenco a sinistra.
Così almeno puoi far sparire i warning del compilatore (te li segnala come errori se li trova).
__________________
0: or %edi, %ecx; adc %eax, (%edx); popf; je 0b-22; pop %ebx; fadds 0x56(%ecx); lds 0x56(%ebx), %esp; mov %al, %al andeqs pc, r1, #147456; blpl 0xff8dd280; ldrgtb r4, [r6, #-472]; addgt r5, r8, r3, ror #12 |
![]() |
![]() |
![]() |
#18 |
Senior Member
Iscritto dal: May 2002
Città: Massa Carrara
Messaggi: 589
|
allora l'opzione -Wall C'era gia e invece non c'era -Werror
ora pero' non mi finisce nemmeno di compilare che si blocca su un errore che prima non considerava ![]() cliccando sul warning, che e' In file included from /usr/include/g++/backward/iostream.h:31, from main.cpp:6: /usr/include/g++/backward/backward_warning.h:32:2: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated. mi apre un file backward-warning.h da quel che si capisce e' quindi il file iostream.h che ho incluso che mi crea problemi,piu' precisamente cio' che include quest'ultimo: #ifndef _CPP_BACKWARD_IOSTREAM_H #define _CPP_BACKWARD_IOSTREAM_H 1 #include "backward_warning.h" #include <iostream> using std::iostream; using std::ostream; using std::istream; using std::ios; using std::streambuf; ......... ma il warning mi consiglia di utilizzare una delle 32 intestazioni situate nella sez xxx del g++(ma cos'e' questa sezione? l'ho cercata come se fosse una directory ma non l'ho trocvata) in piu' il warning mi consiglia di usare un file senza .h perche' piu' recente, ma iostream include gia' un file senza .h. ragazzi grazie mille per l'aiuto, capirete che sono alle prime armi, ma da qualche parte si deve iniziare.. ciao. |
![]() |
![]() |
![]() |
#19 |
Senior Member
Iscritto dal: Apr 2000
Città: Roma
Messaggi: 15625
|
Sì -Werror tratta i warning come errori.
Nota che iostream.h è deprecata; dovresti usare: #include <iostream> using namespace std; Risolta questa rogna, dovresti vedere i "tuoi" warning.
__________________
0: or %edi, %ecx; adc %eax, (%edx); popf; je 0b-22; pop %ebx; fadds 0x56(%ecx); lds 0x56(%ebx), %esp; mov %al, %al andeqs pc, r1, #147456; blpl 0xff8dd280; ldrgtb r4, [r6, #-472]; addgt r5, r8, r3, ror #12 |
![]() |
![]() |
![]() |
#20 |
Senior Member
Iscritto dal: May 2002
Città: Massa Carrara
Messaggi: 589
|
ok ho cambiato iostream.h con iostream
non mi da piu' warning ma non funziona lo staesso. che cosa sta a dire quel using namespaces std? che cosa voul dire deprecato?--obsoleto? grazie |
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 13:39.