5
I am developing software for communication with meter via serial port, and I am able to send the commands via serial, follow 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 \000 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 I have to put 0x01 in the serial output and this will be considered stable for 1 second, after that I get ENQ and can send the command.
Meanwhile:
serial_send(fd, 0x01);
sleep(1);
This is not being recognized by the meter, I think it may be some configuration the door opening or I’m misunderstanding the protocol?
what is this "logical 1" in the documentation ? is actually a byte of data 0x01 ? wouldn’t be an electrical signal of type RTS (request to send) ?
– zentrunix
Managed to develop the protocol ?
– Joao
@Joao yes, I implemented and the system is in operation in various assets.
– fdavid
Important you [Dit] your question reducing the problem to a [mcve]. To better enjoy the site, understand and avoid closures and negativities worth reading the Stack Overflow Survival Guide in English.
– Bacco