• Welcome to Forum.Deepsoftware.Com. Please login or sign up.
 
April 18, 2024, 11:58:54 pm

News:

SMF - Just Installed!


Sending Reports to HID printer

Started by chedges, January 28, 2009, 10:33:01 am

Previous topic - Next topic

chedges

Hi again,

I've started to look into sending some data to the HID printer I have installed and I'm having problems sending reports to the printer
using either of the SendString or WriteReport methods of the HID component.

I've managed to get a very small app working using the JEDI HID components but I'd like to use your compoents as I'm already using your LPT components with great success :)

I've added a additional button to the HIDdemo project so you can presume the following code has a active HID device via it's UI etc.

I've used the following code but I'm unsure if the report array should be a int or char array?
I've tried sending a string via SendString with the report appended to the front and this doesn't work either (e.g SendString('0Hello World<p>')).
I'm doing something stupid, I just need a push in the right direction.

Thanks again for your helpful support


Chris Hedges
Tickets.com UK



type
  ReportArray = Array[0..255] of Integer;
  PReportArray = ^ReportArray;

procedure TForm1.Button1Click(Sender: TObject);
var
  I: Integer;

  ToWrite: Cardinal;
  Str: string;
  FGL : String;
  Report : PReportArray;
begin

    FGL := 'Hello World<p>'; //The stuff we want to send to the printer

    New(Report); //allocate

    Report^[0] := StrToIntDef('$0', 0);  //Set the Report Id - From the HIDDemo the input and output ReportIds show as zero?

    toWrite := nrHID1.HidDevice.OutputReportLength; //Get the Report length - my printer returns 256bytes

    //init the buffer
    for I := 1 to ToWrite-1 do
      Report^ := StrToIntDef('$0', 0);

    //fill buffer with the chars to sent
    for I := 1 to Length(FGL) do
      Report^ := Ord(FGL);

    nrHid1.WriteReport(Report, ToWrite);

    Dispose(Report);
end;

chedges

Ok , I was a double idiot!

firstly, I posted this in the wrong section and secondly I declared my array as a Integer instead of byte.  :-[

Just need to figure out how to read reports now :)

Roman Novgorodov

Hello

You can use TnrHID.ReadReport() method.
Also we recommend to use TnrHID.OnAfterReceive event.

Roman Novgorodov
DeepSoftware.Com
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.