/*
 * Copyright (c) 2007-2009 by Oleg Trifonov <otrifonow@gmail.com>
 *
 * This file is free software; you can redistribute it and/or modify
 * it under the terms of either the GNU General Public License version 2
 * or the GNU Lesser General Public License version 2.1, both as
 * published by the Free Software Foundation.
 */

#ifndef _TR_RS232_H_
#define _TR_RS232_H_

#include "trTypes.h"
#include "trStream.h"
#include "trException.h"

#ifdef WIN32
#include <windows.h>
#endif


class TrRS232 : public TrStream {
public:
	TrRS232(Byte number, UInt32 baud, bool parity = false, Byte stopBits = 0);
	TrRS232() {};
	~TrRS232();

	bool Open(Byte number, UInt32 baud, bool parity = false, Byte stopBits = 0);

	virtual bool Seek(Int64 pos) { throw new InvalidOperationException(); };
	virtual Int64 GetPos() { throw new InvalidOperationException(); };
	virtual Int64 GetSize() { throw new InvalidOperationException(); };
	virtual bool Eof() { return false; };

	virtual UInt32 Read(void *buf, UInt32 size);

	virtual UInt32 Write(void *buf, UInt32 size);

	virtual bool Close();

	// установка/сброс линии DTR
	bool SetDTR(bool val);
	
	// установка/сброс линии RTS
	bool SetRTS(bool val);

private:
#ifdef WIN32
	HANDLE handle;				// файловый дескриптор
#endif

};



#endif // _TR_RS232_H_
