Hi,
I've been able to communicate using HyperTerminal with my device via
serial port COM1. I just send a command and device switches on. I just
need that to start playing with it. This way, I understand device and
serial communication work wihout problems.
Now I want to do the same with C# code. As simple as that.
I open the serial port with the configuration manufacturer gives me,
send a command with Write() method and wait for data received event to
fire. I understand command is sent (no errors), but device is not
switched on and inmediatelly I data received event is fired. Here I
always get a "?" character, which seems to be an error character.
I'm using "Write", because in HyperTerminal I just type "DM" and device
responds. I also have tried with WriteLine() and so on.
This is my code, I would be very grateful if anybody could take a look
at it:
------------------------------------------------------------------------------------------------------------------
private void ReceiveData(obj ect sender, SerialDataRecei vedEventArgs e)
{
try
{
MessageBox.Show (serialPort.Rea dExisting());
}
catch (Exception ex)
{
MessageBox.Show (ex.Message);
}
}
private void ErrorInSerialCo mmunication(obj ect sender,
SerialErrorRece ivedEventArgs e)
{
MessageBox.Show ("ERROR!");
}
private void button1_Click(o bject sender, System.EventArg s e)
{
try
{
serialPort.Baud Rate = 9600;
serialPort.Stop Bits = StopBits.One;
serialPort.Pari ty = Parity.None;
serialPort.Data Bits = 8;
serialPort.Port Name = "COM1";
serialPort.Hand shake = Handshake.None;
serialPort.Data Received += new
SerialDataRecei vedEventHandler (ReceiveData);
serialPort.Erro rReceived += new
SerialErrorRece ivedEventHandle r(ErrorInSerial Communication);
serialPort.Open ();
serialPort.RtsE nable = true;
serialPort.DtrE nable = true;
serialPort.Writ e("DM");
}
catch (Exception exc)
{
MessageBox.Show (exc.Message);
}
}
Manufacturer tells me about FlowControl = None, I understand that
matches with Handshake = None.
Thanks very much for all your help. It's really urgent.