Hi,
I am using the TinkerForge RS232 V2 Module and want to read sensor data.
This is my code
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# For this example connect the RX1 and TX pin to receive the send message
HOST = "localhost"
PORT = 4223
UID = "XXXX" # Change XYZ to the UID of your RS232 Bricklet 2.0
from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_rs232_v2 import BrickletRS232V2
import time
# Callback function for read callback
def rs232_data_received(data):
test = ''.join(data)
print(test)
if __name__ == "__main__":
ipcon = IPConnection() # Create IP connection
rs232 = BrickletRS232V2(UID, ipcon) # Create device object
ipcon.connect(HOST, PORT) # Connect to brickd
rs232.set_configuration(baudrate=9600,
parity=BrickletRS232V2.PARITY_NONE,
stopbits=BrickletRS232V2.STOPBITS_1,
wordlength=BrickletRS232V2.WORDLENGTH_8,
flowcontrol=BrickletRS232V2.FLOWCONTROL_OFF)
# Don't use device before ipcon is connected
print(rs232.get_chip_temperature())
# Register read callback to function cb_read
rs232.register_callback(rs232.CALLBACK_READ, rs232_data_received)
# Enable read callback
rs232.enable_read_callback()
input("Press key to exit\n") # Use raw_input() in Python 2
ipcon.disconnect()
The problem is, when I get the data output I only see unusual characters like this:
[
ý
¿
¿
å
ë
[
ý
å
ë
[
ý
When I use a FTDI Chip I can read the correct output (using pyserial). I also attached a LogicAnalyzer and the data shows fine. So I think it is a problem of converting the Data (Baudrate is correct).
Since I do not now what in the middle "layer" of TinkerForge is happening with the data, can someone please help me how to convert the data into correct ascii Numbers?
Many thanks