?
Solved

Convert file to bitstream and send thru serial port

Posted on 2003-03-30
7
Medium Priority
?
558 Views
Last Modified: 2013-11-15
I am to read a m2v file and send it thru serial port. The mpeg2decoder that i am using reads a bunch of bytes at a time( say n) . I want to read the m2v file 'n' bytes at a time and then send it thru a serial port to an FPGA board where a decoder will be running. How should i go about it ?

Problems :
(1) I am facing problems in reading a file in 'n' bytes at a time.
(2) Even if i am successful in doing that, how do i send it thru a serial port (say a modem port coneected to an FPGA)

Thanx in advance. Help me out pls.

Email : anshuman4u@rediffmail.com
0
Comment
Question by:anshuman4u
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 5

Expert Comment

by:Kocil
ID: 8233753
The first problem is easy.
#define NDATA 1024

main()
{
  FILE *f;
  char data[NDATA];
  int nread;
 
  f=fopen("MYDATA.DAT", "r+b");
  do {
     nread = fread(f, NDATA, 1, data);
     /* you got the data as many as nread (max = NDATA)
        should be less at the end of file */

    /* do something with your data */

  } while (!feof(f));
  fclose(f);
}

The second is a little bit complex.
What computer/OS/compiler are you working on ?

0
 
LVL 5

Accepted Solution

by:
Kocil earned 60 total points
ID: 8233760
And what is FPGA ?
Does it have a standard protocol to receive the file (say kermit or xmodem), or will you write a receiver program for it too ?
0
 
LVL 2

Expert Comment

by:Francoz
ID: 8237715
Use one array of kind as follows

unsgined char DATA[MAX_SIZE];

Depends on the device connected at the serial port decide the transfer method of data.
If you want to send the data bit by bit do something as follows.

//Get the data
unsigned char data = DATA[i];

The output of below code will be a binary string equivallent to  the data we got from DATA array.

char *convertobinary()
{
     unsigned char ch = ( unsigned char ) num ;
     unsigned char mask = UCHAR_MAX - ( UCHAR_MAX >> 1 ) ;
     static char result [CHAR_BIT + 1] ;
     char *store = result ;
     
     while ( mask )
     {
         
          *store++ = ( char ) ( '0' + ( ( ch & mask) != 0 ) ) ;
          mask >>= 1 ;
         
     }
     
     *store = '\0' ;
     return result ;
}

  Use the binary string to encode bit stream to be sent to the output. Now use C apis of outp or outport to emit data to the port.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Expert Comment

by:sheeparegreat
ID: 8238128
A FPGA is a Digital logic device it stands for Field Programmable Gate Array.

You can think of it as a big digital microcontroller.

FPGA's can be programmed with software to be any digital circuit element you want.  They can be programmed in VHDL (visual hardware description language) or sometimes in a schematic form.  

The software required to program the FPGA is usually very expensive.  At my university we use Xilinx FPGA's and their sofware.

FPGA's contain millions of logic gates and there are joined together by the software (during programming the chip) to give the functionality required.

In my experience with them I have made a RS232 monitor and various other 'State Machines'.  They are very flexable and you can create pretty much whatever you like.

As far as protocol, the FPGA does whatever it is programmed to.  (Depending on the board that its attached to and its inputs).

You will have to look at what the board does and see how the FPGA's been programmed.

Hope this helps
0
 
LVL 2

Expert Comment

by:Francoz
ID: 8243418
If you're device willing to take bits coming at the port why cant you send the binary stream to the port? Do you've a standard adapter to connect to the RS232 port? If the voltage levels are matching you can pass bit by bit. If suitable encoding methods not present in the device you'll have to use IC555 for making the pulses in your requiremnts. Get the standard protocol first then make the frames to communicate. Once the frames are ready you can send them with standard APIs inp,outp etc. Or win32 apis WriteFile(). By protocol I meant there will be some start stop parity bit structures for your device.

0
 
LVL 20

Expert Comment

by:jmcg
ID: 10199304
Nothing has happened on this question in more than 9 months. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
accept answer by Kocil [grade B] (only partial answer).

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In our personal lives, we have well-designed consumer apps to delight us and make even the most complex transactions simple. Many enterprise applications, however, are a bit behind the times. For an enterprise app to be successful in today's tech wo…
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
XMind Plus helps organize all details/aspects of any project from large to small in an orderly and concise manner. If you are working on a complex project, use this micro tutorial to show you how to make a basic flow chart. The software is free when…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question