I have a running position or something like that I mean if I toggle the breakpoint before reading COM So everything is good but when I'm toggling it, it freeze. Write:
Send Public Zero (Com Message Message) {Byte [] bytes = Message. Seriali (); If (_outputPort.IsOpen) _outputPort.Open (); Try {byte [size] = bit sign. Getbyte (bytes lang); _outputPort.Write (size, 0, size. Length); _outputPort.Write (byte, 0, bytes lang); } Finally {if (_outputPort! _inputPort) _outputPort.Close (); }}
read
Private Zero InputportAdata received (Object Sender, SerialDataReceivedEventArgs serialDataReceivedEventArgs) {var port = (SerialPort) Sender; Byte [] shapebuffer = new byte [size (tall)]; Harbour. Read (size buffer, 0, size buffer lang); Int length = bit convertor toInt32 (size buffer, 0); Byte [] buffer = new byte [length]; Int i = 0; Whereas (i & lt; length) {int readed = port.Read (buffer, eye, length - i); I + = read; } Var Message = Com Message Diarrhea (buffer); Receive message (this, message); }
For example, the message has a length of 625 bytes. If I toggle a breakpoint, then port.BytesToRead
is equal to 625, but if I disable it, the byte count is 621.
Strange, but it works for little bytes (
Blockquote>
There is a length of 625 bytes in the message. If I toggle a breakpoint, the port bytes are equal to 625, but if I disable it, the byte count is 621 .
How many bytes you read before it can be read less than sizeof (long)
bytes. Problem problem There is no rote, your main problem is that you are making a size buffer long
but for a long time Int64
, you ToInt32
(and Due to a byte count is 261 instead of 265, because the first 4 bytes of your message size buffer [4]
via in the size buffer [7]
that you have never processed.
To fix this, you either have to type sizeof (int )
or even more Should Psht buffer ToInt32
to call, Akarf (Int32)
Comments
Post a Comment