Serial Communication, vb.net
-
I have a problem here with receiving data from the serial COM port. The i received is not in full, example if i suppose to received "password" but u only display pass. I know it is something wrong with my buffer but in my code i did not specified my buffer. have anyone encounter similar problem?? How can i set the buffer size of my data received?
-
I have a problem here with receiving data from the serial COM port. The i received is not in full, example if i suppose to received "password" but u only display pass. I know it is something wrong with my buffer but in my code i did not specified my buffer. have anyone encounter similar problem?? How can i set the buffer size of my data received?
Hi, there are latencies (time delays) everywhere: in the target device, in the driver, in intermediate buffers. As a result you typically can't expect to get a DataReceived event and Read() an entire message; instead you may well read half a message, or even more than one message. There are two easy situations: 1. if messages are far apart (or you have to issue a command before a single message can come), then it suffices to incorporate a delay in between the DataReceived event and the Read() operation. The delay needs to exceed the normal transmission time for the given message length (This method creates a bandwidth limitation). 2. if data is text and each message/line ends on a fixed delimiter (see NewLine property), you can forgo the DataReceived event; instead use a separate thread that calls ReadLine() to get an entire line of text. In all other cases, you must organize your software yourself such that it knows how to collect bytes and extract messages from them. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in
-
Hi, there are latencies (time delays) everywhere: in the target device, in the driver, in intermediate buffers. As a result you typically can't expect to get a DataReceived event and Read() an entire message; instead you may well read half a message, or even more than one message. There are two easy situations: 1. if messages are far apart (or you have to issue a command before a single message can come), then it suffices to incorporate a delay in between the DataReceived event and the Read() operation. The delay needs to exceed the normal transmission time for the given message length (This method creates a bandwidth limitation). 2. if data is text and each message/line ends on a fixed delimiter (see NewLine property), you can forgo the DataReceived event; instead use a separate thread that calls ReadLine() to get an entire line of text. In all other cases, you must organize your software yourself such that it knows how to collect bytes and extract messages from them. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in
Actually i not sure if the complete output is shown. As i can only see part of it and the other part of it is missing. My buffer is 15 letters and it should be more den enough to fill the output. So if between the data received and read i do a sleep, will it works?
-
Actually i not sure if the complete output is shown. As i can only see part of it and the other part of it is missing. My buffer is 15 letters and it should be more den enough to fill the output. So if between the data received and read i do a sleep, will it works?
Subjugate wrote:
will it works?
with a larger buffer and more delay, it may or may not receive more data. If it is binary data, make sure to use a binary Read, not a text-oriented ReadLine which stops at the first CR, LF, NULL. If it is text data, you might try and receive the data with a terminal emulator (e.g. HyperTerminal) so you can see what gets received. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in
-
Subjugate wrote:
will it works?
with a larger buffer and more delay, it may or may not receive more data. If it is binary data, make sure to use a binary Read, not a text-oriented ReadLine which stops at the first CR, LF, NULL. If it is text data, you might try and receive the data with a terminal emulator (e.g. HyperTerminal) so you can see what gets received. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in
i already tried using hyper terminal before using my application. i know what is the result i am expecting but somehow when i used my application, the result i got is not complete. I tried changing some of the code and i test it again and it works and shown the complete result but when i test it the second time rd it fails again. I will show u might data received code below and see if u can help to see whether there is anything wrong with it. If port.bytesToRead > 0 then checkforillegalcrossthreadcalls = false Dimbytetoread as integer bytetoread = port.bytestoread Dim array as byte() = new byte(bytetoread - 1)() Dim linedata as string port.read(bytearray, 0, bytetoread) linedata = converttostring(bytearray) txtcommand.text = linedata port.close()
-
i already tried using hyper terminal before using my application. i know what is the result i am expecting but somehow when i used my application, the result i got is not complete. I tried changing some of the code and i test it again and it works and shown the complete result but when i test it the second time rd it fails again. I will show u might data received code below and see if u can help to see whether there is anything wrong with it. If port.bytesToRead > 0 then checkforillegalcrossthreadcalls = false Dimbytetoread as integer bytetoread = port.bytestoread Dim array as byte() = new byte(bytetoread - 1)() Dim linedata as string port.read(bytearray, 0, bytetoread) linedata = converttostring(bytearray) txtcommand.text = linedata port.close()
Hi, your code is no good; it probably would not compile, it certainly will not work
If port.bytesToRead > 0 then
checkforillegalcrossthreadcalls = false <<<<<<< never do this, it is BAD
Dimbytetoread as integerbytetoread = port.bytestoread
Dim array as byte() = new byte(bytetoread - 1)()
Dim linedata as string
port.read(bytearray, 0, bytetoread) <<<<<<< bytearray or array???
linedata = converttostring(bytearray) <<<<<<< use Encoding.ASCII.GetStringtxtcommand.text = linedata <<<<<<< use txtcommand.InvokeRequired pattern
port.close():)
Luc Pattyn [Forum Guidelines] [My Articles]
Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in
-
Hi, your code is no good; it probably would not compile, it certainly will not work
If port.bytesToRead > 0 then
checkforillegalcrossthreadcalls = false <<<<<<< never do this, it is BAD
Dimbytetoread as integerbytetoread = port.bytestoread
Dim array as byte() = new byte(bytetoread - 1)()
Dim linedata as string
port.read(bytearray, 0, bytetoread) <<<<<<< bytearray or array???
linedata = converttostring(bytearray) <<<<<<< use Encoding.ASCII.GetStringtxtcommand.text = linedata <<<<<<< use txtcommand.InvokeRequired pattern
port.close():)
Luc Pattyn [Forum Guidelines] [My Articles]
Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in
Thanks for all the comment. i know that it is bad to use checkforillegalcrossthreadcalls = false but this is really the last resort as i still cant understand multi-threading. Next, port.read(bytearray, 0, bytetoread), it is bytearray and a few line above should be Dim bytearray as byte.. Sorry for the typo error. Noted for the encoding.ASCII.getstring. thanks for the advise. For the 2nd last line i don't get u.. Care to explain??