
Win95: Reading ASCII from Serial port with VB4 :(
Quote:
>I need to read a stream of ASCII data that is being fed to the serial
>port. This is Time Code from a professional video deck. The chunk I
>want to read is 11 bytes long.
>I want to press a button and see/save what the time code is at that
>instant.
>My question is two fold. The first has to do with the ASCII itself.
>The info word is 11bytes long for any one peice of time code
>information. Is ASCII serial data a streaming of single characters
Yes
Quote:
>that I read into an array? Do they get read into a string? Integer
>array?
It depends which read function you use. You can read into a string or
an integer array. Look at the input$() function in help.
Quote:
>If its a stream of characters do I have to take in a large chunk and
>then look for the first complete set withing the carriage returns or
>whatever the seperator is? I guess what I am asking is when you hit
>'save' what happens if its in the middle of a time code peice, or is
>there a middle, or are there only xxx number of bytes sitting in a
>buffer somwhere you read, that only changes when the next xxx number
>of bytes are in.
If you hit "Save" you would probably have a buffer full of all the time
code characters since the last time you hit save. And yes, the chances
are that the last few characters would be part of a time code.
Quote:
>Am I making this way more complex than it is?
No!
Quote:
>I am currently trying to do this with C++ under Win95 but its not
>working so I am looking for other solutions including Delphi and
>Visual Basic. How would you do this in Delphi or VB?
I would consider two methods, depending on how frequent the time codes
are. Are they frequent enough for you to start monitoring characters
when START is pressed, wait for the CRLF at the end of the current part-
string, then read 11 bytes and check that they end with another CRLF?
If so, I would:-
Sub Start_Click
Open "com4" for Input As #1
Line Input #1,A$: Rem Read the part-code
Line Input #1,A$: Rem Read the time code
If Len(A$) = 11 then ...
Close #1
End Sub
If you want it to happen faster than that, you would need to have two
tasks running simultaneously (which you can in VB).
AT the end of your Sub Form_Load, just before End Sub, put:
Show
Open "com4" for Input As #1
Do
Line Input #1,TimeCode$: Rem Read the Time code
DoEvents
Loop
End Sub
The "Show" command would display your form and then the rest of the
routine would stick in a permanent loop updating the variable TimeCode$.
Meanwhile your START button would be clickable, so within Start_Click
you could have:-
Sub Start_Click
Do whatever you want with TimeCode$
End Sub
Quote:
>In C++.....
Far too complicated!
--
Peter Hesketh
Turnpike evaluation. For information, see http://www.turnpike.com/