15 Commits

14 changed files with 19 additions and 46 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
**/*.o
**/*.so
**/*.pyc
.pymodhis
**/__pycache__

3
.gitmodules vendored
View File

@ -1,3 +0,0 @@
[submodule "rpirtscts"]
path = rpirtscts
url = https://github.com/wollud1969/rpirtscts.git

View File

@ -1,15 +0,0 @@
# 2019-06-14 22:50:36.107575
+help
# 2019-06-14 22:50:54.780566
+q
# 2019-06-14 22:52:53.061353
+help
# 2019-06-14 22:53:29.359029
+client.read_ho
# 2019-06-14 22:53:48.878000
+client.read_holding_registers unit=3 address=0 count=3

BIN
docs/modbus-not-ok.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

BIN
docs/modbus-ok.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

View File

@ -1,7 +1,8 @@
CFLAGS=-I/opt/bcm2835/include
CFLAGS=
LIBS=-lwiringPi
writec.so: writec.o /opt/bcm2835/lib/libbcm2835.a
$(LD) -shared -o $@ $^
writec.so: writec.o
$(LD) -shared $(LIBS) -o $@ $^
writec.o: writec.c

View File

@ -7,13 +7,10 @@ class RS485Ext(serial.rs485.RS485):
def __init__(self, *args, **kwargs):
super(RS485Ext, self).__init__(*args, **kwargs)
self.writec = ctypes.cdll.LoadLibrary('writec.so')
fd = self.fileno()
r = self.writec.set_rs485_mode(fd)
r = self.writec.init()
def write(self, b):
d = serial.serialutil.to_bytes(b)
l = len(d)
fd = self.fileno()
r = self.writec.writec(fd, d, l)
r = self.writec.writec(self.fileno(), d, len(d))
return r

View File

@ -1,30 +1,25 @@
#include <unistd.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <linux/serial.h>
#include <errno.h>
#include <string.h>
#include <stdint.h>
#include <bcm2835.h>
#include <wiringPi.h>
const uint8_t DE_PIN = RPI_V2_GPIO_P1_11;
const uint8_t DE_PIN = 0;
int set_rs485_mode(int fd) {
bcm2835_init();
bcm2835_gpio_fsel(DE_PIN, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_write(DE_PIN, LOW);
int init() {
wiringPiSetup();
pinMode(DE_PIN, OUTPUT);
digitalWrite(DE_PIN, HIGH);
}
ssize_t writec(int fd, char *buf, size_t count) {
bcm2835_gpio_write(DE_PIN, LOW);
digitalWrite(DE_PIN, LOW);
ssize_t r = write(fd, buf, count);
uint8_t lsr;
do {
int r = ioctl(fd, TIOCSERGETLSR, &lsr);
} while (!(lsr & TIOCSER_TEMT));
bcm2835_gpio_write(DE_PIN, HIGH);
digitalWrite(DE_PIN, HIGH);
return r;
}

Binary file not shown.

Binary file not shown.

Submodule rpirtscts deleted from 612b065e38

View File

@ -1,12 +1,6 @@
from pymodbus.client.sync import ModbusSerialClient
import serial.rs485
import RS485Ext
#ser=serial.rs485.RS485(port='/dev/ttyAMA0',baudrate=1200)
#ser.rs485_mode = serial.rs485.RS485Settings(rts_level_for_tx=False,
# rts_level_for_rx=True,
# delay_before_tx=0.005,
# delay_before_rx=-0.0)
ser=RS485Ext.RS485Ext(port='/dev/ttyAMA0', baudrate=1200)
client = ModbusSerialClient(method='rtu')