I want to implement a Tinkerforge ReadCallback function in matlab to log changes from a RS485Bricklets with four slaves. I am able to establish an IP-connection and if I input a value into the bricklet via Brickviewer I receive it in matlab but I don't automatically receive values with the Callback-function without manual input.
clc
clear all
global data
import com.tinkerforge.IPConnection;
import com.tinkerforge.BrickletRS485;
import java.lang.String;
HOST = 'localhost';
PORT = 4223;
UID = 'DKf'; % Change XYZ to the UID of your RS485 Bricklet
input('Press key to start\n', 's');
ipcon = IPConnection(); % Create IP connection
rs485 = handle(BrickletRS485(UID, ipcon), 'CallbackProperties'); % Create device object
ipcon.connect(HOST, PORT); % Connect to brickd
% Don't use device before ipcon is connected
% Set Mode to RS485
rs485.setMode(BrickletRS485.MODE_RS485);
% Configure RS485Bricklet
rs485.setRS485Configuration(9600, BrickletRS485.PARITY_EVEN, ...
BrickletRS485.STOPBITS_1, BrickletRS485.WORDLENGTH_7, ...
BrickletRS485.DUPLEX_HALF);
% Register read callback to function cb_read
set(rs485, 'ReadCallback', @(h, e)cb_read(e));
% Enable read callback
rs485.enableReadCallback();
% Write "ASCII" string (Adresse und Befehl)
rs485.write(String(':9003015E00020C\r\n').toCharArray()); %SWA 144
rs485.write(String(':8E03015E00020E\r\n').toCharArray()); %SWB 142
rs485.write(String(':8D03015E00020F\r\n').toCharArray()); %SWC 141
rs485.write(String(':8F03015E00020D\r\n').toCharArray()); %SWD 143
input('Press key to exit\n', 's');
ipcon.disconnect();
% Callback function for read callback
function cb_read(e)
global data
tmp_t = now;
fprintf('test \n');
fprintf('Message: "%s"\n', e.message);
B = convertCharsToStrings(e.message);
C = [tmp_t; B];
data = [data, C];
end