در ابتدا یک Console Application ایجاد کنید سپس فایل کتابخانه را به رفرنس ها اضافه کنید. جهت دانلود فایل کتابخانه به بخش دانلودها مراجعه کنید.
در این مثال با فشردن دکمه Enter بر روی کیبرد یک Event در نرم افزار Apex ثبت خواهد شد.
static void Main(string[] args)
{
Thread thread = new Thread(thread_run);
thread.Start();
string cmd = Console.ReadLine();
Console.WriteLine("-------");
while (cmd!="exit")
{
_trigger.Trigger_send();
cmd = Console.ReadLine();
}
}
private static BSNlab_tcp.Apex_TCP_Trigger _trigger;
public static void thread_run()
{
_trigger = new BSNlab_tcp.Apex_TCP_Trigger();
_trigger.run(callback);
}
public static void callback(byte[] msg)
{
foreach (var item in msg)
{
Console.Write(item.ToString());
}
Console.WriteLine(".");
}
پس از اتصال صحیح Application در لیست ماژول های نرم افزار Apex یک ماژول Trigger ایجاد خواهد شد.
با استفاده از این سرور میتوانید داده های سنسورهای IMU را به صورت برخط در نرم افزار های دیگر همچون Matlab جمع آوری کنید دانلود آرمیتا
clc;
clear all;
close all;
t = tcpclient('127.0.0.1',5050);
write(t,'Sample_Period,2,5','string');
write(t,"LOGIN,email@example.com,Password");
login = readline(t)
if (strcmp(login,'Done'))
flush(t);
write(t,"START");
res = readline(t)
if (strcmp(res,'Done'))
h = figure(1);
subplot(3,1,1);
title('Acceleration');
subplot(3,1,2);
title('Gyroscope');
subplot(3,1,3);
title('Magnetameter');
view = 500;
frame =1;
flush(t);
while(1)
temp = readline(t);
if (temp ~= "")
Mdata = split(temp,'|');
for imu = 1:size(Mdata,1)
data = split(Mdata(imu));
if (size(data,1)>=10)
IMUS(imu).time(frame,1) = str2double(data(1));
IMUS(imu).acc(frame,:) = [str2double(data(2)), str2double(data(3)), str2double(data(4))];
IMUS(imu).gyro(frame,:) = [str2double(data(5)), str2double(data(6)), str2double(data(7))];
IMUS(imu).mag(frame,:) = [str2double(data(8)) , str2double(data(9)), str2double(data(10))];
end
end
%plot
if (rem(frame,100)==0)
if (frame < view +1)
subplot(3,1,1);
plot(1:frame, IMUS(1).acc(1:frame,:));
title('Acceleration');
subplot(3,1,2);
plot(1:frame, IMUS(1).gyro(1:frame,:));
title('Gyroscope');
subplot(3,1,3);
plot(1:frame, IMUS(1).mag(1:frame,:));
title('Magnetameter');
else
subplot(3,1,1);
plot(frame-view:frame, IMUS(1).acc(frame-view:frame,:));
title('Acceleration');
subplot(3,1,2);
plot(frame-view:frame, IMUS(1).gyro(frame-view:frame,:));
title('Gyroscope');
subplot(3,1,3);
plot(frame-view:frame, IMUS(1).mag(frame-view:frame,:));
title('Magnetameter');
end
end
frame = frame + 1
end
isKeyPressed = ~isempty(get(h,'CurrentCharacter'));
if isKeyPressed
break
end
%pause(0.01);
end
end
else
disp('Login failed...')
end
flush(t);
write(t,"STOP");
t.Terminator;