Reputation: 345
I am attempting to serially communicate with a XM tuner. The tuner requires that a series of bytes be sent from the comport to control the tuner, an example of the command stream would be as follows: "B8,4D,18,30,20,B8". Initially, I attempted to send the command as a string (below), which did not work.
_Comport.Write("B8,4D,18,30,20,B8");
I also attempted to convert the command to a byte array, however this also was not effective.
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
Byte[] bytes = encoding.GetBytes("B8,4D,18,30,20,B8");
_Comport.Write(bytes,0,bytes.Length);
The comport is open and receives messages from the tuner; however I am at a loss as to how to transmit the stream of bytes to the tuner. Could someone kindly steer me as to how I need to communicate appropriately with the tuner?
Upvotes: 2
Views: 652
Reputation: 141703
If you want to literally send those as bytes, not an ASCII byte representation, you would do something like this:
var bytes = new byte[] { 0xB8, 0x4D, 0x18, 0x30, 0x20, 0xB8 };
_Comport.Write(bytes, 0, bytes.Length);
The 0x
in front of the numbers indicates to the compiler that they are hexadecimal numbers.
Upvotes: 6