SEARCH
TOOLBOX
LANGUAGES
Register    Login    Forum    Search    FAQ

Board index » Electronics Projects » PIC microcontroller projects




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: How to read potentialmeter value from the device ?
 Post Posted: Thu Feb 16, 2012 8:45 pm 
Offline

Joined: Thu Sep 29, 2011 4:18 pm
Posts: 51
Can anyone please teach me how to receive the value of potentialmeter from the device !
I had try to write but i don't think it can work and i haven't try it .

public bool readpotential()
{
bool buttonState = false;

if (isDeviceAttached)
{
// Declare our output buffer
Byte[] outputBuffer = new Byte[65];

// Declare our input buffer
Byte[] inputBuffer = new Byte[65];

// Byte 0 must be set to 0
outputBuffer[0] = 0;

// Byte 1 must be set to our command
outputBuffer[1] = 0x83;

// Perform the write command
bool success;
success = writeRawReportToDevice(outputBuffer);

// Perform the read
success = readSingleReportFromDevice(ref inputBuffer);

// Was the read successful?
if (!success) return false;

// Set the returned button state flag
if (inputBuffer[2] == 1) buttonState = true;
else buttonState = false;
}

return buttonState;
}

Please give commends on the code i wrote and learned from Sir Simon Inns. Thank


Top 
 Profile  
 
 Post subject: Re: How to read potentialmeter value from the device ?
 Post Posted: Fri Feb 17, 2012 5:54 am 
Offline

Joined: Thu Apr 01, 2010 6:23 am
Posts: 893
The following part of the code is the bit that you need to change:

// Set the returned button state flag
if (inputBuffer[2] == 1) buttonState = true;
else buttonState = false;

Here the code expects a value of either 0 or 1 in inputBuffer[2] which is the state of a button on the device. You would need to change this to read a value (say 0-255) which represents the position of your potentiometer.

On the device side you would have to perform an ADC on the potentiometer when the command(0x83) is received and place the result into the send buffer.


Top 
 Profile  
 
 Post subject: Re: How to read potentialmeter value from the device ?
 Post Posted: Fri Feb 17, 2012 4:02 pm 
Offline

Joined: Thu Sep 29, 2011 4:18 pm
Posts: 51
Sorry for late reply . Sir , how can i change the code to read a value (say 0-255) which represents the position of the potentiometer.

isn't ?
// Set the returned button state flag
if (0 >= inputBuffer[2] <= 255 ) buttonState = true;
else buttonState = false;


Top 
 Profile  
 
 Post subject: Re: How to read potentialmeter value from the device ?
 Post Posted: Fri Feb 17, 2012 5:42 pm 
Offline

Joined: Thu Apr 01, 2010 6:23 am
Posts: 893
Please don't take this the wrong way, but it looks like you need to learn some basic C# programming before attempting this. You will probably find this a lot easier if you took the time to read a book on C# or followed some basic web tutorials. If you know C or C++ it's very easy.

You will need at least a working knowledge of C# to use the USB host library.

/Simon


Top 
 Profile  
 
 Post subject: Re: How to read potentialmeter value from the device ?
 Post Posted: Fri Feb 17, 2012 6:12 pm 
Offline

Joined: Thu Sep 29, 2011 4:18 pm
Posts: 51
Sorry for i have lack of time to study all the C# programming now.. :cry: I will further study on C# programming after i graduate from my college ! By the way , I actually not really understand how ur code work on READ process . On the device side , an ADC on the potentiometer when the command(0x83) is received and place the result into the send buffer. How to receive the value of potentialmeter(say 0-255) ?

Please explain on this .. :cry:


Top 
 Profile  
 
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 5 posts ] 

Board index » Electronics Projects » PIC microcontroller projects


Who is online

Users browsing this forum: Bing [Bot] and 1 guest

 
 

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Translated by MaĆ«l Soucaze © 2009 phpBB.fr