0

I need to send Hex data like a command to my serial port using Delphi.
The Hex data like "0x1b 0x31".

What the procedure can I used ?
writestring() or writebuffer() ? How to use them ?

TridenT
  • 4,879
  • 1
  • 32
  • 56
hytham
  • 53
  • 1
  • 6
  • Which `TComPort` component do you use ? This [`TComPort`](http://sourceforge.net/projects/comport) component has no `WriteBuffer` method (I've grepped only version 4.11f). I'd suggest that the [tag:tcomport] tag should either be properly described (if it's about TurboPower components, or the TComPort library that I've linked in this comment, or another one), or should de destroyed as ambiguous. – TLama Mar 22 '15 at 20:31

1 Answers1

4

If you use TComPort from ComPort Library (sourceforge), then invoke WriteStr() method:

ComPort.WriteStr(chr($1b));

If you use TApdComPort from TurboPower component, use the PutChar() method (according that command you want to send is $1b):

ApdComPort1.PutChar(char($1b);
TridenT
  • 4,879
  • 1
  • 32
  • 56
  • Thanks TridenT it is work fine – hytham Mar 22 '15 at 22:51
  • 2
    Ad ComPort Library, if the aim is to send two bytes (not two chars, nor 1 char as shown in this post), you should use `Write` method. In TP there is a similar method, `PutBlock`. Except that the command should be declared as a constant, not as some magical number. But take this comment just as a note about how to do things right, hytham. It you're happy with *it works*, then you should be fine with sending your two bytes char by char in this case. – TLama Mar 23 '15 at 05:05