I have a simple program written in C that uses Termos to send the original string to the Raspberry PUART and Attempts to read and read Production response Rx and Tx pins on Raspberry P are connected with a jumper so that whatever is sent is to be received immediately.
Despite the output of the program that it has been successfully sent and received 5 characters for the selected string ('hello'), in the attempt to print the content of buffer, only one or two trash characters Does.
Program:
#include & lt; Stdio.h & gt; # Include & lt; Stdlib.h & gt; #include & lt; String.h & gt; # Include & lt; Unistd.h & gt; # Include & lt; Fcntl.h & gt; # Include & lt; Termios.h & gt; Int main (int argc, char * argv []) {struct termios serial; Char * str = "Hello"; Four buffers [10]; If (argc == 1) {printf ("Usage:% s [device] \ n \ n", argv [0]); Return -1; } Printf ("Open% s \ n", argv [1]); Int fd = open (argv [1], o_rrdwr | o_ctiti | o_dealele); If (FD == -1) {mirror (argv [1]); Return -1; } If (TCGTat (FD, and Serial) & lt; 0) {Zira ("Getting Configuration"); Return -1; } // set up serial configuration serial.c_iflag = 0; Serial.c_oflag = 0; Serial.c_lflag = 0; Serial.c_cflag = 0; Serial.c_cc [VMIN] = 0; Serial.c_cc [VTIME] = 0; Serial.c_cflag = b1125200 CS8 | CREAD; TCSetter (FD, TCSONO, and Serial); // Attempt to send and receive // printf // printf ("sending:% s \ n", str); Int wcount = write (FD, & str, strlen (str)); If (wcount & lt; 0) {mirror ("Write"); Return -1; } Other {printf ("% d characters sent \ n", wcount); } Int rcount = read (fd, and buffer, size (buffer)); If (receipt Output:
Opening / dev / ttyAMA0 Sending: Hello sent 5 characters received 5 characters: [trash] < / Code> I do not see any major problems with the code, but I could be wrong. I can successfully send and receive characters using a connecting system connected to the same setting, so it can not really be a hardware problem although I have not tried to put it in the cyst, with this program less than 115200 baud Nothing will be found as a result of trying to connect with.
Where am I going?
int wcount = write (fd, and str, strlen (str)); Int Record = Read (FD, and buffer, size (buffer)); In these lines, buffers / str are already indicated. You are passing an indicator near the indicator.
lines should be:
int wcount = write (fd, str, strlen (str)); Int rcount = Read (FD, buffer, size (buffer));
No comments:
Post a Comment