Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Other Programming Languages (http://www.programmingforums.org/forum38.html)
-   -   Interfacing with a serial port? (http://www.programmingforums.org/showthread.php?t=10778)

titaniumdecoy Jul 19th, 2006 4:55 PM

Interfacing with a serial port?
 
I am working as a summer intern at a large company. My responsibilities involve writing scripts to accomplish various tasks.

I was recently asked if I would write a script to interface with an external device. All I know so far is that the device records temperatures and connects to a computer via a serial port.

I have never attempted this sort of thing before, and I was hoping someone more experienced could point me in the right direction. I currently have no idea how get a reference to a computer's ports or read data from them.

Is there a standard way to connect to/read from a computer's ports? Or does each device have its own API, and if so, how would I find this information as it pertains to a particular device?

In addition, is it likely that I will be restricted to coding in C++, or will I be able to use a higher-level language such as Python?

Thanks in advance for your replies.

DaWei Jul 19th, 2006 5:12 PM

Heaven knows why we always mention this, but you need to specify your platform and OS. I guess if people ever designed one of those effers they might know why we're so silly.

linxis Jul 19th, 2006 5:22 PM

You can use a High Level Language like python. BUT YOU MAY NEED TO CREATE A DRVIVER. I once made a QB program compatable with a bar code scanner. I made a driver using C++ that would read it's serial port input it and enter it just like a keyboard does. But python is not good for devices. Use some c++ to asign it a COM PORT 1 or 2 then use QB to read input from it.

titaniumdecoy Jul 19th, 2006 5:30 PM

I'm using Windows XP. That's all I know at the moment; I'll post again when I have more details about the project.

linxis Jul 19th, 2006 5:32 PM

Well with XP you are probably using an X86 architecture

Game_Ender Jul 19th, 2006 5:40 PM

PySerial
 
2 Minutes on google dug up PySerial. Looks pretty simple to use, and it seems you are using python for the rest of you stuff so this is a good fit.

You can also check out USPP which is also for python it is more recently updated.

titaniumdecoy Jul 19th, 2006 6:04 PM

I'm interested in how you would go about connecting to and reading from/to a serial port without using other people's wrapper classes (although that is probably what I'll end up using). How do the people who write the wrapper classes (such as PySerial and USPP) get access to the serial ports?

Arevos Jul 19th, 2006 6:27 PM

Quote:

Originally Posted by titaniumdecoy
How do the people who write the wrapper classes (such as PySerial and USPP) get access to the serial ports?

It depends what OS you're using. On Linux, you can access the first serial port by accessing the file "/dev/ttyS0". On Solaris, the file is "/dev/ttya". On OS X it's "/dev/cuaa". On Windows, one can use the win32 API to access the serial port (not quite as easy to do, but then that's to be expected with Windows).

PySerial just takes all the above approaches and stuffs them into one cross-platform library.

DaWei Jul 19th, 2006 6:29 PM

With XP you have to get out of fully-protected mode and get at the hardware, or use someone else's code (driver or wrapper or whatever) that does. It gets in the way when you decide to get down and dirty, but it keeps lebenty-zillion users from wiping out their system every time they turn around. If you want to get directly at it, yourself, you have to go that way, and you'll have to study serial devices, how you know when they're ready to transmit or receive, how to set up the bit rates and formats, all that hooey. It's interesting and fun the first several times you do it (if you aren't blowing a delivery date), but it probably isn't what your bosses want. They could be tasking you with it, just to see how you handle it, but they probably want a job done.

titaniumdecoy Jul 19th, 2006 6:37 PM

Thanks for all the replies. It sounds like I'll be going with PySerial or a similar library.

I suppose the real question is, how do I determine how to interpret the data that is read from the port? I assume most devices don't come with a manual detailing how to interpret the bits it sends to the computer. Does the way data is sent depend on the port, or the device sending it to the port? Is there usually a reference for this sort of thing?


All times are GMT -5. The time now is 12:45 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC