Skip to main content

Posts

Showing posts with the label Programming

python process real time output

Real Time Output Issue resolved: I did encountered similar issue in Python, while capturing the real time output from c program. I added " fflush(stdout) ;" in my C code. It worked for me. Here is the snip the code << C Program >> #include <stdio.h> void main () { int count = 1 ; while ( 1 ) { printf ( " Count %d\n" , count ++); fflush ( stdout ); sleep ( 1 ); } } << Python Program >> #!/usr/bin/python import os , sys import subprocess procExe = subprocess . Popen ( ".//count" , shell = True , stdout = subprocess . PIPE , stderr = subprocess . PIPE , universal_newlines = True ) while procExe . poll () is None : line = procExe . stdout . readline () print ( "Print:" + line ) << OUTPUT>> Print: Count 1 Print: Count 2 Print: Count 3 UPDATE:: The above one has flaws as we are reading only oneline per poll iteratio...

Cross Platform UI application with Python

Today I came to know about the open source software called wxPython . This has basic core libraries for the Windows, MAC, Linux. The user has to write the UI/code in python using these wxPython APIs. These APIs will be common across all platforms. You can easily port this code into other platforms. URL for wxPython: wxPython I am a novice for this.. Some time in future I might use this to create some cross platform apps... There is one more library called tkInter . This also looks cool. There is a python IDE which looks super cool with the black theme i like so much. its called pyCharm

Convert to html in VIM batch mode

VIM has a beautiful feature of converting the code into a html formatted code. When you apply syntax highlighting, the code gets beautified. But when you need to copy and visualize the code some where else.. the copy does not actually copy the formatting along with it. Vim has a menu option of converting the code into html syntax. Syntax -> Convert to HTML. This looks cool, but if you have some bunch of files and you have to convert them to html.. The savior is writing some script to automate this The tag that does HTML conversion is this: :.,$TOhtml Now you can automate this: Write this in a vim script. Lets name it as "test.vim" zR :set autochdir :.,$TOhtml  :wqa How to run over a file: vim -s test.vim test.sv  Now this will generate test.sv.html file in the file directory. Point to note: Your .vimrc should contain the setting the automatic file type.  Now i took the file name as "sv". When i open GVIM/VIM, the sv (system v...

SystemVerilog: Mailboxes and Queues

Mailboxes and queues are couple of basic data constructs of system verilog language. Lets get to the definition of them: Queue: A Queue in system verilog function as the name suggests. But with a twist. Queue in system verilog is a list of similar elements. Queue is built on top of an array. Delcaration of a queue. < TYPE > < que_name >[ $ ]; Default Behaviour: The default size of the queue in system verilog is " Infinite ". The above declaration will create a que of infinite length. You can add elements to the que until your simulator crashes :) What if you want to create a queue of finite length. Just look at the declaration below: < TYPE > < que_name >[ $ :< LIMIT >]; The above declaration will create a queue of size " LIMIT+1 " Initializing queue with elements Accessing elements of a queue Methods in queue Inserting elements into queue Reoving elements from queue http://www.project-veripage.com/queue_1.ph...

Fork Join in System Verilog

The fork join is very basic construct in the system verilog usage. But there are also side effects of this fork and disable fork. The fork join can be used in two ways as shown below: Un-Named fork join blocks: In this scenario Named fork join blocks:

Queue of arrays and Array of Queues

1 2 module test ; 3 4 int a [ $ ][]; 5 int b []; 6 int c []; 7 8 int aa [][ $ ]; 9 int bb [ $ ]; 10 int cc [ $ ]; 11 12 initial 13 begin 14 b = new [ 10 ]; 15 b [ 0 ] = 100 ; 16 a .push_back ( b ); 17 c = a .pop_back (); 18 $display ( "Read back value is: %0d \n " , c [ 0 ]); 19 20 aa = new [ 10 ]; //Make 10 wide queues. 21 bb .push_back ( 1000 ); 22 aa [ 0 ] = bb ; 23 cc = aa [ 0 ]; 24 $display ( "Read back value from que is: %0d \n " , cc .pop_back ()); 25 26 end 27 28 endmodule

Remove .nfsXXXXX files

Sometime s it is so irritating when you want to remove some thing in linux and you find .nfsXXXXX file “Cannot be removed: Device or resource busy”. ps command would not help in these scenarios to know what is actually using it. lsof is a command in linux to figure the open files. The output of this command is the list of files that open and used by the processes, the process name and PID of the process that is using the file. To remove .nfsXXXX files. Run lsof command Find the processID of the process that is using .nfsXXXX file. Kill the process. Remove the .nfsXXX file using rm command.