Unsuccessfull serial communication with CF 2.0

L

Lonifasiko

Hi,

I must communicate my PDA with a device via serial communication. The
device brings a cable ready for that, and in order to provide a seriaI
port to my PDA, I bought this cable:
http://www.cablematic.com/index.php?_cl_id=1&fam=128&p=25&pp=&mode=1&id=90&fam=128&pag=2&p=25

Well, I have some specifications from my manufacturer. They are related
for device-PC (not PDA) communication via serial port, but I suppose
they will be the same for device-PDA coomunication. I sum up them:

Baud Rate = 9600 bps Data Bits = 8
Stop Bits = 1 Parity = none
Flow Control = None Com Port = port utilized (I'm trying with "COM1")

And here are another conditions:
1. The computer must assert (apply a positive RS-232 voltage to) RTS
and/or DTR. Either or
both of these signals supply power to the cable circuitry.
2. The computer may leave RTS "open" but may not drive it to a negative
RS-232 level.
3. The computer communications port must be set to 9600 baud, 8 data
bits, no parity, and one
stop bit.

I've been able to open the serial port on COM1, and send a command
specified by the manufacturer (no error indeed) that should wake up the
device, but I'm not seeing any result on the device's screen.
I've carefully followed the manufacturer's specifications and I'm using
CF 2.0 with System.IO.Ports.SerialPort class. This is my code:

-------------------------------------------------------------------------
SerialPort sp = new SerialPort();
sp.BaudRate = 9600;
sp.StopBits = StopBits.One;
sp.Parity = Parity.None;
sp.DataBits = 8;
sp.PortName = "COM1";
sp.RtsEnable = true;
sp.DtrEnable = true;
//sp.Encoding = Encoding.ASCII;
//sp.Handshake = Handshake.None;

try
{
sp.DataReceived += new
SerialDataReceivedEventHandler(this.ReceiveData);
sp.ErrorReceived += new
SerialErrorReceivedEventHandler(this.ErrorInSerialCommunication);
sp.WriteTimeout =
System.IO.Ports.SerialPort.InfiniteTimeout;
sp.Open();
sp.WriteLine("DMP");
MessageBox.Show("Command sent");
}
catch (Exception exc)
{
MessageBox.Show(exc.Message);
}


private void ReceiveData(Object sender, SerialDataReceivedEventArgs e)
{
MessageBox.Show("Receive Data");
}

-----------------------------------------------------------------------------------------

Hope you can see something that is not letting me communicate properly
with the device.

Thanks very much in advance.
 
L

Lonifasiko

Hi again,

from Microsoft's documentarion about SerialPort class:
"Use this class to control a serial port file resource. This class
provides SYNCHRONOUS and event-driven I/O, access to pin and break
states, and access to serial driver properties "

Only synchronous I/O? Asynchronous would not be supported by this
class? I've noticed specification from device's manufacturer also tells
me this:

"The device supports ASYNCHRONOUS, RS-232 communications via the data
port at 9600 baud only.
Data are transferred as 8-bit characters with no parity and one stop
bit. Communication is via three-wire (RS-232
designations of BA, BB, AB) cable."

So I'm seeing an incompatibility right now. Can anybody explain me this
and give me a clear solution?

Thanks.
 
G

Guest

Does your device support DTR or RTS? Not al UARTs do.

As for the synchronous v. asynchonous, the docs are wrong. RS232 by
definition is asynchronous and I know that the serial classes will not work
for synchronous serial.

-Chris
 
L

Lonifasiko

Hi Chris,

Thanks for your interest. What do you mean by UART? This is what I can
tell you:

"supports asynchronous, RS-232 communications via the data port at 9600
baud only.
Data are transferred as 8-bit characters with no parity and one stop
bit. Communication is via three-wire (RS-232
designations of BA, BB, AB) cable."

and.....

"The following conditions must be met:
1. The computer must assert (apply a positive RS-232 voltage to) RTS
and/or DTR. Either or
both of these signals supply power to the cable circuitry.
2. The computer may leave RTS "open" but may not drive it to a negative
RS-232 level.
3. The computer communications port must be set to 9600 baud, 8 data
bits, no parity, and one
stop bit."

Therefore you mean that after knowing RTS or DTR, I would be able with
CF 2.0 SerialPort class to send and receive data via serial port?
I'm using event driven communication like this:

sp.DataReceived += new
SerialDataReceivedEventHandler(this.ReceiveData);

I understand that after sending the specific command I need with Write
or WriteLine(), if device sends me back something, ReceiveData method
should be called.

Thanks very much.
 
G

Guest

Your device requires voltage on RTS or DTR. I'm saying that the UART used
for the serial port on your device may not support them, and the
manuafacturer therefore would not have run any signals. The port could
still send and receive data, it just can't support the handshaking lines.
You have to check with the OEM.

-Chris
 
L

Lonifasiko

Chris,

I've connected the device to my PC, using COM1 serial port.
I'm able to run HyperTerminal , send commands and see what the device
is returning. The configuration of hyperterminal, as you will know,
it's really simple:
just establish parity, stop bits, flow control, data bits, port name
and baudrate........and works!

I've also built a little example application in Winforms and
ReceiveData event is correctly fired after I've sent a command.
However, the value I read is not the value I expected. In all examples
they say "ReadExisting()" method is enough to read all data. This
method only gives me a "?" character, when I expect al least 20
characters.

Any other good way to read received data?

Thanks.
 
J

Joseph Byrns

I think the trouble here is likely that the RTS pin on the PDA is not high
(i.e. does not provide a voltage supply). On the other hand I guess a PC
always provides a voltage to this pin (even though hardware flow control is
not enabled). I don't have the relevant connections to test this.

Judging from what you have written it would seem the other device gets its
power from the RTS pin (RTS is pin 7 at the PDA/PC end). So for you to get
this to work with a PDA you may have to provide your own voltage (using a
battery presumably) to the RTS pin on the other device (infact as the PC RTS
pin connects to CTS on the other device you would need to provide a voltage
to pin 8 on the other device, with ground at pin 5).

HTH
 
D

DickGrier

Hi,

To follow up on what Joseph said, one problem may be that the RTS output
from your device has both too low a voltage level AND cannot drive the
current required. If you attempt to power an external device from a PPC
serial port (DTR and RTS), often you will fail. There simply isn't enough
power available on the output pins. Thus, you have to provide a separate
power supply for such devices.

Dick

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition, ISBN 1-890422-28-2, Mabry Publishing (391 pages, includes CD-ROM).
July 2004.
See www.hardandsoftware.net for details and contact information.
 
M

Markus Humm

Hello,

there are two things, one already mentioned:

1. the RS232 of the PDA might not supply any voltage, e.g. Acer n30
doens't supply any voltage (which is bad habbit), it "steals" it from
the PC.

2. often the cable for the pda rs232 is crossed, since a rs232
connection of two PCs (a PDA is like a PC in this case) requires a
crossed cable, but other devices (like a serial mouse) requires a
straight cable. "de-crossers" are available for purchase.

Greetings

Markus
 
L

Lonifasiko

Hi folks, thanks for your replies.

I'm afraid I'm quite lost in the hardware issues you are mentioning,
talking about pins, voltages and so on ;-)
From your replies, I understand the following:
1. The CompactFlash cable I've purchased provides a serial port for the
PDA but the problem is not here. The problem is that the PDA does not
provice any voltage to RTS or DTR pins of the CompactFlash slot.
2. You tell me to supply power to this pin externally. How? A battery
attached to the PDA? Tell me please (although I don't like the idea
very much).
3. The PDA I'm trying with is an iPAQ h5500. Are iPAQs so special for
serial communication?
4. I don't know about crossed cables and de-crossers. Could you give me
a good link based on the CompactFlash cable I mention above in the
post?
5. The problem could be because of the manufacturer's cable?

