Author Topic: Sending Reports to HID printer  (Read 1734 times)

chedges

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
Sending Reports to HID printer
« on: January 28, 2009, 12:33:01 pm »
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

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
Re: Sending Reports to HID printer
« Reply #1 on: January 28, 2009, 01:52:08 pm »
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

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: Sending Reports to HID printer
« Reply #2 on: January 29, 2009, 06:40:53 am »
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.