ich habe hier einen Sick-Geber SRM50 vor mir liegen.
Angeschlossen habe ich ihn über einen Wandler USB-RS485 von Waveshare.
Betriebssystem ist Linux. Der Wandler läuft an einem anderen Projekt tadellos
Betriebsaleitung des Gebers https://cdn.sickcn.com/media/docs/6/06/ ... 49006.pdf
Erfahrungen habe ich bis jetzt nur mit Modbus am anderen Projekt sammeln können.
Wie schaut es aber bei solch einen Geber aus.
Er wird anders angesprochen, hat eine Adresse 40h, mit 42h sollte ich die Positionen lesen können.
Mein Bastel-Code:
Code: Alles auswählen
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
import serial
import serial.rs485
import sys
import time
import binascii
ser = serial.Serial(
port='/dev/ttyUSB0',
baudrate = 9600,
bytesize = serial.EIGHTBITS, # number of bits per bytes
parity = serial.PARITY_EVEN, # set parity check: no parity
stopbits = serial.STOPBITS_ONE, #number of stop bits
timeout = .2, #block read
xonxoff = False, #disable software flow control
rtscts = False, #disable hardware (RTS/CTS) flow control
dsrdtr = False, #disable hardware (DSR/DTR) flow control
writeTimeout = .2 #timeout for write
)
time.sleep(0.010)
try:
ser.is_open
print(ser.name)
ser.flushInput() #flush input buffer, discarding all its contents
ser.flushOutput()#flush output buffer, aborting current output
except Exception as e:
print(f"Error: {e}")
sys.exit(1)
i = 1
data = [40]
# ser.write(bytes)
while i < 10:
ser.write(data)
ser.flush
time.sleep(0.1)
response = ser.readline()
hex_string = binascii.hexlify(response).decode('utf-8')
print(hex_string)
i = i + 1
Ist meine Vorgehensweise annähernd ok? Wie rufe ich mehrere Registerwerte auf./dev/ttyUSB0
00
00
00
00
00
00
00
00
00
So richtig verstehen tu ich es noch nicht.
Gruß Ralf