If I do not supply voltage to the mentioned pin, isn't there another
solution? Just I won't be able to achieve satisfactory serial
communication? I can't believe my eyes :(
I thougth serial communication did not depend so much on the PDA and on
the external device. I thougth the Compact Flash was the only thing I
need.

Thanks very much.
 
L

Lonifasiko

Why can I see in HyperTerminal the text the device is sending back to
PC via serial port and a simple Winforms application does nothing?

Simply returns me "?" character. I don't understand anything. And I'm
trying with the PC, not with the PDA. I see PDA communicating via
serial port almost impossible!

Bye..........
 
J

Joseph Byrns

Inline:
1. The CompactFlash cable I've purchased provides a serial port for the
PDA but the problem is not here. The problem is that the PDA does not
provice any voltage to RTS or DTR pins of the CompactFlash slot.
It is the CF card does not provide power to the RTS pin.
2. You tell me to supply power to this pin externally. How? A battery
attached to the PDA? Tell me please (although I don't like the idea
very much).
If you are not comfortable with this you should ask the manufacturers of the
serial device, or better still an electronics engineer, for advice on this.
3. The PDA I'm trying with is an iPAQ h5500. Are iPAQs so special for
serial communication?
Every serial device I have ever used has it's own power supply so would work
perfectly with your PDA, I am aware that some serial devices use RTS for
power but have never used any.
4. I don't know about crossed cables and de-crossers. Could you give me
a good link based on the CompactFlash cable I mention above in the
post?
5. The problem could be because of the manufacturer's cable?
You should get a volt meter and see if the pins at the end of your cable
provide a voltage (ground is pin 5 and RTS will connect to pin 8 at the
other end of the cable (which is infact CTS)). The pins are actually
numbered on normal serial cables (with little tiny numbers). If there is a
suitable voltage there then you have other problems (as Dick mentioned
perhaps there is insufficient power for your device, back to the
manufacturer again I am afraid).
If I do not supply voltage to the mentioned pin, isn't there another
solution? Just I won't be able to achieve satisfactory serial
communication? I can't believe my eyes :(
I thougth serial communication did not depend so much on the PDA and on
the external device. I thougth the Compact Flash was the only thing I
need.
Ordinarily the compact flash serial card may well have been the only thing
you needed, unfortunately in your case you have chosen a serial device that
requires power from the serial to work (which in my opinion is not the
norm).

