NXT like standard C? - nxt

I'm currently working on a project, where we want to program a swarm of nxts. I have a question to this one, and I can't find a precise answer on the web. So there will be a program on my pc, let's call it a switch, which should connect to 3 robots.
The program on the pc is not an issue, I thought of a simple berkeley socket with AF_BLUETOOTH. Now here the question: Can I write a simple C program for the robot (NXT) as well, or can I use only NXC with it's libraries? What I mean is - can I write a C program with p.ex. #include and it will work there?
Because all I can find are codes written using only functions the nxc has, and I'd like to write my own socket/connect/accept/and-so-on functions. Is it possible?
Thx :)

Related

How to use Objective C in an AppleScript-Cocoa Application?

I am developing an Applescript application using X-Code and I'm having the hardest time finding answers to questions. It's tough because I'm struggling to understand how the UI elements work, etc., and most answers to those questions are written in Objective C. I have learned a little bit about how to convert Objective C code into Applescript, but in most cases I'm still not sure.
For example, this answer shows some ObjC code, but I don't know how to make use of it in my Applescript application.
Is there a resource or guide that can help me to a) understand how to use Objective C code in my Applescript app, and/or b) how to rewrite Objective C code in Applescript?
In general, Applescript can be used to automate tasks (especially repetitive ones) for any MacOS application that exposes an Applescript dictionary.
One can compile and execute Applescript from within MacOS applications written in Objective-C (via the NSApplescript class, but the other way around, one would use Applescript to call into an already existing app (or one that you created yourself) that was written in Objective-C.
It sounds like you should write the lowest level stuff natively in Objective-C and see if you can automate that from within Obj-C, or expose an Applescript dictionary (via an sdef file that gets included in the Xcode project) and then you can use Applescript to do things via your native app.
Makes sense?

C two platform compiling

I want to run some C code targeted to run on a unique PIC micro based hardware setup in a PC windows environment as well. The objective is to emulate multiple instances of the hardware without the actual hardware. I expect to have to write the code upfront to account for this and to create low level functions in C or C# that emulate each of the PIC functions.
Does anyone know an environment that can support this?
What you're looking for is a microcontroller simulator. The simulator will run on the PC and execute the PIC code. In order to e.g. generate interrupts / simulate serial data / whatever you'll need to either configure the simulator settings or write a few custom function.
Your target code (for the PIC itself) shouldn't need to be aware of what environment it's running on.
Here's a few links, but you're best off searching for some variant of "PIC microcontroller simulator" or "microchip PIC simulator".
http://sourceforge.net/projects/gpsim/
http://sourceforge.net/projects/picsim/
I'm not sure that this question is about an instruction simulator. It seems to me that it is simply about the technique called "dual targeting". I've asked a similar question on StackOverflow before, please see: Prototyping and simulating embedded software on Windows . Recently, I've also made a blog post about dual targeting and rapid prototyping on Windows here: http://embeddedgurus.com/state-space/2013/04/dual-targeting-and-agile-prototyping-of-embedded-software-on-windows/ .
So, while the links should provide the answer to the original question, I'd like to add that the 8-bit PIC is probably no programmable in C++. In fact, it is so baroque that even C compilers for this "architecture" must cut many corners.

How to program hardware? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am an adept Visual Basic programmer. I wish to learn about how people program hardware. For example I have seen people create an LED watches, boxes etc. How do you achieve this? Can it be done using VB or Java? I have some experience in reading C, C++ code. I am only aware of IO in the C and C++ language.
Probably you are looking for a programmable microcontroller. If you have experience in C/C++/Java, checkout Arduino. Its chip is programmed using a C like language. This "How tos" page might help you get started. There are also some good books that will help you move forward:
Programming Interactivity.
Making Things Move DIY Mechanisms for Inventors, Hobbyists, and Artists
Wiring is a platform similar to Arduino.
Also have a look at the Forth programming language. There are lot of interesting "tiny
computers" that you can program with this rather unusual language. Here is a partial list:
Forth Inc
Greenarrays
Zilog Z8
PIC18Fxx2
Two famous Forth books:
Starting Forth
Thinking Forth (A classic in Software Engineering literature.)
how people program hardware
If by 'hardware' you mean a standalone device (an embedded system), then the process involves cross-compilation. Code for the device is written in some (high-level) language on a host PC, compiled, and converted to a form suitable for downloading onto the target device.
A cross-compiler generates executable code for a platform other than the one it is running on -- for example, an AVR cross-compiler will generate code for the AVR microcontroller, but the compiler runs on a PC. Universally, assembly and C are used, and to some extent C++, Java and Ada.
If by 'hardware' you mean some device connected to the PC via some port (serial, parallel, USB), then the programing involves interaction through that port, possibly needing a device driver as well.
Can it be done using VB or Java?
I'm not sure about VB (perhaps there are VB compilers for WinCE and its ilk). Java is used on more complex/larger embedded systems (eg. mobile phones), mainly to develop user applications for the device.
create an LED watches, boxes etc. How do you achieve this?
If you're interested in developing something like a LED watch, you need to learn how to program a microcontroller. At the least, you need two components: the microcontroller and some hardware which loads programs onto it (a programer). You may invest on a development board, or build one yourself. Naturally, you will also need the cross-compiler, and the sotware that interacts with the programer so that it can load code.
I'm partial to AVR, so I'd suggest that. Other options include PIC, some variant of 8051, PSoC1 and TI's MSP devices.
The AVR tool-chain is bundled in WinAVR, and it includes avr-gcc (cross-compiler frontend), avrdude (software that interacts with the programer hardware) and a C library (avr-libc) + a bunch of useful tools. Programing hardware can be as simple as DAPA/bsd to USB based ones (AVRISP, USBasp, Usbprog) etc.
Or, if your PC still has a parallel port, you can try to control say a set of LEDs using an application written in VB. Check http://www.lvr.com/parport.htm for details.
I would recommend starting out with something like an arduino, which is a good place to get started with programming close to the hardware. It's a prototyping board with some built-in leds and other things, depending on which model you get. You can use C/C++, or any other language which can be cross-compiled to a format which is compatible with the target hardware (ATMega microcontroller I believe on the arduino).
Check out: http://www.google.com/search?client=ubuntu&channel=fs&q=arduino&ie=utf-8&oe=utf-8
If you just want to connect something to the computer serial/parallel port and 'talk' to it, you can use most languages. In Visual Basic you'll need a dll to achieve this. Java may be able to do it too.
If you want to program a microcontroler chip, you'd best learn C, because this is the language used to program most of them, although some of them accept basic, java, processing and C++.
There are a number of basic stamps you can use to get your feet wet. parallax for example made their business on basic based embedded systems. If you want to move forward at that programming level you really need to learn C for the most coverage, and I highly recommend assembler as well, at least a few different instruction sets.
You might be interested in Gadgeteer. I got to play with a kit a few weeks ago, and it's amazing fun. You can't currently do VB, but you can do C# and VB is coming very soon.

How to create a compiler in vb.net

Before answering this question, understand that I am not asking how to create my own programming language, I am asking how, using vb.net code, I can create a compiler for a language like vb.net itself. Essentially, the user inputs code, they get a .exe. By NO MEANS do I want to write my own language, as it seems other compiler related questions on here have asked. I also do not want to use the vb.net compiler itself, nor do I wish to duplicate the IDE.
The exact purpose of what I wish to do is rather hard to explain, but all I need is a nudge in the right direction for writing a compiler (from scratch if possible) which can simply take input and create a .exe. I have opened .exe files as plain text before (my own programs) to see if I could derive some meaning from what I assumed would be human readable text, yet I was obviously sorely disappointed to see the random ascii, though it is understandable why this is all I found.
I know that a .exe file is simply lines of code, being parsed by the computer it is on, but my question here really boils down to this: What code makes up a .exe? How could I go about making one in a plain text editor if I wanted to? (No, I do not want to do that, but if I understand the process my goals will be much easier to achieve.) What makes an executable file an executable file? Where does the logic of the code fit in?
This is intended to be a programming question as opposed to a computer question, which is why I did not post it on SuperUser. I know plenty of information about the System.IO namespace, so I know how to create a file and write to it, I simply do not know what exactly I would be placing inside this file to get it to work as an executable file.
I am sorry if this question is "confusing", "dumb", or "obvious", but I have not been able to find any information regarding the actual contents of an executable file anywhere.
One of my google searches
Something that looked promising
EDIT: The second link here, while it looked good, was an utter fail. I am not going to waste hours of my time hitting keys and recording the results. "Use the "Alt" and the 3-digit combinations to create symbols that do not appear on the keyboard but that you need in the program." (step 4) How the heck do I know what symbols I need???
Thank you very much for your help, and my apologies if this question is a nooby or "bad" one.
To sum this up simply: I want to create a program in vb.net that can compile code in a particular language to a single executable file. What methods exist that can allow me to do this, and if there are none, how can I go about writing my own from scratch?
What you're asking is a pretty complex question. Sure, at its core it seems pretty basic:
Interpret the code itself
Write out the interpreted code
but each of those steps can be pretty intense. Step 1 should be somewhat achievable with some time and a LOT of elbow grease - you need to parse the code into a number of control statements based upon the specification of the language. Check out http://en.wikipedia.org/wiki/Parsing for more information on this step. In essence you're converting the typed code into a common format that represents the functionality you want.
Once you've parsed the code, the next step would be to take that parsed code and convert it into machine-runnable code (typically assembly, though with VB.NET you can write Microsoft Intermediate Language code as the output and then run it in the CLR). This is what will actually create the executable file in a manner that lets the computer run the program.
Unfortunately, the best advice for solving this problem is to either:
Go purchase several books on a programming language, machine code, assembly language, compilers, and so on, then spend several months or years reading and experimenting until the knowledge you gain from the books results in your writing a successful compiler.
Enroll in a computer science program at a local university. Writing compilers and programming languages are usually covered at a rudimentary level during the second or third year of a BS in computer science, and then in much more depth at a graduate level.
Good luck!
EDIT: If all you're looking for is a way to write code and then write a way to execute it, you might try looking at writing an interpreter for one of the scripting languages that already exist - Ruby, Python, Lua, etc.
Process.Start(String.Format("vbc.exe {0}", sourceFilePath))
Here is one book that explains it all at a very basic level. Including sample code that you can get working in a matter of hours.
As with many programming endevors, it will take you many months of study to accomplish what you want. Good luck!!
Let me start by saying this is totally doable. Ignore the naysayers.
OK, so it seems you bit off more than you could chew here. I would suggest slightly re-evaluating your goal. It seems that you want to learn how compilers work, and writing a VB.net compiler is your project to get started.
Try instead to write an interpreter, which is a much smaller and simpler task. Here's how you do it:
Write a parser for a very very small language, maybe only supporting assignment statements. Use a parser toolkit, like Antlr. This will build an AST ("abstract syntax tree" - ie a few classes or objects representing the program's syntax, without the crap like semi-colons, as a tree), which will look something like this:
then you go through the AST, and just execute it. Google for "AST walker". So for the assignment x = 5, create a hashtable entry for 'x', assign 5 to it, then move on to the next statement.
keep adding features as you go.
Once you've got the full language, you'll probably have learned enough on the way to understand the compiler books. Don't use the dragon book, try Appel's book instead, or Cooper/Torczon. There are online books if you prefer, I've never tried them.
When you go to write the compiler, you'll just be changing the bit that executes the AST into one which generates assembly (or C if you prefer) which will do the same action when it's run.
I'll grant that it seems daunting, but if you stick to a something simple to start, you'll get something working in a few days at most. In a few months, you'll have built it up to something like what you're looking for. Good luck.
To the final part of your question:
It seems that you don't know how executables are made from code. People haven't messed with hex in their compilers since the 80s, and hopefully not much even then.
Basically, after parsing the code, you go through a series of steps which make the code progressively simpler. At the end of that, you have something that is quite close to assembly. You then generate assembly, and the assembler and linker conspire to make it into an executable.
The Visual Basic .NET compiler is shipped for free as part of the .NET Framework - you don't even need the SDK or Express Editions. The compiler for VB (and C#) is located at c:\windows\microsoft.net\framework[version]\vbc.exe (or csc.exe for C#). Therefore, any computer which can run a VB.NET program can compile one. The .NET Framework also includes the System.CodeDom namespace which provides a way from within a program to compile a program, either from a document model or from a string (or file) into a .NET assembly (.exe or .dll) and generate code in both VB and C#.
Regards,
Anthony D. Green | Program Manager | Visual Basic Compiler
You create a compiler for vb.net the same way you create any other compiler. You need a lexer/parser. Entire books have been written on this topic, the most famous probably being The Dragon Book.
To provide a definitive answer: No, you cannot create a decent compiler that will generate an executable file using Notepad. You need a compiler to convert from human-readable text into the machine language (assembly or IL) that a linker or interpreter can then execute.
You can try checking out my tutorial at http://www.icemanind.com
It is a tutorial on creating your own virtual machine and assembler, written in 100% C#.
Cyclone, I'm wondering exactly what are you trying to achieve? You say "the exact purpose of what I wish to do is rather hard to explain" and "essentially, the user inputs code, they get a .exe".
If you just want the user to be able to enter code and then execute it, you might consider an existing scripting language. VBScript is built into Windows and the language is fairly similar to VB.Net, or there are various excellent free languages you can download like Python.
If the user really needs to be able to create a .exe - I think it's likely scripting might do - then why not use an existing free compiler like FreeBasic, or even Visual Basic.Net Express Edition.
I am making a tutorial for that in my website, http://dgblogs.weebly.com. It is written with C# and you can create your own computer programming language!
You will never see this syntax in my tutorials:
Console.Readline();
My website is currently offline by now so, GOOD LUCK!
Thanks,
DgBlogs
Im quite shocked that this question was never fully answered ; Recently i came across some tutorials on the subject of developing a programming language from scratch https://www.youtube.com/c/DmitrySoshnikov-education/playlists
Although the person uses Java Script the technique used for creating the tokenizer and the parser to consume the output from the tokenizer producing the AST for the transcribed language which i would consider to be GOLD! ...
Another tutorial or person https://youtube.com/playlist?list=PLSq9OFrD2Q3DasoOa54Vm9Mr8CATyTbLF
Toby Ho! Has also produce various methods using the Nearly parser (plugin) to build a language much easier but not a Pure code coder like myself(does not like extensions to do the work which i can do myself)....
https://github.com/spydaz/SpydazWeb-AI-_Emulators
I was able to do some different experiments designing a stack machine (runs mini assembly language). for my "Toy" Programming language(basic) could be executed on. (the VM) - Using Visual Basic(My personal Lang - I think in VB)
Since revisiting the tutorials ;
https://youtube.com/playlist?list=PLRAdsfhKI4OWNOSfS7EUu5GRAVmze1t2y
Immo Landwerth! Had a few more experiments This time with C#
A bit more Spaghetti to mull over; but actually revealing (after knowing a lot more);
Yes IT is possible to design a Compiler / VM with VB.net Quite easily ... without external tools .
For myself as an AI developer (CONVERSATIONAL AI / NLP) i was interested in building a compiler for the English language if it would be possible to use the technique for parsing syntax trees and building syntax trees from text using the Tokenizer/Parser to AST Method , as well as designing the transpiler to allow for the syntax tree to be used for translation to other languages. as with today's programming languages merely being a Higher lever language interfacing with a low level(VM) language. in-fact we should be developing more natural language - programming languages and dispelling the more cryptic languages such as C# (Lol) and Java and Go and the like (so many brackets and semi colons / tabs etc - truly not needed!) and that is to say that we programmers still think in code! the journey as a AI developer crosses many domains. forces many off topic research pathways .. So Again a big YES! and we Still could say that ANy programming language can be used to create another programming language it just depends on which language you "THINK IN" .... hence not having too many languages using (i understand most programming languages - but i will always think in VB)...

Analog circuit simulation library?

I'm working on a genetic programming tool and I'd like to evolve analog circuits. Can anyone suggest a library or tool or even a reference for hooking my GP code up? I just need some way to have something like SPICE evaluate the circuits that are created by my code. I've seen reference to plain text representations of the circuits (netlists) which are used by tools like SPICE. I'd like to know if there is a better way to connect to a simulator than to run it and pass the netlist on standard input. My code is written in C, in case you're wondering what sort of library I'm interested in.
Modelica has various circuit analysis capabilities.
SPICE is the reference electronics simulator.
I think it's mostly written in Forth, these days mostly using a Forth-to-C translator. I'd try to integrate it simply reading its text output to pick the values you want to {min/max}imize