Comm32 Logo
Home Button   

Topic:   Real time data using EvtChar is not working properly - missing CR in data sporadically

By: ShawnPosted on: May 14 2015 at 02:42:24 PM
What I wan to do is read the buffer into a string. But I want to only read it line by line into the string. The machine is generating the serial data and placing a CR character at the end of each line. I am implementing SComm32 in a Access 2007-2013 database via VBA 7.1

I have the settings in SComm32 to open my port matching the machine - 9600,N,8,1

Here is the data via RealTerm: (Each Line Ends With LF char AND CR char)


E 241 D 14.01.05 07:48:01
AUTOMATIC MODE
7145 THOUSAND
209 BRUSHES

E 242 A 14.01.05 07:48:01
TB3 STOPPED
7145 THOUSAND
209 BRUSHES


E 241 A 14.01.05 07:48:05
AUTOMATIC MODE
7145 THOUSAND
209 BRUSHES

E 242 D 14.01.05 07:48:05
TB3 STOPPED
7145 THOUSAND
209 BRUSHES

__________________________________________________________

My goal is to read one complete line at a time, using the CR character as the terminator real time.

So I am trying the comEvEventChar event.


When I implement the comEvEvtChar event, and I set the controls to:


SComm1.InputLen = 0
SComm1.RThreshold = 0 'I do not want any OnComm event but EvtChar, so I set to 0
SComm1.EvtChar = 10 'ASCII 10 is Carraige Return character



Here is my code for the OnComm event:

Case comEvEvtChar
CharRead = SComm1.Input


Debug.Print ("CharRead: " & CharRead & vbCrLf)



My output is below. As you will clearly see, the program seems to miss the CR character sent in real time. Sometimes it gets it... sometimes it does not. I get lines of data that are choppy and not correct to the stream you saw above.

I need this this to run live, and when I get the whole line of text I send it to a string and
manipulate the string.

Any thoughts on how to solve this?

Data output below line from Immediate Window in VBA:
_________



CharRead: E 241 D 14.01.05 07:48:01

AUTOMATIC MODE

7145 THOUSAND

CharRead:



CharRead: 209 BRUSHES

E 242

CharRead: A 14.01.05 07:48:01



CharRead: TB3 STOPPED



CharRead: 7145 THOUSAND



CharRead: 209 BRUSHES



CharRead: E 241 A 14.01.05 07:48:05

AUTOMATIC MODE

7145 THO

CharRead: USAND



CharRead: 209 BRUSHES

E 242

CharRead: D 14.01.05 07:48:05



CharRead: TB3 STOPPED



CharRead: 7145 THOUSAND



CharRead: 209 BRUSHES

By: ShawnPosted on: May 14 2015 at 02:44:56 PM
Oh, and you are seeing that right. Those are date time stamps but they are wrong. Ignore them. I just collected them today.

By: Guest Posted on: May 14 2015 at 07:56:47 PM
The evtChar property just gives you an event that tells you that theres a specific character in the receive buffer. By the time you respond to that event theres probably more data arrived so when you do sComm1.Input you'll get all data from the buffer and your character is going to be somewhere in the middle. Its up to you to split your data.

I'd respond to the evtchar event and input one byte at a time into a local string till i hit the CR and that would be the Line i want.