Author Topic: C# application interfacing with hardware device  (Read 2039 times)

0 Members and 1 Guest are viewing this topic.

gib65

  • Guest
C# application interfacing with hardware device
« on: March 24, 2012, 04:07:44 PM »
I've been ask to build a simple C# application that receives input from a hardware device. The hardware device is a sensor that sends out "packets" twice a second. It sends it to a USB device (something like a Blue Tooth) that's plugged into my computer. This is what my program needs to interface with. The USB device will provide my program with the packets it receives. The packets are 8 byte bit strings and each byte means something different.

My question is, if I were to build a function that takes one of these packets as an argument, what would be the best data type to use. The best thing I can think of is an 9 character string. Each character being 1 byte could be interpreted as one of the packet bytes and processes as such.

I'm not sure this is the best way to go about it though. I'm experienced in programming, but not very experienced in interfacing with hardware devices that broadcast data. Would YOU handle the packets as strings? Is there some other kind of data type I should use?

Thanks for the help.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: C# application interfacing with hardware device
« Reply #1 on: March 24, 2012, 06:04:40 PM »
I've only managed code that received data from COM ports, but I would suspect that the USB would be similar. The question for me wasn't how to interpret the data, but rather how do I read the data from the port?

There are several functions available that read port data, what you will need to determine is what data type is returned from the function you will use.

Personally, I would use a char array, but in C# it might be easier to use a string then parse it according to the format of the polled data from the device.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8767
  • AKA Daniel
Re: C# application interfacing with hardware device
« Reply #2 on: March 27, 2012, 11:04:19 AM »
Sounds like fun,
I don't think chars in .NET are one byte , I think they are two, so I might use UTF8 (byte) in a stream, then decode it.

gib65

  • Guest
Re: C# application interfacing with hardware device
« Reply #3 on: March 27, 2012, 11:40:16 AM »
Thanks both,

Turns out there's a data type for just this purpose: byte (which I knew about but forgot). So I'm declaring a byte array and using that to store and send info.