Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 19th, 2006, 4:55 PM   #1
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 908
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Question 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.
titaniumdecoy is offline   Reply With Quote
Old Jul 19th, 2006, 5:12 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jul 19th, 2006, 5:22 PM   #3
linxis
Programmer
 
Join Date: May 2006
Location: USA
Posts: 52
Rep Power: 0 linxis has a little shameless behaviour in the past
Send a message via ICQ to linxis
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.
__________________
Get programming and game creation tutorials and discuss apon you peers at
http://s14.invisionfree.com/tsoft
We also accept custom software requests and new mods will be needed soon
linxis is offline   Reply With Quote
Old Jul 19th, 2006, 5:30 PM   #4
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 908
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
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.
titaniumdecoy is offline   Reply With Quote
Old Jul 19th, 2006, 5:32 PM   #5
linxis
Programmer
 
Join Date: May 2006
Location: USA
Posts: 52
Rep Power: 0 linxis has a little shameless behaviour in the past
Send a message via ICQ to linxis
Well with XP you are probably using an X86 architecture
__________________
Get programming and game creation tutorials and discuss apon you peers at
http://s14.invisionfree.com/tsoft
We also accept custom software requests and new mods will be needed soon
linxis is offline   Reply With Quote
Old Jul 19th, 2006, 5:40 PM   #6
Game_Ender
Professional Programmer
 
Game_Ender's Avatar
 
Join Date: May 2006
Location: Maryland, USA
Posts: 306
Rep Power: 3 Game_Ender is on a distinguished road
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.
Game_Ender is offline   Reply With Quote
Old Jul 19th, 2006, 6:04 PM   #7
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 908
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
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?
titaniumdecoy is offline   Reply With Quote
Old Jul 19th, 2006, 6:27 PM   #8
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
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.
Arevos is offline   Reply With Quote
Old Jul 19th, 2006, 6:29 PM   #9
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jul 19th, 2006, 6:37 PM   #10
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 908
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
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?
titaniumdecoy is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Data logging problem from the serial port jerryleo Perl 0 Jan 10th, 2006 8:47 AM
Help in QBASIC (I think it's similar to VB) phoenix987 Visual Basic 3 May 9th, 2005 1:33 PM
Help with a QBASIC program phoenix987 Other Programming Languages 4 May 5th, 2005 1:27 PM
Script to output HDD data to serial port Europa2010AD C 2 Apr 6th, 2005 2:37 PM
Printer Port Programming shadowhunter C++ 3 Feb 28th, 2005 5:16 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:07 PM.

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