0

I got myself some Kit-Starter code from google uploaded by someone else.

I hooked on my USB-Serial Cable and set my COM port to COM1.

When i build and ran it , it gave me error on this line, im not sure what's happening.

private int parseLGResponseHexa(string resp) {
        var splitter = new string[1];
        splitter[0] = "OK";
        String[] partes = resp.Split(splitter, StringSplitOptions.RemoveEmptyEntries);
        String naco = partes[1];
        String num = naco.Substring(0, 2);
        int decAgain = int.Parse(num, NumberStyles.HexNumber);
        return decAgain;
    }

Error At "String Naco = partes[1];"

MizLucid
  • 241
  • 1
  • 3
  • 9
  • Did `resp` contain the substring `OK`? If not `partes` will only have one element, so that line will be using an out-of-bounds array index. – pobrelkey Nov 07 '13 at 00:58
  • 1
    I'm wondering if you have the correct COM port. My experience with USB-Serial dongles is that they start at COM3 and go up from there. I would look in "Manage Devices" and see what comports you have and which one that is assigned (remove/insert to see the changes). Also look at http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.getportnames.aspx – kenny Nov 07 '13 at 01:47
  • 1
    Unless you're certain the array contains N elements, ALWAYS check before accessing element N-1: `if (partes.Length >= 2) { String naco = partes[1]; ... }` – groverboy Nov 07 '13 at 02:55

0 Answers0