Protocol NBR 14522

2

I am developing software for communication with meter via serial port, and I am able to send the commands via serial, it follows the codes:

int serial_open(const char *device, int baud)
{   
    struct termios tio;
    int fd = open(device, O_RDWR | O_NOCTTY | O_NONBLOCK);

    memset (&tio, 0, sizeof tio);

    /*
     * Note that 'baud' is not an actual baud rate number;
     * it's one of the constants (e. g., 'B9600') in <termios.h>
     */
    tcgetattr(fd, &tio);

    cfsetospeed(&tio, baud);
    cfsetispeed(&tio, baud);

    tio.c_cflag = (tio.c_cflag & ~CSIZE) | CS8;     // 8-bit chars
    // disable IGNBRK for mismatched speed tests; otherwise receive break
    // as 
serial_send(fd, 0x01);
sleep(1);
0 chars tio.c_iflag &= ~IGNBRK; // disable break processing tio.c_lflag = 0; // no signaling chars, no echo, // no canonical processing tio.c_oflag = 0; // no remapping, no delays tio.c_cc[VMIN] = 0; // read doesn't block tio.c_cc[VTIME] = 5; // 0.5 seconds read timeout tio.c_iflag &= ~(IXON | IXOFF | IXANY); // shut off xon/xoff ctrl tio.c_cflag |= (CLOCAL | CREAD);// ignore modem controls, // enable reading tio.c_cflag &= ~(PARENB | PARODD); // shut off parity tio.c_cflag |= 0; //parity tio.c_cflag &= ~CSTOPB; tio.c_cflag &= ~CRTSCTS; tcsetattr (fd, TCSANOW, &tio); sleep(1); //Waiting for set serial port return fd; } uint8_t serial_recv(int fd) { uint8_t byte; read(fd, &byte, sizeof byte); usleep(1000); return byte; } void serial_send(int fd, uint8_t byte) { write(fd, &byte, sizeof byte); usleep(1000); //Waiting write byte }

However the communication protocol says that I have to put 0x01 on the serial output and this will be considered stable for 1 second, after that I get ENQ and I can send the command.

In the meantime:

int serial_open(const char *device, int baud)
{   
    struct termios tio;
    int fd = open(device, O_RDWR | O_NOCTTY | O_NONBLOCK);

    memset (&tio, 0, sizeof tio);

    /*
     * Note that 'baud' is not an actual baud rate number;
     * it's one of the constants (e. g., 'B9600') in <termios.h>
     */
    tcgetattr(fd, &tio);

    cfsetospeed(&tio, baud);
    cfsetispeed(&tio, baud);

    tio.c_cflag = (tio.c_cflag & ~CSIZE) | CS8;     // 8-bit chars
    // disable IGNBRK for mismatched speed tests; otherwise receive break
    // as 
serial_send(fd, 0x01);
sleep(1);
0 chars tio.c_iflag &= ~IGNBRK; // disable break processing tio.c_lflag = 0; // no signaling chars, no echo, // no canonical processing tio.c_oflag = 0; // no remapping, no delays tio.c_cc[VMIN] = 0; // read doesn't block tio.c_cc[VTIME] = 5; // 0.5 seconds read timeout tio.c_iflag &= ~(IXON | IXOFF | IXANY); // shut off xon/xoff ctrl tio.c_cflag |= (CLOCAL | CREAD);// ignore modem controls, // enable reading tio.c_cflag &= ~(PARENB | PARODD); // shut off parity tio.c_cflag |= 0; //parity tio.c_cflag &= ~CSTOPB; tio.c_cflag &= ~CRTSCTS; tcsetattr (fd, TCSANOW, &tio); sleep(1); //Waiting for set serial port return fd; } uint8_t serial_recv(int fd) { uint8_t byte; read(fd, &byte, sizeof byte); usleep(1000); return byte; } void serial_send(int fd, uint8_t byte) { write(fd, &byte, sizeof byte); usleep(1000); //Waiting write byte }

This is not being recognized by the meter, I think it may be some configuration to open the port or am I misunderstanding the protocol?

Serial 9600 8N1 Setup

    
asked by anonymous 22.10.2018 / 13:05

0 answers