Author Topic: Transmission of data to light a led c ++ builde  (Read 165 times)

Slim78

  • Newbie
  • *
  • Posts: 3
    • View Profile
Transmission of data to light a led c ++ builde
« on: April 18, 2017, 07:11:48 pm »
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 :(
Code: [Select]
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

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: Transmission of data to light a led c ++ builde
« Reply #1 on: April 19, 2017, 12:24:24 pm »
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:

Code: [Select]
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

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Transmission of data to light a led c ++ builde
« Reply #2 on: April 19, 2017, 06:35:29 pm »
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 :)