• Welcome to Forum.Deepsoftware.Com. Please login or sign up.
 

Transmission of data to light a led c ++ builde

Started by Slim78, April 18, 2017, 04:11:48 pm

Previous topic - Next topic

Slim78

Hello,

To begin by forgive me for my English,
About 1 month ago I buy this software nrcommlib
I am confronted with a problem, being a beginner I do not know at all how to send give in hid usb to light a led under proteus (software of electronic simulation)

If someone could give me a small example with explanation his would be nice thanks in advance.

Here is my code I can not go further :(
void __fastcall TForm1::B_ConnectionClick(TObject *Sender)
{
for(int i=0;i < nrHid1->DeviceCount;i++)
   {
nrHid1->DeviceIndex=i;
Vid= IntToHex(nrHid1->HidDevice->VendorId,4);
Pid= IntToHex(nrHid1->HidDevice->ProductId,4);
Indexx= nrHid1->DeviceIndex;
Manufact= nrHid1->HidDevice->Manufacturer;
NomFriendly= nrHid1->HidDevice->NameFriendly;
Test= nrHid1->HidDevice->Description;
Test2=nrHid1->HidDevice->InstanceId;

   if(Vid=="1234" && Pid=="0001")
   {
   Label_Statut->Caption="Priferique trouvé";
   Label2->Caption="Description          : " + Test;
   Lab_Vendorid->Caption="Vendor id             : " + Vid;
   Lab_Productid->Caption="Product id            : " + Pid;
   Lab_Nom->Caption="Test                     : " + NomFriendly;

   Lab_Index->Caption="Index                  : " + Indexx;
   Lab_Manfacture->Caption="Manufcturer        : " + Manufact;


   Label3->Caption="Instance ID         : " + Test2;

   nrHid1->DeviceIndex =i;
   nrHid1->Active = true;
   break;
   }
   else{
Label_Statut->Caption="PAS DE CONNEXION";
   }

   }


}

   

Roman Novgorodov

Hello

If I understand you correctly you want to make write operation ot HID device.

Please take a look at following part of HIDDemo project:

procedure TForm1.Button1Click(Sender: TObject);
var s, s2:string;
    len:integer;
begin
  // prepare data string and reserve first byte for ID ...
  s := Char(eID.Value);
  if cbType.ItemIndex = 0
    then s := s + Edit1.Text
    else s := s + Deserialize(Edit1.Text);

  // send HID report
  if CheckBox2.Checked then begin
    len := Length(s);
    if nrHid1.OutputReportLength < len
      then len := nrHid1.OutputReportLength;
    SetLength(s2,  nrHid1.OutputReportLength);
    CopyMemory(@s2[1], @s[1], len);
    nrHid1.SendData(@s2[1], nrHid1.OutputReportLength);
  end else
    nrHid1.SendData(@s[1], Length(s));
end;

procedure TForm1.Button2Click(Sender: TObject);
var s,s2:string;
    len:integer;
begin
  // prepare data string and reserve first byte for ID ...
  s := Char(eID.Value);
  if cbType.ItemIndex = 0
    then s := s + Edit1.Text
    else s := s + Deserialize(Edit1.Text);

  // send HID report
  if CheckBox2.Checked then begin
    len := Length(s);
    if nrHid1.OutputReportLength < len
      then len := nrHid1.OutputReportLength;
    SetLength(s2,  nrHid1.OutputReportLength);
    CopyMemory(@s2[1], @s[1], len);
    nrHid1.SetOutputReport(@s2[1], nrHid1.OutputReportLength);
  end else
    nrHid1.SetOutputReport(@s[1], Length(s));

end;


Roman Novgorodov
DeepSoftware llc

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

Slim78

Hello, yes Roman Novgorodoff is good, yes I watched the example its function may be worry is that my led always stay on
What I would like to know is how to send the number "1" to turn it on and the number "0" to turn it off

thank you :)