Project

General

Profile

RE: RS-485 problems » RS485.cpp

Steven Hill, 07/17/2013 06:48 PM

 
1
/*
2
 * RS485.cpp
3
 *
4
 *  Created on: 2013-07-17
5
 *      Author: mitydsp
6
 */
7
#include <sys/ioctl.h>
8
#include "RS485.h"
9
using namespace MityDSP;
10

    
11
tcArmRS485::tcArmRS485()
12
{
13
	isOpen = false;
14
	isReady = false;
15

    
16
	termHandle = open("/dev/ttyS2", O_RDWR | O_NOCTTY | O_NDELAY);
17
	if (termHandle < 0)
18
		return;
19
	else
20
		isOpen = true;
21
	rs485conf.flags = SER_RS485_ENABLED;
22
	rs485conf.flags |= SER_RS485_USE_GPIO;
23
	rs485conf.delay_rts_before_send = 0;
24
	rs485conf.gpio_pin = GPIO0_9;
25

    
26
	rv = ioctl (termHandle, TIOCSRS485, &rs485conf);
27
	if (rv) {
28
		perror("unable to set IOCTL:");
29
		return;
30
	}
31
	tcgetattr(termHandle, &my_termios);
32
	// this is for raw mode, 19.2 kBaud
33
	/*	my_termios.c_iflag &= ~(IGNBRK | BRKINT | ICRNL | INLCR | PARMRK | IGNCR | ISTRIP | IXON);
34
		my_termios.c_oflag &= ~OPOST;
35
		my_termios.c_lflag &= ~(ECHO | ECHONL | ICANON | IEXTEN | ISIG);
36
		my_termios.c_cflag &= ~(CSIZE | PARENB);
37
		my_termios.c_cflag |= CS8 | CLOCAL;
38
		my_termios.c_cflag &= ~CBAUD;
39
		my_termios.c_cflag |= B19200;
40
	*/
41
	// this is for test mode
42
	my_termios.c_iflag &= ~(IGNBRK | BRKINT | ICRNL | INLCR | PARMRK | INPCK | ISTRIP | IXON);
43
	my_termios.c_oflag &= ~(OCRNL | ONLCR | ONLRET | ONOCR | OFILL | OLCUC | OPOST);
44
	my_termios.c_lflag &= ~(ECHO |  ECHONL | ICANON | IEXTEN | ISIG | ECHOK | ECHOCTL | ECHOPRT);
45
	my_termios.c_cflag &= ~(CSIZE | PARENB);
46
	my_termios.c_cflag &= ~CRTSCTS;
47
	my_termios.c_cflag |= CS8 | CLOCAL;
48
	my_termios.c_cflag &= ~CBAUD;
49
	my_termios.c_cflag |= B19200;
50
	my_termios.c_cc[VMIN] = 1;
51
	my_termios.c_cc[VTIME] = 0;
52
	rv = tcsetattr(termHandle, TCSANOW, &my_termios);
53

    
54
	tcgetattr(termHandle, &new_termios);
55

    
56
	isReady = true;
57

    
58
}
59

    
60
tcArmRS485::~tcArmRS485()
61
{
62
	if(isOpen)
63
		close(termHandle);
64
}
65

    
66

    
67

    
68

    
69

    
(1-1/2) Go to top
Add picture from clipboard (Maximum size: 1 GB)