-1

I'm with trouble in +CDS return from channel. I'm using a modem with 64 channels and I need to get this value. This missing information in any lines above

+CDS: 6,248,"21988
+CDS: 6,249,"6299224415
+CDS: 6,39,"11974579414",129,"13/01/31,16:40:30-12","13/02/01,16:40:30-12",70
+CDS: 6,211,"2199678119",129,"13/01/31,16:40:31-12","13/02/01,16:40:31-12",70
+CDS: 6,51,"6
+CDS: 6,105,"11974579414",129,"13/01/31,16:40:32-12","13/02/01,16:40:32-12",70
+CDS: 6,40,"11973375726",129,"13/01/31,
+CDS: 6,106,"2199378635",129,"13/01/31,16:
+CDS: 6,251,"1297228284",129,"13/01/31,16:40:38-12","13/02/01,16:40:38-12",70
+CDS: 6,53,"2499482633",129,"13/
+CDS: 6,243,"2198922817",129,"13/01/31,16:40:45-12","13/02/01
+CDS: 6,253,"2198070285",129,"13/01/31,16:40:48-12","13/02/01,16:40:48-12",70
+CDS: 6,43,"2197371789",129,"13/01/31,16:40:51-12","13/02/01,16
+CDS: 6,170,"11975327641",129,"13/02/01,11:47:58-12","13/02/01,16:41:37-12",0
+CDS: 6,158,"1982067777",129,"13/02/01,17:36:31-08","13/02/01,17:36:34-08",0
+CDS: 6,46,"1992200437",129,"13/02/01,17:36:32-08","13/02/0
+CDS: 6,154,"4891019678",129,"13/01/31,17:52:44-08","13/01/31,17:52:45-08",70
+CDS: 6,254,"6296236810",129,"13/01/31,16:41:58-12","13/02/01,16:41:59-12",

I'm starting:

public PortaCOM(string porta)
    : base(porta, 115200, Parity.None, 8, StopBits.One)
{
    this.StatusPort = StatusPorta.Ready;
    this.DiscardNull = true;
    this.Handshake = Handshake.RequestToSend;
    //this.RtsEnable = true;
    //this.DtrEnable = true;
    //this.ReadTimeout = 12000;
    //this.ReadTimeout = 12000;
}

I get value using:

static void p_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
    var p = (PortaCOM)sender;
    try
    {

        int dataLength = p.BytesToRead;
        byte[] dados = new byte[dataLength];
        int nbrDataRead = p.Read(dados, 0, dataLength);
        if (nbrDataRead == 0)
            return;

        var retorno = Encoding.ASCII.GetString(dados);
        Console.WriteLine(retorno);
    }
    catch (Exception err) { Console.WriteLine(err.Message); }
}

Please, any help me!

Ricardo Beck

hlovdal
  • 26,565
  • 10
  • 94
  • 165
  • Is this a problem only with `+CSD`? What results do you get from other commands that produce lots of responses like `at+cpbr=1,200` or `at+cmgl=4`. – hlovdal Mar 30 '13 at 22:49
  • Hello, I fixed error creating a loop: var b = new List(); while (p.BytesToRead > 0) b.Add((byte)p.ReadByte()); if (b.IsEmpty()) return; var retorno = Encoding.ASCII.GetString(b.ToArray()) – Ricardo Beck Mar 30 '13 at 23:27
  • If the problem is solved, please write the solution as an answer. – hlovdal Mar 31 '13 at 08:54

1 Answers1

0

I changed inside p_DataReceived

    static void p_DataReceived(object sender, SerialDataReceivedEventArgs e)
    {
        var p = (PortaCOM)sender;
        try
        {

           **var b = new List<byte>(); 
            while (p.BytesToRead > 0) 
                b.Add((byte)p.ReadByte()); 
            if (b.IsEmpty()) 
                return;**

            var retorno = Encoding.ASCII.GetString(b.ToArray());

            Console.WriteLine(retorno);
        }
        catch (Exception err) { Console.WriteLine(err.Message); }
    }