mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-09-20 00:55:58 -04:00
60 lines
1.2 KiB
C
60 lines
1.2 KiB
C
|
#pragma once
|
||
|
//
|
||
|
// FILE: RS485.h
|
||
|
// AUTHOR: Rob Tillaart
|
||
|
// DATE: 30-okt-2017
|
||
|
// VERSION: 0.2.0
|
||
|
// PURPOSE: Arduino library for RS485 modules
|
||
|
// URL: https://github.com/RobTillaart/RS485
|
||
|
|
||
|
|
||
|
#include "Arduino.h"
|
||
|
#include "ASCII_CONTROL.h"
|
||
|
|
||
|
#define RS485_LIB_VERSION "0.2.0"
|
||
|
|
||
|
|
||
|
class RS485 : public Stream
|
||
|
{
|
||
|
public:
|
||
|
RS485(Stream * stream, uint8_t sendPin, uint8_t deviceID = 0);
|
||
|
|
||
|
// baudRate must match Serial baudRate
|
||
|
// micros are needed before RS485 stream may be reset
|
||
|
// to (default) receiving mode.
|
||
|
void setMicrosPerByte(uint32_t baudRate);
|
||
|
uint32_t getMicrosPerByte() { return _microsPerByte; };
|
||
|
|
||
|
uint8_t getDeviceID() { return _deviceID; };
|
||
|
|
||
|
|
||
|
// Stream interface
|
||
|
int available();
|
||
|
int read();
|
||
|
int peek();
|
||
|
void flush();
|
||
|
size_t write(uint8_t c);
|
||
|
size_t write(uint8_t * array, uint8_t length);
|
||
|
|
||
|
|
||
|
// TODO TEST 0.3.0
|
||
|
// void send(uint8_t deviceID, uint8_t msg[], uint8_t len);
|
||
|
// bool receive(uint8_t &deviceID, uint8_t msg[], uint8_t &len);
|
||
|
|
||
|
private:
|
||
|
Stream * _stream;
|
||
|
uint8_t _sendPin = 0;
|
||
|
uint8_t _deviceID = 0;
|
||
|
uint16_t _microsPerByte = 1000;
|
||
|
|
||
|
|
||
|
|
||
|
// TODO TEST
|
||
|
// uint8_t _bidx = 0;
|
||
|
// uint8_t _buffer[50]; // internal receive buffer
|
||
|
};
|
||
|
|
||
|
|
||
|
// -- END OF FILE --
|
||
|
|