Home > Archive > Smartphone Developer Forum > January 2005 > IrDA problem
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| ukpauls 2005-01-26, 4:00 pm |
| hoping for any advise! basically i am writing a small program that works
between 2 mobile phones, the idea is that it one phone sends a integer to the
over then the other replys.. and so on and so on... i used some sample code
in vb and got the very basics working... but i am trying to get this to work
in c#
i can get the sending integer to work in the c# program and the vb app (that
i know works) recieves the value.. the problem occurs when i try receive the
integer. and a error is genarated.
this is the receive method:
private int waitToReadIRData(byte[] Buffer, int BufferLen)
{
Status.Text = "Waiting for Number";
int BytesRead = 0;
IrDAListener listener = new IrDAListener(ServiceName);
IrDAClient client = null;
System.IO.Stream stream = null;
try
{
listener.Start();
client = listener.AcceptIrDAClient();// blocking call
stream = client.GetStream();
BytesRead = stream.Read(Buffer, 0, BufferLen);
}
finally
{
if (stream == null)
{
stream.Close();
}
if (client == null)
{
client.Close();
}
listener.Stop();
}
return BytesRead;
}
the error comes from the "BytesRead = stream.Read(Buffer, 0, BufferLen);"
as it has a ArgumentNullException.
yet it works in vb :S
any ideas?
| |
| ukpauls 2005-01-26, 4:00 pm |
| just thought i just point out that while debugging step by step each line, i
have noticed that the byte stream gets sent and is received but for some
reason we know the bufferlen but the buffer value is an <undefined value>
which is weird as the vb program can determine this value.
"ukpauls" wrote:
> hoping for any advise! basically i am writing a small program that works
> between 2 mobile phones, the idea is that it one phone sends a integer to the
> over then the other replys.. and so on and so on... i used some sample code
> in vb and got the very basics working... but i am trying to get this to work
> in c#
>
> i can get the sending integer to work in the c# program and the vb app (that
> i know works) recieves the value.. the problem occurs when i try receive the
> integer. and a error is genarated.
>
> this is the receive method:
>
> private int waitToReadIRData(byte[] Buffer, int BufferLen)
> {
> Status.Text = "Waiting for Number";
> int BytesRead = 0;
> IrDAListener listener = new IrDAListener(ServiceName);
> IrDAClient client = null;
> System.IO.Stream stream = null;
>
> try
> {
> listener.Start();
>
> client = listener.AcceptIrDAClient();// blocking call
> stream = client.GetStream();
>
> BytesRead = stream.Read(Buffer, 0, BufferLen);
> }
> finally
> {
> if (stream == null)
> {
> stream.Close();
> }
>
> if (client == null)
> {
> client.Close();
> }
> listener.Stop();
> }
> return BytesRead;
> }
>
>
> the error comes from the "BytesRead = stream.Read(Buffer, 0, BufferLen);"
> as it has a ArgumentNullException.
>
> yet it works in vb :S
>
> any ideas?
| |
| Alex Feinman [MVP] 2005-01-29, 3:57 am |
| How are you invoking this function? It sounds like you pass a variable for a
"Buffer" parameter that was not set to any value
--
Alex Feinman
---
Visit http://www.opennetcf.org
"ukpauls" <ukpauls@discussions.microsoft.com> wrote in message
news:AF63907B-27E4-4351-B332-73BEA7B32BFF@microsoft.com...[color=darkred]
> just thought i just point out that while debugging step by step each line,
> i
> have noticed that the byte stream gets sent and is received but for some
> reason we know the bufferlen but the buffer value is an <undefined value>
> which is weird as the vb program can determine this value.
>
> "ukpauls" wrote:
>
|
|
|
|
|