-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserial.h
More file actions
37 lines (28 loc) · 794 Bytes
/
serial.h
File metadata and controls
37 lines (28 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#ifndef SERIAL_H
#define SERIAL_H
#include <termios.h>
// Paridades
#define NOPARITY 0
#define PARITY_EVEN 1
#define PARITY_ODD 2
// Stop Bits
#define ONESTOPBIT 1
#define TWOSTOPBITS 2
// Timeout padrão (ms)
#define TIMEOUT_INTERBYTE_MS 4
#define TIMEOUT_TOTAL_MS 10000 //10seg
// Estrutura da porta
typedef struct {
int fd;
struct termios tty;
} SerialPort;
// Variável global
extern SerialPort portaSerial;
// Assinaturas das funções
int serialOpen(const char *portname, int baudrate, int databits, int parity, int stopbits);
int serialWrite(const char *data, int length);
int serialClose(void);
void exibeDados(const char *buffer, int length);
char *lerResposta(void);
int modbusWrite(const char *req, int total);
#endif