Friday, May 21, 2010

Serial Port in BASIC?

I've asked this question before but got no answers so im gonna simplify the question. What is the best way to send a constant "1" signal through a serial cable with Liberty BASIC? All it needs to do is trigger a transistor to turn a motor on and off. I know, I should use C or something, but im fairly familiar with BASIC languages and the liberty site boasts good hardware interface. THANKS!

Serial Port in BASIC?
I would recommend using C -- its simple to do and will compile to native code for your platform. Also, if you're building your own controllers that hookup to your serial/parallel port be sure to throw a diode in between them otherwise you might get some back voltage, damaging your port/mobo.





Yes, there are many free C compilers for virtually any platform. I recommend GCC if you're using Linux or Windows. I like the Microsoft Embedded C++ for PocketPC.





As a side note, if you find this kind of thing interesting you may be interested (as I am) in Microcontrollers such as the AtMega 128 -- these little gadgets are small microprocessors (about 33MHz with only 128k of memory) but they have a wide collection of I/O ports you can hookup for control/communication applications. There are existing componetns you can innexpensively buy to connect to these things to add features like GPS, long range wireless communication, etc., etc. Highly recommend it :)





Update: I recommend learning C for operating system tasks (microcontrollers/stuff you're working with now) C++ is just a small jump but there are enough features within it to distinguish it from C. Also, the free/open source compilers are adequate -- no need to spend any $$$.
Reply:For COM1:


OUT %26amp;H3FC, 10


to turn on RTS or


OUT %26amp;H3FC, 1


to turn on DTR.





%26amp;H2FC for COM2:


DTR is Pin 20 on a 25 way serial port and RTS is pin 4 (or 4 and 7 on a 9 way).





You don't need C, you can even do it with debug.
Reply:According to http://babek.info/libertybasicfiles/lbne... , the basic outline for what you need to do is this:


1- create an instance of the needed DCB structure


2- open the User.DLL


3- build the DCB


4- open the comm port


5- read or write to the port


6- close the port when done


7- close the DLL


The site has sample code and tutorials.





As to your free compiler question, since you want to stick with windows, why not just grab http://www.mingw.org/ or http://www.cygwin.com/ ?
Reply:The first link below contains code for controlling the RTS line with Liberty basic (you can't use the DATA line as there's no way to keep it at a constant level).





The second link shows a project where people used Liberty to control lights via the parallel port. This gives you up to 8 data lines.





The last two links show a very cheap and easy-to-use RX/TX pair for transmitting a signal. I've used these before to make wireless controllers for game consoles....they work really well! Good luck.


No comments:

Post a Comment