Tak jsem změnil int val na char val a zobrazovali se nějaké klikyháky.Po odeslání čísla 20 se zobrazilo 50 pak 48.Odstranění delay nepomůže.Zkoušel jsem odesílat data zpět z arduina do pc a je to stejné.Všechno co tank control posílá je v ascii.
Odstranění DEC ze závorky jsem zkoušel jako první.I tak se vše zobrazuje v DEC.Pro ten Herkules ale musím mít na pc com,ne?Já žádný com nemám(mám notebook).¨
Jinak jsem si naistaloval delphi 7 a prozkoumal jsem kod.našel jsem řádky, kde bylo psáno FF (levý pravý motor forward)BB.... tak jsem to přepsal na čísla 0 až 4, ale pořád to posílá původní text.Ještě za každým odeslaným příkazem se automaticky odešle číslo 13 a 10.V kodu jsou definovány jako chr(10) chr (13) a ty v arduinu opravdu přijmu jako číslo 10 a 13. Zkoušel jsem tedy stejně definovat i ostaní proměné ale neuspěšně.
Podle mě je tam někde definováno, že vše co se odesílá je jako text.
Nevíte jak upravit kod aby to posílalo čísla ne text.Vyznáte se v delpi.Prosím jestli můžete poraďte.Díky.
Pokud stisku tlačítko Forward příjmu postupně 70,13,10 Stop 83,13,10 Backward 66,13,10 Left 70,66, 13,10 Right 66,70,13,10
Přikádám původní zdrojový kod:
Jedná se o písmena SS,FF,FB,BF,BB.
Proměnná command je typu TEdit není tohle definice textu?
Kód: Vybrat vše
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
SynaSer, StdCtrls, ExtCtrls, Menus, Unit2;
type
TForm1 = class(TForm)
GroupBox1: TGroupBox;
comName: TEdit;
baudrate: TEdit;
connectButton: TButton;
Label4: TLabel;
Label5: TLabel;
GroupBox2: TGroupBox;
Memo1: TMemo;
Forward: TButton;
Stop: TButton;
disconnectButton: TButton;
Backward: TButton;
Right: TButton;
Left: TButton;
MainMenu1: TMainMenu;
xzcxzcxz: TMenuItem;
Exit1: TMenuItem;
GroupBox3: TGroupBox;
command: TEdit;
sendButton: TButton;
About1: TMenuItem;
procedure connectButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ForwardClick(Sender: TObject);
procedure StopClick(Sender: TObject);
procedure disconnectButtonClick(Sender: TObject);
procedure LeftClick(Sender: TObject);
procedure RightClick(Sender: TObject);
procedure BackwardClick(Sender: TObject);
procedure Exit1Click(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure sendButtonClick(Sender: TObject);
procedure About1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
connected: boolean;
ser: TBlockSerial;
stopped: boolean;
const
APP_VERSION = 'v1.0';
implementation
{$R *.DFM}
(**
* sends command to serial port
*)
procedure sendCommand(command: string);
begin
if (command = 'SS') then begin
stopped := true;
end else begin
stopped := false;
end;
if connected = true then begin
try
ser.SendString(command+chr(13)+chr(10));
Form1.Memo1.Lines.Text := Form1.Memo1.Lines.Text+ser.RecvPacket(10)+' ';
finally
//ser.free;
end;
end;
end;
(**
* connect the com port
*)
procedure TForm1.connectButtonClick(Sender: TObject);
begin
ser := TBlockSerial.Create;
ser.RaiseExcept := false; // do not throw exceptions (maybe dirty hack, but the library used to raise exceptions any time :-) )
try
ser.Connect(comName.Text);
ser.Config(strToInt(baudrate.Text), 8, 'N', 0, false, false);
// enable/disable buttons when connected
connected := true;
connectButton.Enabled := false;
disconnectButton.Enabled := true;
sendButton.Enabled := true;
left.Enabled := true;
right.Enabled := true;
forward.Enabled := true;
backward.Enabled := true;
stop.Enabled := true;
finally
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
connected := false;
stopped := true;
Form1.Caption := Form1.Caption+' '+APP_VERSION;
end;
procedure TForm1.ForwardClick(Sender: TObject);
begin
sendCommand('FF');
end;
procedure TForm1.StopClick(Sender: TObject);
begin
sendCommand('SS');
stopped := true;
end;
procedure TForm1.disconnectButtonClick(Sender: TObject);
begin
try
// disable/enable buttons when disconnecting
connected := false;
connectButton.Enabled := true;
disconnectButton.Enabled := false;
sendButton.Enabled := false;
left.Enabled := false;
right.Enabled := false;
forward.Enabled := false;
backward.Enabled := false;
stop.Enabled := false;
// free COM connection
ser.Free;
finally
end;
end;
procedure TForm1.LeftClick(Sender: TObject);
begin
sendCommand('FB');
end;
procedure TForm1.RightClick(Sender: TObject);
begin
sendCommand('BF');
end;
procedure TForm1.BackwardClick(Sender: TObject);
begin
sendCommand('BB');
stopped := false;
end;
procedure TForm1.Exit1Click(Sender: TObject);
begin
Application.Terminate;
end;
(**
* key control
*)
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
//memo1.Lines.text := memo1.lines.Text+FloatToStr(key)+' ';
case (key) of
38: sendCommand('1'); // forward
40: if (stopped) then sendCommand('BB') else sendCommand('SS'); // stop
37: sendCommand('FB'); // left
39: sendCommand('BF'); // right
end;
end;
(**
* Sends command to COM port ('terminal') :-)
*)
procedure TForm1.sendButtonClick(Sender: TObject);
begin
sendCommand(command.Text);
end;
(**
* shows 'About' forma
*)
procedure TForm1.About1Click(Sender: TObject);
begin
aboutForm.Show;
end;
end.