Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem using BULKputs(char *buffer, byte length)
28-07-2013, 08:24 AM, (This post was last modified: 28-07-2013, 10:21 AM by JackyZai.)
#1
Problem using BULKputs(char *buffer, byte length)
Hi guys,

I'm trying to communicate my PIC with Processing through usb bulk transfer.
My pinguino is able to read data from Processing but not send data to Processing, the library I use is __bulk.c.

The function used to send data is:
BULKputs(char *buffer, byte length)

Device: Pinguino 4550
Bootloader: v2.12 and v4.9
IDE version : x4-easy-rev857
Operating System: Windows 7

There is a fix in usb_config.c by me
///////////////////////////////////////
usb_config.c changes
///////////////////////////////////////
#ifdef USB_USE_BULK
__code USB_Configuration_Descriptor libconfiguration_descriptor = {
// Configuration Descriptor Header
{sizeof(USB_Configuration_Descriptor_Header),// Size of this descriptor in bytes
CONFIGURATION_DESCRIPTOR, // CONFIGURATION descriptor type
sizeof(USB_Configuration_Descriptor),// Total length of data for this configuration //This line has been fixed
///////////////////////////////////////

///////////////////////////////////////
Pinguino side program:
///////////////////////////////////////
#include <__bulk.c> //include bulk transfer library

void BULKwrite(u8 c) //function to write a single byte
{
BULKputs(&c, 1);
}

void setup()
{
pinMode(7, OUTPUT); //set RB7(led) as digital output pin
}

u8 command[]; //variable to store received data

void loop()
{
BULKgets(command); //read bulk
if(command[0] == '0')
{
//if data = 0 turn off led and send 0x09 to Processing
digitalWrite(7,LOW);
BULKwrite(9);
}
else if(command[0] == '1')
{
//if data = 1 turn on led
digitalWrite(7,HIGH);
}
}
///////////////////////////////////////

///////////////////////////////////////
Processing side program:
//////////////////////////////////////
import hypermedia.pinguino.*; //import pinguino library

Pinguino board; //pinguino object

void setup()
{
board = new Pinguino(this); //connect to Pinguino board
}

byte[] write_1 = new byte[] {'1'};
byte[] write_0 = new byte[] {'0'};
byte[] response = new byte[1];

void draw()
{
board.write( write_1 );
delay(500);
board.write( write_0 );
readpinguino();
delay(500);
println();
}

void readpinguino() // get Pinguino's response
{
response = board.read( response );
while(response == null)
{
response = board.read( response );
}
println( str(response) );
}
///////////////////////////////////////

Its been a month I'm trying to solve this problem, but I'm getting out of time to complete my project so I decided to ask for help.

Jacky,
Thanks.


Attached Files
.pde   pinguino_program.pde (Size: 619 bytes / Downloads: 1)
.hex   pinguino_program.hex (Size: 16.76 KB / Downloads: 0)
.pde   Processing_program.pde (Size: 666 bytes / Downloads: 8)
.c   usb_config.c (Size: 9.96 KB / Downloads: 0)
My English is poor, and if I made any mistakes, please forgive me.Tongue
Reply
04-08-2013, 12:37 PM,
#2
RE: Problem using BULKputs(char *buffer, byte length)
Hi Jacky,
Side Pinguino board I propose to you the attached usb_blink0.1.pde.
Usually with Processing we use USB.available(), USB.read(), USB.send() which are found in p8\pinguino\libraries\usb.c, last revision (alias usbavailable(), usbread() ,usbsend())

Today this usb.c works only with bootloader v2.12.

Unfortunately I could only test blink0.1.pde with a C-program compiled with Mingw or a Python program.
2 years (and +) ago I could work with processing +pinguino but today I meet problems with libusb0.dll (timeout ?)

I hope this can help you.
André

(28-07-2013, 08:24 AM)JackyZai Wrote: Hi guys,

I'm trying to communicate my PIC with Processing through usb bulk transfer.
My pinguino is able to read data from Processing but not send data to Processing, the library I use is __bulk.c.

The function used to send data is:
BULKputs(char *buffer, byte length)

Device: Pinguino 4550
Bootloader: v2.12 and v4.9
IDE version : x4-easy-rev857
Operating System: Windows 7

There is a fix in usb_config.c by me
///////////////////////////////////////
usb_config.c changes
///////////////////////////////////////
#ifdef USB_USE_BULK
__code USB_Configuration_Descriptor libconfiguration_descriptor = {
// Configuration Descriptor Header
{sizeof(USB_Configuration_Descriptor_Header),// Size of this descriptor in bytes
CONFIGURATION_DESCRIPTOR, // CONFIGURATION descriptor type
sizeof(USB_Configuration_Descriptor),// Total length of data for this configuration //This line has been fixed
///////////////////////////////////////

///////////////////////////////////////
Pinguino side program:
///////////////////////////////////////
#include <__bulk.c> //include bulk transfer library

void BULKwrite(u8 c) //function to write a single byte
{
BULKputs(&c, 1);
}

void setup()
{
pinMode(7, OUTPUT); //set RB7(led) as digital output pin
}

u8 command[]; //variable to store received data

void loop()
{
BULKgets(command); //read bulk
if(command[0] == '0')
{
//if data = 0 turn off led and send 0x09 to Processing
digitalWrite(7,LOW);
BULKwrite(9);
}
else if(command[0] == '1')
{
//if data = 1 turn on led
digitalWrite(7,HIGH);
}
}
///////////////////////////////////////

///////////////////////////////////////
Processing side program:
//////////////////////////////////////
import hypermedia.pinguino.*; //import pinguino library

Pinguino board; //pinguino object

void setup()
{
board = new Pinguino(this); //connect to Pinguino board
}

byte[] write_1 = new byte[] {'1'};
byte[] write_0 = new byte[] {'0'};
byte[] response = new byte[1];

void draw()
{
board.write( write_1 );
delay(500);
board.write( write_0 );
readpinguino();
delay(500);
println();
}

void readpinguino() // get Pinguino's response
{
response = board.read( response );
while(response == null)
{
response = board.read( response );
}
println( str(response) );
}
///////////////////////////////////////

Its been a month I'm trying to solve this problem, but I'm getting out of time to complete my project so I decided to ask for help.

Jacky,
Thanks.


Attached Files
.pde   usb_blink0_1.pde (Size: 385 bytes / Downloads: 4)
Reply
04-08-2013, 05:50 PM, (This post was last modified: 04-08-2013, 06:03 PM by JackyZai.)
#3
RE: Problem using BULKputs(char *buffer, byte length)
Hi Andre,

Thank you. I'm able to fix Pinguino x4 IDE main.c to work with USB.available(), USB.read(), USB.send() which are functions depend on bootloader v2.12 and it works well with Processing(libusb library).

But actually I want to communicate my Pinguino(pic) with LabVIEW.
bootloader v2.12,USB.available(), USB.read(), USB.send():
I tried using bootloader v2.12 but the endpoints are not detected by LabVIEW due to its Configuration Descriptor: wTotalLength: 0x12 which supposed to be 0x20. So LabVIEW cannot communicate with Pinguino and this library is not suitable for LabVIEW.

p8\pinguino\libraries\__bulk.c:
I tried using __bulk.c library which its root USB library is same with CDC. By using this library, LabVIEW is able to detect the endpoints and control the LED connected to Pinguino; in the other words Pinguino is able to read from LabVIEW.
But Pinguino is not able to write to LabVIEW, by using BULKputs(char *buffer, byte length) function. Same applies to Processing.

So in order to communicate my Pinguino with LabVIEW I think BULKputs(char *buffer, byte length) function has to be fixed.

Due to project submission date is near, currently I am controlling Pinguino with Processing using USB.available(), USB.read(), USB.send() without problem.

Andre again thank you very much for reply.
Jacky.


(04-08-2013, 12:37 PM)gtcbreizh Wrote: Hi Jacky,
Side Pinguino board I propose to you the attached usb_blink0.1.pde.
Usually with Processing we use USB.available(), USB.read(), USB.send() which are found in p8\pinguino\libraries\usb.c, last revision (alias usbavailable(), usbread() ,usbsend())

Today this usb.c works only with bootloader v2.12.

Unfortunately I could only test blink0.1.pde with a C-program compiled with Mingw or a Python program.
2 years (and +) ago I could work with processing +pinguino but today I meet problems with libusb0.dll (timeout ?)

I hope this can help you.
André
My English is poor, and if I made any mistakes, please forgive me.Tongue
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)