mu*****@sercomtel.com.br wrote:
I would like to know if can I work with DEX (I will transmit
information from my handheld to my PC) using this class? And if it's
possible for you, could you give a sample?
I'm not sure what DEX is. I have successfully used this class to
control ptz cameras and wireless bar code scanners. So, I don't see any
reason why it shouldn't work with your hardware.
Below is some sample code to open a the port and listen for data. It
assumes that the device sends ascii characters and that it terminates
the lines with a carriage return.
If your device has a binary protocol, you will probably want to use
SerialPort.Read() which can fill in an array of bytes.
There's also Write() and WriteLine() is you need to send data/commands
to the device.
using System;
using System.IO.Ports;
public class Example
{
private static SerialPort port;
public static void Main()
{
// setup the port
port = new SerialPort("com1",
9600, Parity.None, 8, StopBits.One);
port.NewLine = "\r";
// setup event handler
port.ErrorReceived += port_ErrorReceived;
// open port
port.Open();
Console.WriteLine("Port opened, waiting for data, " +
"press enter to quit");
Console.ReadLine();
port.Close();
}
private static void port_DataReceived(object sender,
SerialDataReceivedEventArgs e)
{
string line = port.ReadLine();
Console.WriteLine("Received: " + line);
}
}
--
David Hogue