From: Rick Lones on
Antonio,

You need to supply a lot more detail:

Antonio Feliziani wrote:
> HI,
> i hve a problemi whit a little serial port proxi application,
> the application send the byte recivedo from port1 to port 2 and from
> port 2 to port 1

So it sounds like your application is a transparent pipe between ports 1 and 2
and does not want to know the protocol being spoken, is that correct? What is
connected to port1? What is connected to port2? Are you sure that whatever is
connected to your ports has opened those ports from their side before you start
shoveling bytes?


> before i whant see the comunication and send command to my device.
>
> I see the comunication ..send and recived the message but the
> application not open connection whit the device correctly
>

Who did the sending? Who did the receiving? In your example below, it looks
like whatever comes in port 1 is echoed out port 2. Is the device connected to
port 2 failing to see the echoed bytes? Is that the problem you are having?

What exactly do you mean by "the application not open connection whit the device
correctly"? Do you refer to your application or to one running on the other
side of one of the ports? Do you mean an error is thrown? If so, which one?
(And please show the routine which throws it and indicate which line.) If not,
how do you know the connection is not open correctly? You can really only know
the state of things on your side of the port.

> My source code:
>
> all'evento serialPort1_DataReceived
>
> lock (bju)//bju.. ojb che mi serge giusto per fare il lock
> {
> List<byte> bBuffer = new List<byte>();
> while (serialPort1.BytesToRead > 0)
> bBuffer.Add((byte)serialPort1.ReadByte());
>
> serialPort2.Write(bBuffer.ToArray(), 0, bBuffer.ToArray().Length);
> bBuffer.Clear();
> }

If this is really the code then I don't see why you need a lock here (or a
List<byte> either), but nevertheless it looks like this routine should indeed
echo bytes from port 1 to port 2. (Unless port 1 is sending bytes so quickly
that your while loop never terminates.) I assume there is a similar handler for
bytes received at port 2 which echoes them to port 1?

> i have try also :
>
>
> byte[] BytesLetti = new byte[1000];
> int iBytesLetti = serialPort1.Read(BytesLetti, 0, 1000);
> byte[] BytesToBridge = new byte[iBytesLetti];
> Array.Copy(BytesLetti, BytesToBridge, iBytesLetti);
> serialPort2.Write(BytesToBridge, 0, iBytesLetti);

Pretty much the same thing, let's work with the first one . . .

> what is the possible problem?

I assume you have already considered the usual serial communications suspects?
(Baud rate, parity, data bits, stop bits, flow control, need for null modem,
etc.) If not, now is the time to be sure of all of those before pointing the
finger at your application.

Some protocols (e.g. Modbus-RTU are timing sensitive. It might not be possible
to put a gateway between them for that reason.

HTH,
-rick-
 | 
Pages: 1
Prev: Rot13
Next: Entity, problem with entity key