Sending hex codes via serial

My first post! I'm really liking tinkering with these boards!

So, my question: I currently control my samsung TV with some VB code running on a PC, and I'm trying to port that functionality over to my Arduino UNO. So far, I have not been successful. I have a button and an RS232 shifter from Sparkfun setup on the uno. I'm trying to use this code to send hex to the TV, but it does not seem to work. Any tips?

byte outgoingByte[]={0x08,0x22,0x00,0x00,0x00,0x01,0xd5};
byte incomingByte[]={0x00,0x00,0x00};

Serial.write(outgoingByte, sizeof(outgoingByte));
digitalWrite(ledPin, HIGH);
Serial.readBytesUntil(0x09, incomingByte, 3);

Where's the rest of your code?

Here it is:

int buttonState = 0;         // variable for reading the pushbutton status
byte outgoingByte[]={0x08,0x22,0x00,0x00,0x00,0x01,0xd5};
byte incomingByte[]={0x00,0x00,0x00};

void setup() {
  // put your setup code here, to run once:
    Serial.begin(9600); 
    // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
      Serial.write(outgoingByte, sizeof(outgoingByte));
      // turn LED on:
      digitalWrite(ledPin, HIGH);
      //Serial.write(0x08);
      //Serial.write(0x22);
      //Serial.write(0x00);
      //Serial.write(0x00);
      //Serial.write(0x00);
      //Serial.write(0x01);
      //Serial.write(0xd5);
      Serial.readBytesUntil(0x09, incomingByte, 3);
  } 
        else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
}

What have you done to see if the bytes are actually being sent? Also, does the remote expect a specific setup for the com link (e.g., baud rate, parity bits, etc)? Do those match the VB setup? What is the LED doing during your testing?

The TV requires 9600, 8 bits, no parity, 1 stop bit. I believe that is what uno puts out, so I'm good. I have plugged my setup into a USB-serial adapter to my laptop and used a hex-terminal program. I can see the message come through: 082200000001d5. What I can't tell is if the TV sends a packet back. There are both success and fail packets that can exist.

As for the LED, it is just a debug tool for me. What is weird is that my VB code, run from a PC, works great. I'm not really sure why the UNO doesn't. Here is what works in VB:

Module Module1

    Sub Main()
        'Code for display switch to HDMI 3 for 12 seconds
        ' Dim xmtBuf() As Byte = {&H8, &H22, &H0, &H0, &H0, &H1, &HD5}
        'Code for HDMI 3
        Dim xmtBuf1() As Byte = {&H8, &H22, &HA, &H0, &H5, &H2, &HC5}
        'Code for HDMI 1
        Dim xmtBuf2() As Byte = {&H8, &H22, &HA, &H0, &H5, &H0, &HC7}
        Dim rcvBuf(1024) As Byte

        Dim Port1 As System.IO.Ports.SerialPort
        Port1 = New System.IO.Ports.SerialPort

        Port1.PortName = "COM3"

        Port1.BaudRate = 9600

        Port1.StopBits = IO.Ports.StopBits.One

        Port1.DataBits = 8

        Port1.Parity = IO.Ports.Parity.None



        Port1.Open()

        Port1.Write(xmtBuf1, 0, xmtBuf1.Length)

        Port1.Read(rcvBuf, 0, rcvBuf.Length)

        System.Threading.Thread.Sleep(12000)

        Port1.Write(xmtBuf2, 0, xmtBuf2.Length)

        Port1.Read(rcvBuf, 0, rcvBuf.Length)

        Port1.Close()
    End Sub

End Module

Do you need to send a cr/lf at the end of the command being sent?

The documentation for the serial interface does not mention the need for a cr/lf, nor did my VB code require it. I do recall my VB code needing to read the TV's response packet before the TV would take action. I'm really not sure if my code is pulling the packet, so maybe I need to find a way to test for the return packet.

I just posted the below for somebody else. It shows how you might use the serial monitor to communicate directly with another gizmo, possibly like your tv.

Is the COM port in your IDE COM3? A long time ago I had a Visual Studio project using C# and had code like this:

  private string  SetComPort()
  {
    try
    {
      string[] ports = SerialPort.GetPortNames();
      foreach (string port in ports)
      {
        currentPort = new SerialPort(port, 19200);
        currentPort.PortName = port;
        serialPort1.PortName = port;
        currentPort.Parity = Parity.None;
        currentPort.DataBits = 8;
        currentPort.StopBits =  (StopBits) 1;

        if (currentPort != null)
        {
          portName = port;
          break;
        }
        else
        {
          return null;
          //lblPortSearch.Text = "No port found";
        }
      }
    }
    catch (Exception ex)
    {
      MessageBox.Show(ex.Message, "Error Reading Port");
    }
    return currentPort.PortName;
  }

that was used to get the COM port. I don't see you checking that COM3 is open and ready for use.

I'm pretty sure I have a hardware problem. When I plug my laptop into my arduino creation, I get the EXACT same hex being delivered over the serial as when I plug my working desktop with VB code into my laptop. I'm guessing the TV needs +/-12V and maybe my usb adapter for the laptop can deal with a less then optimal signal. Time to build one of these Max232's that I'm reading about!

EDIT:
Yup! Hardware problem. Turns out I needed the max232. The sparkfun rs232 shifter didn't cut the mustard. Thanks for the help everyone!!! I'm pretty stoked this is working now!!!