 |
|
|
Topic: inbuffercount is more than when rthreshhold is set to 1
|
By: Kiran | Posted on: Aug 8 2020 at 09:33:23 AM | serial data is around 20 bytes long string that keeps coming every second. Like S 30 G400
Receivethreshhold is set to 1 and the inputmode is text. I am expecting the oncom event to trigger for every character that I receive. I keep adding that character to a string to build my full string.
Select Case smcomm32.CommEvent 'should trigger for every char
Case comEvReceive
Text1.SelStart = Len(Text1.Text)
Text1.SelText = Now & " (" & MSComm1.InBufferCount & ")" & vbnewline
Now text1 reads 15, 12, 14 etc. Each time it is different. Text1 must be always 1 since receivethreshhold is 1.
After that, when I read the buffer using
myinput = SCommm32.Input
then len(myinput) is more than 1 always (7 or 8 characters) but seems to be less than inbuffercount. myinput must be a single character since threshhold=1
I am not clearing inbuffer manually. what is wrong? | |
By: Kiran | Posted on: Aug 8 2020 at 09:38:07 AM | ie: For MSCOMM this works correctly. When I set receivethreshhold =1 I get one event trigger per byte and .input will be just one character. But in scomm, I am not able to get this behaviour. For the same code, mscom gives me one character at a time for input property. For scom, inbuffercount is more than 1 and the string i read is 5 or 6 characters long. I am confused. same code for both controls. | |
By: James | Posted on: Aug 8 2020 at 11:23:06 PM | Rthreshhold will not work properly for reading each character separately even for low bauds atleast for some cables. It is better to use a while loop and read the entire buffer. But here you need to be careful. While looping through the buffer if another comreceive event is generated then there can be stack overflow issue. May be someone has a work around. Probably this is a driver issue. Some cables like Texas USB to serial is known to have this problem. | |
By: Guest | Posted on: Aug 25 2020 at 12:13:09 PM | rthreshold=1 means that an OnComm even is triggered as soon as one or more characters arrives in the receive buffer.
At a low baud rate that might mean that you appear to get the OnComm event and read the port and find only one character in the buffer. But that is NOT guaranteed. Different serial ports will behave differently. The computer processor might be busy. Some graphic controllers actually disable I/O for a moment. You basically have no control over what hardware your user is using so you can not assume that behaviour will work at all times. It's simply bad code.
Your code, even with working with MSComm, must assume that more characters might be available in the rx buffer and you must handle that. | |
By: Guest | Posted on: Aug 29 2020 at 12:53:48 PM | rThreshold does not limit the number of characters you'll get when you call .Input
If you want to limit the number of characters then set the .Inputlen property | |
|