Hi Dave,
You can use the IrDAClient class to communicate out of your device using
the IrDA port. This class *is* supported with the 1.0 .NET CF. You will
be able to find a sample application and some discussion in the forthcoming
book .NET Compact Framework Kickstart by SAMS publishing, which should be
available in September.
If you don't want to use Socket semantics, you can use (IIRC)
IrDAClient.GetStream(). This gets you a stream through which you can read
and write data to the remote party. The tricky part is getting a
conneciton in the first place; there is a protocol you must follow.
Here is a small snippet of code that might give an idea. The sample
application in the book gives a full end-end demonstration, with both C#
and VB versions...
Hope this helps!
private void WaitForConnection()
{
try
{
IrDAListener l_IrDAListener = new IrDAListener("IRDA_CHAT_SERVER");
// Listen for anyone who wants to connect
l_IrDAListener.Start();
// And now pull the first queued connection request out as an IrDAClient
m_IrDAClient = l_IrDAListener.AcceptIrDAClient();
MessageBox.Show("Accepted a connection", "Ready to chat");
m_Connected = true;
// Now spin off a thread that will listen for data that comes in
through the IrDAClient connection...
this.m_listenerThread = new System.Threading.Thread(new
System.Threading.ThreadStart(ChatListener));
m_listenerThread.Start();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void ChatListener()
{
StreamReader l_StreamReader = null;
while (m_Connected)
{
l_StreamReader = new StreamReader(this.m_IrDAClient.GetStream(),
System.Text.Encoding.ASCII);
this.lbInText.Items.Add(l_StreamReader.ReadLine());
l_StreamReader.Close();
}
}
private void MakeConnection()
{
// In this method, we attempt to connect with another device which is
// waiting for a connection. We assume that the other device is
// called the "IRDA_CHAT_SERVER". We will tell users what devices are
// in range with a MessageBox and then hope that "IRDA_CHAT_SERVER" is in
// range.
const int MAX_DEVICES = 5;
try
{
this.m_IrDAClient = new IrDAClient();
bool l_foundAnyDevice = false;
// Find out who's out there to connect with...
IrDADeviceInfo[] l_DevsAvailable =
m_IrDAClient.DiscoverDevices(MAX_DEVICES);
// Show a MessageBox telling user every device we see out there
foreach (IrDADeviceInfo l_devInfo in l_DevsAvailable)
{
l_foundAnyDevice = true;
MessageBox.Show(l_devInfo.DeviceName, "Discovered IrDA device");
// Now try to connect to the devices, hoping it offers a service named
"IRDA_CHAT_SERVER"
try
{
// Assume that first device is offering a service that we want
IrDAEndPoint chatEndPoint = new
IrDAEndPoint(l_DevsAvailable[0].DeviceID, "IRDA_CHAT_SERVER");
m_IrDAClient.Connect(chatEndPoint);
MessageBox.Show("Connected to chat server!", "Ready to chat");
m_Connected = true;
break;
}
catch (SocketException exc)
{
}
}
if (l_foundAnyDevice)
{
// Now spin off a thread that will listen for data that comes in
through the IrDAClient connection...
this.m_listenerThread = new System.Threading.Thread(new
System.Threading.ThreadStart(ChatListener));
m_listenerThread.Start();
}
else
{
MessageBox.Show("No devices found to chat with!", "Cannot chat");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
-- Erik
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| From: "daveH" <
[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.compactframework
| Subject: Looking for IrCOMM sample code
| Date: Thu, 7 Aug 2003 23:37:02 -0400
| Lines: 18
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
| NNTP-Posting-Host: ppp-52-24.sher.aei.ca
| Message-ID: <3f331bc8_4@aeinews.>
| X-Trace: aeinews. 1060314056 ppp-52-24.sher.aei.ca (7 Aug 2003 23:40:56
-0400)
| Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!news-out.cwix.com!newsfeed.cwix.co
m!newsfeed1.cidera.com!Cidera!aeinews.
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.compactframework:30454
| X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
|
| -1-
|
| I'm looking for IrCOMM sample code in c# OR vb.net . Any snippets will be
| helpfull ! Particularly on how to set the speed and establish a
| communication between two device. I don't wish to use IrSocket since I
will
| communicate with a microcontroller 'small memory' and I don't wish to mess
| with a network stack. It doesn't matter if the link speed is low. It will
be
| used to transfer 5-6 bytes remotely.
|
| -2-
|
| Also, I've read somewhere that the IrCOMM stack wasn't available in the
1.0
| version of the compact framework. It was added in the 1.1 release. Am I
| right ?
|
| Thank you,
|
|
|