I can send correctly, but I can't read.

Can you give me any code, ideas, and links.

Thanks

Recommended Answers

All 2 Replies

no, you need to give US code... as in, the code you're trying to use, so we can see why it's not working.

but since you say it's transmitting properly, the first thing I would do is verify the hardware is connected correctly and is working as it should. put an o'scope or serial analyzer on the RX pin to make certain you're actually receiving anything before indicting the program.

This is the code I'm using:

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <poll.h>
#include <atc_spxs.h>
#include <errno.h>

int fd_biu;

void abre_biu()
{
atc_spxs_config_t sync_config;
sync_config.protocol = ATC_SDLC;
sync_config.baud = ATC_B9600;
sync_config.transmit_clock_source = ATC_CLK_INTERNAL;
sync_config.transmit_clock_mode = ATC_CONTINUOUS;

fd_biu = open("/dev/sp3s", O_RDWR | O_NONBLOCK);
if ( fd_biu < 0 )
        {
           printf("Can't open /dev/sp3s");
exit( EXIT_FAILURE ); // SHOULD NEVER GET HERE!
}

if ( ioctl(fd_biu,0,&sync_config) < 0 )
{
            printf("Can't set /dev/sp3s port settings to SDLC at 9600" );
exit( EXIT_FAILURE ); // SHOULD NEVER GET HERE!
      }

}



void write_outputs_and_read_inputs(unsigned char *output_buffer, unsigned char *input_buffer)

{
unsigned char pckt[8];

int len, i;

pckt[0] = 2;      // biu 3
pckt[1] = 0x83;   // control byte is always 83
pckt[2] = 12;     // command frame byte
pckt[4] = 0x00;
pckt[5] = 0xFF;
pckt[6] = 0xFF;
pckt[7] = 0x00;

write(fd_biu, pckt, 8);

usleep(5000);
len = read( fd_biu, &pckt, 8);
//len = read(fd, &buf, count);
    
if (len == -1)
    printf("read() failure, errno = %d\n", errno);

for ( i = 0; i < len; i++ )
{
printf("resp 3 pck[%d] = %02x\n", i, pckt[i]);
}

//if ( len < 0 ) printf("Error reading from BIU 3\n");

pckt[0] = 3;// biu 4
pckt[1] = 0x83;// control byte is always 83
pckt[2] = 13;     // command frame byte
pckt[4] = 0x00;
pckt[5] = 0xFF;
pckt[6] = 0xFF;
pckt[7] = 0x00;

write(fd_biu, pckt, 8);
usleep(5000);
len = read( fd_biu, pckt, 8);

for ( i = 0; i < len; i++ )
{
printf("resp 4 pck[%d] = %02x\n", i, pckt[i]);
}
  
//if ( len < 0 ) printf("Error reading from BIU 4\n");
}



void latch_biu_outputs()

{
unsigned char pckt[4];
pckt[0]    = 0xFF;
pckt[1]    = 0x83;                      // control field (always 0x83)
pckt[2]    = 18;                        // command frame number
 
write(fd_biu, pckt, 3);	              // no response, don't need to wait
}



/*
OUTPUT:

.
.
.
read() failure, errno = 16
read() failure, errno = 16
read() failure, errno = 16
read() failure, errno = 16
read() failure, errno = 16
.
.
.

*/
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.