Additionally, as you are using the iPaq h5500, why are you using a CF card
for the serial comms? You can get a serial cable for the h5500 that plugs
into the connector at the bottom of the PDA that gives you access to COM1 on
the PDA, you may find that this does provide the necessary voltages? (here
for example http://www.expansys.com/product.asp?code=109386 )
 
L

Lonifasiko

The cable you mention is just a synchronization cable via serial port
of the PC. It can substitute USB connection with the PC. I think this
it's different from providing the PDA a serial port. That's why I
bought the CF card. I also wrote a post for this in this newsgroup and
people advised me to buy the CF card.

Anyway, the cable you mention seems to have a female ending and I need
male ending. My device's cable ending is female, therefore I need male
ending for my cable.

Back to device-PC communication, to see wether communication
works......I send a command via hyperterminal and device switches
on.OK. Another command is sent and I got response.
If I do this, with the same configuration, from a Winforms application,
device is not switched on and always returns me "?", that seems to be
an error character.

This is my Winforms code (forget about Compact Framework for a moment),
see wether you can help me please:

private void ReceiveData(object sender, SerialDataReceivedEventArgs e)
{
try
{
MessageBox.Show(serialPort.ReadExisting());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

private void ErrorInSerialCommunication(object sender,
SerialErrorReceivedEventArgs e)
{
MessageBox.Show("ERROR!");
}


private void button1_Click(object sender, System.EventArgs e)
{
try
{
serialPort.BaudRate = 9600;
serialPort.StopBits = StopBits.One;
serialPort.Parity = Parity.None;
serialPort.DataBits = 8;
serialPort.PortName = "COM1";
serialPort.Handshake = Handshake.None;
serialPort.DataReceived += new
SerialDataReceivedEventHandler(ReceiveData);
serialPort.ErrorReceived += new
SerialErrorReceivedEventHandler(ErrorInSerialCommunication);
serialPort.Open();
serialPort.RtsEnable = true;
serialPort.DtrEnable = true;
serialPort.Write("DM");
}
catch (Exception exc)
{
MessageBox.Show(exc.Message);
}
}

I understand port must leave opened after sending the command.
ReceiveData event is fired but as I've said, always returns "?"
character.
I'm using Write() method instead of WriteLine(), because in
Hyperterminal don't need any return character. Just typing "DM", device
gets ready. With this example, not.

Please tell me if you see something suspicious. Thanks very much.
 
J

Joseph Byrns

Does it work if you leave out these lines?

serialPort.RtsEnable = true;
serialPort.DtrEnable = true;
 
L

Lonifasiko

Ok, I still have these two lines because of the CF example.
Manufacturer said to enable RTS and/or DTR, that's why I still had
them.

I've erased them but still device-PC example does not work. I'm really
getting worried with this issue.

Thanks very much.
 
D

DickGrier

Hi,
The cable you mention is just a synchronization cable via serial port
of the PC. It can substitute USB connection with the PC. I think this
it's different from providing the PDA a serial port. That's why I
bought the CF card. I also wrote a post for this in this newsgroup and
people advised me to buy the CF card.
<<

No, the internal serial port is a true serial port. It shares the connector
with USB but has no other hardware in common. The issue here is that the
serial cable FOR THE INTERNAL port is wired as a DCE. Thus, it can be used
to communicate with PC, but the cross over of Tx and Rx lines (and the
handshaking lines) means that you must insert a null-modem adapter in series
with the cable in order to connect it to a non-PC device. Also, the voltage
and current available on this port is quite limited, so furnishing power to
your device from the handshaking lines is problematic. To use this port as
a normal serial port, all you must assure is that ActiveSync does not
attempt to use it for synchronization. Use the PPC ActiveSync settings to
disable its use there. The internal serial port is Com1.

You ask how to furnish power to your device using an external power supply?
This requires a little skill with a soldering iron, a suitable power supply,
and two diodes (IN4001 will surely work). Total, probably about $10 at
Radio Shack. You can contact me offline for more information -- I'd need to
know more about your device to offer any exact details.

Dick

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition, ISBN 1-890422-28-2, Mabry Publishing (391 pages, includes CD-ROM).
July 2004.
See www.hardandsoftware.net for details and contact information.
 
D

DickGrier

Do you have an online link to the technical description for your device, or
can you email me a PDF or DOC? I don't mind looking at it more closely.

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition, ISBN 1-890422-28-2, Mabry Publishing (391 pages, includes CD-ROM).
July 2004.
See www.hardandsoftware.net for details and contact information.
 
L

Lonifasiko

Thanks very much Dick for your interest.

I'm now trying to communicate with the device from my PC. When I
achieve this, I will continue with the PDA-Device serial communication
and resume with you the cabling issue.
I'm also having problems to communicate via serial port from my PC.
Serial communication is hellish!

All you can follow my new post and help me here:

http://groups.google.es/group/micro...read/thread/3825a9c868d916d8/d27ecb402dd9e81a

Seems to be an encoding issue but I think I've tried everything!

Thanks very much.
 
D

DickGrier

Hi,

If you don't mind VB, I think I cover the subject fairly well in my book,
both for desktop and compact devices. You do have to get the details right,
and an understanding of the underlying hardware is REALLY helpful, both the
h ardware of the PC or PPC and the hardware in the actual serial ports --
along with the hardware and software requirements of the devices with which
you communicate. This last issue can be the real challenge. Often,
inexpensive devices have inadequate documentation. That's one of the
lessons that I use in my book, where I have examples that cover many of the
situations that I've encountered over the years. The theams seem to repeat.

Dick

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition, ISBN 1-890422-28-2, Mabry Publishing (391 pages, includes CD-ROM).
July 2004.
See www.hardandsoftware.net for details and contact information.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top