Bluetooth Connection D7

aj85
aj85 used Ask the Experts™
on
I am using these components for D7: http://www.btframework.com/wcl.htm to build a bluetooth application that connects to an overhead LED sign display using this device: UD100 http://www.sena.com/products/industrial_bluetooth/ud100.php.  

At present I have been able to transmit a text file in testing the connection to a separate bluetooth device using this code:


procedure TfmMain.btPutClick(Sender: TObject);
var
  Stream: TFileStream;
begin
  if OpenDialog.Execute then begin
    Stream := TFileStream.Create(OpenDialog.FileName, fmOpenRead or fmShareDenyWrite);
    wclShowError(wclOPPClient.Put(ExtractFileName(OpenDialog.FileName), Stream));
    Stream.Free;
  end;
end;

I want to transmit a single line command in D7, using the components above to the LED, for example, the commands below will make the sign display "Open":

                        [COMON]
                  [PX0 PY0]Open[ACT0]
                  [COMOFF]


I know this may be a simple fix, but I am not sure how to proceed, and I am new to developing bluetooth applications.

Thanks in advance,
aj85
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Also use wclOPPClient.Put() to send strings to your USB device:

First write your command string into a stream and then send it to your USB device. Don't forget to free stream immediately after sending...

var
  Stream: TStream;
  s: String;
  n: LongInt;
begin
  n:= Length(s);

  if n > 0 then begin
    Stream:= TStream.Create;
    Stream.Write(n, SizeOf(n));
    Stream.Write(s[1],n);

    wclShowError(wclOPPClient.Put(ExtractFileName(OpenDialog.FileName), Stream));

    Stream.Free;
  end;
  

Open in new window


Streams, streams, ... using the TStream in Delphi

Author

Commented:
Hello Thommy,

Okay can you show in an example using the previous commands I posted:

                  [COMON]
                  [PX0 PY0]Open[ACT0]
                  [COMOFF]

Thanks,
aj85

Commented:
Can you please provide command reference of your overhead LED sign display?

Author

Commented:
Hello,

Attached is the complete communications protocol command reference for the sign display.

Thanks,
aj85
COMMUNICATIONS-PROTOCOL.pdf

Commented:
var
  Stream: TStream;
  s: String;
  n: LongInt;
begin
  s:='[COMON][PX0 PY0]Open[ACT0][COMOFF]'
  n:= Length(s);

  if n > 0 then begin
    Stream:= TStream.Create;
    Stream.Write(n, SizeOf(n));
    Stream.Write(s[1],n);

    wclShowError(wclOPPClient.Put(ExtractFileName(OpenDialog.FileName), Stream));

    Stream.Free;
  end;

Open in new window


Please see page 115 on WCL Developer's Guide for explanation of wclOPPClient.Put - method...

Author

Commented:
Hello,

So just to confirm after you looked at the protocol documentation, in order to send the command to the LED sign to display "Open" the command that I was using should work?  How do I send the command to dim the sign?

Thanks,
aj85

Author

Commented:
Hello,

I got the attached error message when I ran the code.

Thanks,
aj85
Error-Message.png

Commented:
From the communications protocol I found this commands for brightness control:

GETBRIGHT : return the LED brightness (1 ~ 100 return)
BRIGHT : LED brightness control (applicable to common condition, range:1~100)

Can you please state the line, where the error occurs and/or provide your demo code?

Author

Commented:
Hello,

The error occurs on this line of code: Stream.Write(n, SizeOf(n));

Thanks,
aj85

Commented:
Sorry, my fault!
This line is nonsense, so just leave it off...
How do I put a string onto a stream?

Author

Commented:
Hello,

It seems that I am getting the same error even after I comment that line out.  Not sure what else could be cause this error.  If I comment out the next line then the variable will not have the command string.

aj85
Commented:
Ok, TStream is an abstract class and the base class of other stream objects. Therefore it should only be used in its descendant's forms...
Streams, streams, ... TStream

Use TStringStream:

var
  Stream: TStringStream;
  s: String;
  n: LongInt;
begin
  s:='[COMON][PX0 PY0]Open[ACT0][COMOFF]';
  n:= Length(s);

  if n > 0 then begin
    Stream:= TStringStream.Create(s);

    wclShowError(wclOPPClient.Put(ExtractFileName(OpenDialog.FileName), Stream));

    Stream.Free;
  end;
end;

Open in new window

Author

Commented:
Hello,

Thanks!  That solved the problem.

aj85

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial