![]() |
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. |
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.
|
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.
|
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.
|
Well with XP you are probably using an X86 architecture
|
PySerial
|
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?
|
Quote:
PySerial just takes all the above approaches and stuffs them into one cross-platform library. |
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.
|
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