Hi,
I have PIC32MX795F512L. I have used the "USB Host - MCHPUSB - Generic Driver Demo - PIC32 USB Starter Kit II.mcp" Firmware.

I am very new to Delphi. So I have copy and paste the code from http://www.sixca.com/delphi/article/microchip_usb.html It is working fine.

I want to use the UPDATE_LED (change the LED status). Please help me.

The Update LED status C# code is at http://www.piccoder.co.uk/content/view/42/26/. it is working perfect. but i want this in delphi.

---------------------
i think it may the problem so please convert c# code to delphi. i don't know about bytes data type.

byte* send_buf=stackalloc byte[64];
			byte* receive_buf=stackalloc byte[64];

			DWORD RecvLength=3;
			send_buf[0] = 0x32;			//Command for LED Status  
			send_buf[1] = (byte)led;//0111
			send_buf[2] = (byte)(State?1:0);
			
			if (SendReceivePacket(send_buf,3,receive_buf,&RecvLength) == 1)
			{
				if (RecvLength == 1 && receive_buf[0] == 0x32)
				{	
					return 0;
				}
				else
				{
					return 2;
				}
			}
			else
			{	
				return 1;
			}

Please help me.

Thanks,
Hari

Something like this I think, but I have no way of testing.

type
  TBlock: array [0..63] of Byte;
  PBlock: ^TBlock;

var
  send_buf: PBlock;
  receive_bug: PBlock;
  RecvLength: Longint;
begin
  GetMem(send_buf, SizeOf(TBlock));
  GetMem(receive_buf, SizeOf(TBlock));

  RecvLength := 3;
  send_buf[0] = $32;
  send_buf[1] = (Byte)led;
  if State then
    send_buf[2] = 1
  else
    send_buf[2] = 0;

  if SendReceivePacket(send_buf, 3, receive_buf, RecvLength) = 1 then
  begin
    // ...
  end;

  FreeMem(send_buf);
  FreeMem(receive_buf);
end;

Edited 5 Years Ago by pritaeas: n/a

This article has been dead for over six months. Start a new discussion instead.