Sending a string/byte to the usb port

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2007
Posts: 6
Reputation: docdoc is an unknown quantity at this point 
Solved Threads: 0
docdoc docdoc is offline Offline
Newbie Poster

Sending a string/byte to the usb port

 
0
  #1
Nov 11th, 2007
The following bit of code is to send a string of data to the usb port. How can I modify the code so I only send one byte of data to the usb port instead of a string?

private void usb_OnSpecifiedDeviceArrived(object sender, EventArgs e)
{
this.lb_message.Items.Add("My device was found");

//setting string form for sending data
string text = "";
for (int i = 0; i < this.usb.SpecifiedDevice.OutputReportLength - 1; i++)
{
text += "000 ";
}
this.tb_send.Text = text;
}

private void btn_send_Click(object sender, EventArgs e)
{
try
{
string text = this.tb_send.Text + " ";
text.Trim();
string[] arrText = text.Split(' ');
byte[] data = new byte[arrText.Length];

for (int i = 0; i < arrText.Length; i++)
{
if (arrText[i] != "")
{
int value = Int32.Parse(arrText[i], System.Globalization.NumberStyles.Number);
data[i] = (byte)Convert.ToByte(value);
}
}

if (this.usb.SpecifiedDevice != null)
{
this.usb.SpecifiedDevice.SendData(data);
}
else
{
MessageBox.Show("Sorry but your device is not present. Plug it in!! ");
}

}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 103
Reputation: mariocatch is an unknown quantity at this point 
Solved Threads: 17
mariocatch mariocatch is offline Offline
Junior Poster

Re: Sending a string/byte to the usb port

 
0
  #2
Nov 13th, 2007
please use code tags im getting a headache reading that.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3
Reputation: nivek564 is an unknown quantity at this point 
Solved Threads: 0
nivek564 nivek564 is offline Offline
Newbie Poster

Re: Sending a string/byte to the usb port

 
0
  #3
Nov 19th, 2007
i
Last edited by nivek564; Nov 19th, 2007 at 11:44 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 9
Reputation: doleh is an unknown quantity at this point 
Solved Threads: 1
doleh's Avatar
doleh doleh is offline Offline
Newbie Poster

Re: Sending a string/byte to the usb port

 
0
  #4
Aug 3rd, 2008
do you use apackage or namespace named usb
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC