Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.
I want to communicate with ngspice through an external application by writing to the standard input stream of the process and listening on the standard output and error streams. The external application I m having works with a simple console C application which has 'gets' and 'puts' commands. When I use the standard C I/O functions in the ngspice source code and and compile it, it allows me to give input from the text box provided in the GUi where we usually type the commands and the output is displayed in the interface again. When I tried communicating with my external application, the input is not taken by the ngspice application and also the output of ngspice is not captured by the external application. I tried running it in batch mode and also tried making a console ngspice application and the communication with the external application is still not working. How to make ngspice like a console C application without the GUI so that the I/O commands when used will occur through the console itself.
what about chapter 16.11 of the actual ngspice manual?
cat input.cir | ngspice -s | more
with a console ngspice?
you did not tell us about your operating system/compiler setup.
Under LINUX you will have the console application anyway.
Under MS Windows (and mingw/msys) you might try
./configure -enable-adms -enable-xspice -enable-cider -enable-openmp -disable-debug CFLAGS=-m32 LDFLAGS=-m32 prefix=C:/Spice
or similar (_not_ adding -with-windows).
Thanks for the reply.
I am using MS Windows and Visual C++ to compile the source code. While using VC++, I selected the 'console_debug' option from the configuration manager and compiled it to generate a ngspice console. Still I couldn't achieve the inter process communication. I am actually trying to build a Graphical User Interface (GUI) for ngspice and the module which I am having now generates the ngspice netlist. I want to feed the netlist as a line by line input to ngspice from my GUI followed by the commands, the way a .cir file with the '.plot','.print' and other commands included in itself is fed to ngspice in batch mode. For this I modified the 'inp_readall' function in the ngspice vc++ project by adding 'gets' and other input commands so that it will take the netlist as input and not by reading from a file using a file pointer. I also took care that the way initialization files and other required files are read is not changed. By doing this, it allowed me to type in the netlist and the commands line by line in the ngspice interface and then run the required simulations. But my GUI is not able to feed input to this and listen to the output generated. But the GUI is able to do the same with a simple C program with just these(gets,scanf, puts..etc) I/O commands. I thought this might be because of the way the standard streams have been redirected in ngspice.
I also tried using the '-p' option for ngspice pipe mode but not much of information was available about how to use this. When I looked at the code this option was added in the part where the command line arguments were processed and I couldn't see any continuation from this. May be I am wrong but I could only notice two boolean variables or flags being set and they didn't lead to other parts of the code.
Thanks in advance
The way I am calling ngspice from my GUI is the same as calling it from cmd.exe and I pass arguments if and whenever needed. I don't have a .cir file and as I mentioned I want to feed the netlist as line by line input. Also as I am using windows I can pass '-s' as argument but I wouldn't be making use of the '|' symbol in the command which is used for piping. Should I be using the same command with some modifications??
I am not a specialist in interprocess communication, but I think the changes you intend to do are too heavy.
There is the internal i/o-loop of ngspice, if you change that, its your's!
Can you offer any interactive command (manual chapter 17) from your app to ngspice? If yes, why not define a new command (e.g.
linesource "string from netlist",
), and then start netlist parsing?
as far as I know, the -p option is used by xcircuit (http://opencircuitdesign.com/xcircuit/) to communicate with ngspice (under LINUX). You might have a look there also.
a simple experiment, maybe that it helps.
Start ngspice console with -s flag in an msys shell, e.g.
Then type in your circuit, line by line,e.g.:
v1 1 0 1
.tran 0.1 1
.print dc v(1)
Finish the input by ^z (that is ctrl z),
and viola there is (a binary) output to the console.
to be more precise:
v1 1 0 1
.tran 0.1 1
will print a binary raw file with the simulation results to the console. .print does not change this.
If you add
to your circuit,
you will get readable ascii values on the console.
Hi Rohith, Holger,
I am unable to find "to where exactly the input text (for example load,run,*.cir file name), in the console, during interactive session, is received by the Ngspice". Pls help.
this is the call stack:
> vngspice_cd.exe!inchar(_iobuf * fp=0x00a39be0) Zeile 38 C
vngspice_cd.exe!input(_iobuf * fp=0x00a39be0) Zeile 68 + 0x9 Bytes C
vngspice_cd.exe!cp_lexer(char * string=0x00000000) Zeile 144 + 0xb Bytes C
vngspice_cd.exe!cp_parse(char * string=0x00000000) Zeile 62 + 0x9 Bytes C
vngspice_cd.exe!getcommand(char * string=0x00000000) Zeile 601 + 0x9 Bytes C
vngspice_cd.exe!cp_evloop(char * string=0x00000000) Zeile 631 + 0x9 Bytes C
vngspice_cd.exe!app_rl_readlines() Zeile 648 + 0x7 Bytes C
vngspice_cd.exe!main(int argc=1, char * * argv=0x01a73500) Zeile 1316 C
In function inchar() in file ngspice\src\frontend\parser\input.c you see where characters are entered.
Ya, thanks. I see to it..