fscanf for streamed I/O



I am in the process of porting some legacy code to vxworks and am
running into problems with reading from the port.

Here is what I have:

void test_routine()
{
    FILE *read;
    char buffer[300];

    if ((read = fopen("/tyCo/0", "r")) == NULL)
	printf("Packet INPUT port did not open");
    if (setvbuf(read, NULL, _IONBF, NULL))	/* unbuffered */
	printf("setvbuff(read, NULL, _IONBF, NULL) failed\n");

    while(1) {
 	fscanf(read, "\002%[^\003]\003",buffer); 	/* <STX>data<ETX> */
                printf("%s\n",buffer);
        }
}

This code always lags by one packet...
   * I send packet_A
        -->  no output
   * I send packet_B
        -->  packet_A displayed
   * I send packet_C
        -->  packet_B displayed
   * I send packet_D
        -->  packet_C displayed

Any ideas??  (We are attempting to continue using this same code on our
existing system, so I'd like to avoid completely rewriting it.)

jimzat

.



Relevant Pages

  • Re: PPC 2003 Thread
    ... // Create a read thread for reading data from the communication port. ... DWORD dwError; ... >> not get signaled and the Kernel Tracker tool shows that my main thread is ...
    (microsoft.public.windowsce.embedded.vc)
  • Serial port :bytesAvailable
    ... I am reading binary data from a serial port (it is actually ... have no problem reading data, I am reading data from an eye ...
    (comp.soft-sys.matlab)
  • Re: EAGAIN mystery on accept()
    ... Thanks a real lot Michael for reading my mail. ... lsof showed this to be the only process with a socket on this port ... > In an earlier post you said that tcpdump showed no incoming packets. ... > interface that you're not sniffing, ...
    (comp.unix.solaris)
  • Re: Write to file handle
    ... > port is reading) to a log file continuously .Can anybody help me how to do ... That's used for opening a file for reading ... use lexical filehandles, ... > #The line below declares it and ties it to the file handle INFILE ...
    (perl.beginners)
  • Re: pyserial and file open conflict?
    ... open a file on disk for reading and then open a com-port, ... from the file to the port and then read something back and compare it ...
    (comp.lang.python)