Data Receiver
ZDSimulator Data Receiver
ZDSimulator Data Receiver предназначен для чтения активных параметров симулятора в виде исходного кода Delphi. Может использоваться для модификации параметров игры, добавления пользовательской логики и интеграций

Находится в папке utils\ZDReceiver в директории, где установлен ZDSimulator Content Editor
Для сборки проекта необходимо использовать Lazarus
Примеры
Вывод на Arduino через порт COM
Пример от игрока JazzyManSerg
- Подключил 2 библиотеки
Synaser,math
- Добавил в объект формы (для наглядности значение скорости и положение крана395 которое уходит в компорт)
speed: TStaticText;
Kran395: TStaticText;
- Переменную для COM порт
var
ser: TBlockSerial;
- В процедуру
TZDReceiverForm.Timer1Timerдобавил два блока не посредственно перед заполнением таблицы
if (Name='Kran395RealPos') then
begin
if (ser=nil) then
begin
ser:= TBlockSerial.Create;
ser.RaiseExcept := True;
ser.LinuxLock := False; // это требуется для Linux. Если это не установить, то не удастся открыть порт.
ser.Connect('COM3'); // открытие порта
ser.Config(9600, 8, 'N', 0, false, false); // указываем параметры передачи данных
end;
sst:="!"+ValueStr+"!"+#13#10; // это для примера
ser.SendBuffer(@sst[1],Length(sst)); // отправляем буфер в порт
kran395.Caption:=sst;
end;
if (Name='SpeedKpH') then
begin
if (ser=nil) then
begin
ser:= TBlockSerial.Create;
ser.RaiseExcept := True;
ser.LinuxLock := False; // это требуется для Linux. Если это не установить, то не удастся открыть порт.
ser.Connect('COM3'); // открытие порта
ser.Config(9600, 8, 'N', 0, false, false); // указываем параметры передачи данных
end;
fft:=StrToFloat(ValueStr);
ValueStr:=FloatToStr(SimpleRoundTo(FFT,-2));
sst:=">"+ValueStr+"<"+#13#10; // это для примера
ser.SendBuffer(@sst[1],Length(sst)); // отправляем буфер в порт
Speed.Caption:=sst;
end;
Можно было воспользоваться каким-то протоколом но для 2-х значений вполне подойдет просто 3 спецсимвола !,>,<
!кран>скорость<
- В проекте для Ардуино я использовал немного другой протокол пользователя CobraOne (который он любезно предоставил со своей бесплатной программой драйвером и примером под Ардуино) для вывода скорости в TSW - чтобы один и тот же экранчик показывал скорость в разных играх. Я доработал его скетч для использования с экраном TFT
<Speed:MySpeedometer:скорость>В ждресивере немного изменить передачу скорости (значение крана не передавал, хотя можно, используя этот протокол)
if (Name='SpeedKpH') then
begin
if (ser=nil) then
begin
ser:= TBlockSerial.Create;
ser.RaiseExcept := True;
ser.LinuxLock := False;
ser.Connect('COM3');
ser.Config(115200, 8, 'N', 0, false, false);
end;
fft:=StrToFloat(ValueStr);
ValueStr:=FloatToStr(SimpleRoundTo(FFT,-2));
sst:="<Speed:MySpeedometr:"+ValueStr+">"+#13#10;
ser.SendBuffer(@sst[1],Length(sst)); // отправляем буфер в порт
Speed.Caption:=sst;
end;
вот пример работы экранчика https://youtu.be/cJ9kfh2o9Ic
- скетч ардуино
#include <Adafruit_GFX.h>
#include <UTFTGLUE.h> // 480*320
#include <stdio.h> // 480*320
UTFTGLUE myGLCD(0x9488,A2,A1,A3,A4,A0);
//Buffer to hold data from serialport, I use an array size of 3 to keep the format
// the same as my TS Classic version, "<Speed:MySpeedometer:" + speed + ">"
//The < and > are used to indicate the start and end of a message.
//data[0] = controlgroup
//data[1] = controlname
//data[2] = value
//data[0] will be Speed, Data[1] will be MySpeedometer and data[0] will be the actual speed.
char data[3][80];
// byte data to hold the position of the current char in the data array.
byte cnt = 0;
byte pos = 0;
//Marker set when start of data received
boolean started = false;
//Marker set when all data received
boolean finished = false;
void setup() {
// Setup the Arduino for serial communications.
Serial.begin(115200);
myGLCD.InitLCD();
myGLCD.setRotation(3);
myGLCD.fillScr(0, 0, 0);
myGLCD.setColor(255,255, 0); //font color
myGLCD.setBackColor(0,0,0);
myGLCD.setTextSize(3);
myGLCD.print("T R A I N",140,50);
myGLCD.print("S P E E D",140,120);
myGLCD.print("S Y S T E M",195,200);
myGLCD.printNumI(" ", 150, 260);
myGLCD.printNumI("Speed = 0 km/h", 195, 260);
myGLCD.setColor(255,20, 0); //font color
myGLCD.drawRect(5, 5, 475, 315);
myGLCD.setColor(0,0, 0); //font color
}
void loop() {
// Check we have something in the serial buffer
while(Serial.available() > 0) {
char nextChar = Serial.read();
if(nextChar == '<') { //Check for start of command marker
started = true;
finished = false;
pos = 0;
cnt = 0;
//Reset data to nothing
data[0][0] = '\0';
data[1][0] = '\0';
data[2][0] = '\0';
}
else if(nextChar == '>') { //End of command marker
finished = true;
break; //We have our data so exit the loop
}
else if(nextChar == ':') { //End of current string
pos++;
cnt = 0;
}
else {
data[pos][cnt] = nextChar; //Store the incoming data one char at a time
cnt++;
data[pos][cnt] = '\0'; //Null terminate the data array;
}
} //End of While loop
if(started && finished) { //All data for the current command received.
UpdateHardware();//Activate switches/displays etc
}
}
void UpdateHardware() {
//Create a variable used to hold how many spaces required at end of a line for the lcd
byte padding = 0;
//Temporary variable used when formatting output string for the display
char tmp[30];
//Here we check to see if the controlgroup is "Speed", if it is, we display the data to the lcd.
if( !strcmp(data[0], "Speed")){
myGLCD.setRotation(3);
myGLCD.fillScr(0, 0, 0);
myGLCD.setColor(255,255, 0); //font color
myGLCD.setBackColor(0,0,0);
myGLCD.setTextSize(3);
myGLCD.print("T R A I N",140,50);
myGLCD.print("S P E E D",140,120);
myGLCD.print("S Y S T E M",195,200);
myGLCD.printNumI(" ", 195, 260);
sprintf(tmp,"%s = %s km/h", data[0], data[2]);
myGLCD.printNumI(tmp, 150, 260);
myGLCD.setColor(255,20, 0); //font color
myGLCD.drawRect(5, 5, 475, 315);
myGLCD.setColor(0,0, 0); //font color
}
}