943,779 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 13665
  • C# RSS
Nov 11th, 2007
0

Sending a string/byte to the usb port

Expand Post »
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());
}
}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
docdoc is offline Offline
8 posts
since Jun 2007
Nov 13th, 2007
0

Re: Sending a string/byte to the usb port

please use code tags im getting a headache reading that.
Reputation Points: 11
Solved Threads: 17
Junior Poster
mariocatch is offline Offline
103 posts
since Apr 2007
Nov 19th, 2007
0

Re: Sending a string/byte to the usb port

i
Last edited by nivek564; Nov 19th, 2007 at 11:44 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
nivek564 is offline Offline
3 posts
since Nov 2007
Aug 3rd, 2008
0

Re: Sending a string/byte to the usb port

do you use apackage or namespace named usb
Reputation Points: 8
Solved Threads: 1
Newbie Poster
doleh is offline Offline
9 posts
since Jul 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Alt-ctrl-del in vista
Next Thread in C# Forum Timeline: dictionary





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC