Win95: Reading ASCII from Serial port with VB4 :( 
Author Message
 Win95: Reading ASCII from Serial port with VB4 :(

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
that I read into an array?  Do they get read into a string? Integer
array?

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.

Am I making this way more complex than it is?

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?

In C++.....

 I am using CreateFile and ReadFile, but nothing seems to happen.
(currently testing with a touch screen instead of vid deck)

I have tried a zillion different versions of the C++ code below.

HANDLE hSerl;

???????  ??Buffer;

BOOL bTest;

hSerl CreateFile("COM2", GENERIC_READ,  0,  NULL,  OPEN_EXISTING,
NULL, NULL);

bTest ReadFile(hSerl, ??Buffer, ??, NULL, NULL);

if(bTest)
{
        //Display ??Buffer

Quote:
}

// ReadFile always returns false. I have tried numerous versions of
// ??Buffer and the ?? size of bytes read.

I can find no reference in the documentation, at least none I
understand, or in books to know if "COM2"is the right thing to put in
the CreateFile function.

Any help would be greatly appreciated.

Thanks.

:)



Sun, 25 Apr 1999 03:00:00 GMT  
 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/



Tue, 27 Apr 1999 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. VB4 Serial Port Readings

2. Comm Overrun when playing sound while reading serial port (VB4.0)

3. How to loop comm port control to read text files through serial port in VB3

4. Receiving ASCII Values Through Serial Port

5. ASCII string from serial port

6. Serial Com Port ASCII(0)

7. Serial Com Port ASCII(0)

8. Sending ASCII out serial port

9. GW-Basic and Win95 Serial port problem

10. serial port communication under WIN95 using VB

11. Reading ASCII from COM port

12. I/O port, Parallel port, Serial port

 

 
Powered by phpBB® Forum Software