Using PC RS232 Input

BrownTown

Diamond Member
Dec 1, 2005
5,314
1
0
So, for my senior project the sponsor wants us to be able to write a program on a PC to monitor what the microcontroller in our custom PC is doing. So since PCs have RS232 and the microcontroller has RS232 it makes sense to use that for the communications. However the big problem is that I don't actually know how to read data from a the computers serial port. Wouldn't you need to write a serial port device driver that messes around with IRQ numbers and generally messes around with the parts of the computer that you were always told you could really really screw yourself over in when programming C? Anyone know how to interface with a RS232 device, or have any source code that already does it?
 

PottedMeat

Lifer
Apr 17, 2002
12,365
475
126
Originally posted by: BrownTown
So, for my senior project the sponsor wants us to be able to write a program on a PC to monitor what the microcontroller in our custom PC is doing. So since PCs have RS232 and the microcontroller has RS232 it makes sense to use that for the communications. However the big problem is that I don't actually know how to read data from a the computers serial port. Wouldn't you need to write a serial port device driver that messes around with IRQ numbers and generally messes around with the parts of the computer that you were always told you could really really screw yourself over in when programming C? Anyone know how to interface with a RS232 device, or have any source code that already does it?

I've never actually done this before, but in MS VC# 2005 Express ( the free one ) there are controls for serial ports and parallel ports. I'm sure what you're asking has been done before and theres probably code you can cut'n'paste to do basic functions.

Wouldn't you need 2 RX ( so 2 serial ports on recording pc - one to tap (MCU -> PC ) and one for (PC -> MCU) ) to completely monitor comms between devices?

 

Modelworks

Lifer
Feb 22, 2007
16,240
7
76
The really easy way to do it is just to have your micro send text to the serial port.
You should be able to monitor the information being sent in hyperterminal.

As long as your not in need of real time data that requires specific timing, don't worry about drivers and irq's .

I've done pic and embedded micro development for 20 years and sending text from the micro to the pc is the easiest.

Then its a simple matter of , open the port, read the string, store it , program reads it, displays variable or does whatever you want when it receives that certain string.
 

CycloWizard

Lifer
Sep 10, 2001
12,348
1
81
You can directly read input pin values and set pin output values using standard procedure calls. I did this a while back to control a piece of hardware, but it's been a few years now and the code is on a different PC.

Basic pinout
 

BrownTown

Diamond Member
Dec 1, 2005
5,314
1
0
Thanks for all the links guys, it doesn't look like this will be too hard to do with all the information out there on the internet. Will have to polish off my old C++ programming boots though, been a couple of years. Actually now that I think of it I don't know how to do a GUI in C++ only VB, isn't there an easy way to call functions from a C++ DLL file out of VB or something like that I remember? I'm sure I can look it up on my own, project isn't due till graduation so no hurry here, I'm more worried about "looking" like I'm working than actually working right now .

EDIT: will be pretty cool though to design a circuit and PCB with 200 components then write a program in assembly to run it off a microcontroller then write a program in C++ to read out what the microcontroller is doing. Sort of covering several layers of abstraction there going up from designing the interface with transistors resistors and capacitors then going up to assembly to run the I/O then going up to a higher level language to monitor the I/O and bring it out to a form a non-tech savvy person can control and understand.

EDIT2: even cooler is the fact I don't have to pay for any of it
 

Born2bwire

Diamond Member
Oct 28, 2005
9,840
6
71
Sun has a serial port communications API for Java. I've used it to write programs to run function generators and digital multimeters to automate testing of circuit boards. The API is really easy to use. Heck, you can just use your default TELNET program to communicate using ASCII if you need to.
 

BrownTown

Diamond Member
Dec 1, 2005
5,314
1
0
Originally posted by: Born2bwire
Sun has a serial port communications API for Java. I've used it to write programs to run function generators and digital multimeters to automate testing of circuit boards. The API is really easy to use. Heck, you can just use your default TELNET program to communicate using ASCII if you need to.

Yeah, well the point is to make it so a person who is not tech savvy can interface, so a GUI and all. I can already use hyperterminal as an interface, but I need a way to get the data into a GUI and not a command line prompt.
 

Lord Banshee

Golden Member
Sep 8, 2004
1,495
0
0
BrownTown

I made a visual C++.net program to read and write to a serial port, if you want a copy i can send it to you or advise you on how to get to work (well after Thursday). The only difference is my C++.net program was not reading and writing to a MCU but a serial interface i design on FPGA + RS232 chip... should work the same.

PM me if you do, but you can't make fun my crappy coding skills lol
 

ScottMac

Moderator<br>Networking<br>Elite member
Mar 19, 2001
5,471
2
0
Do it in Perl.

Use Net::Telnet to read the MCU, use CGI for GUI interface. You could toss in some Java and / or Javascript to spiffy it up a little.

As an alternative, there are some Perl compilers, you could use Perl for the low-level interface objects and C / C++ for the processing.

Worse case, I think you can use WIN32 DLLs to create a Windows GUI, or tk or GTK+ ... there's a few packages you could use.

Also remember that the RS232 from the MCU is at TTL level; for a reliable link, you need a driver like a MAX232 chip to scale it up to the +/- 13v for EIA level.

I have some temperature probes using PIC 12f683s (8 pin DIP, cheap) and Dallas 1822s; I read 'em with Perl (using Net::Telnet) and use the Perl code to collect the info and a mail module to email and page (and syslog trap) when thresholds are violated.

Perl's easy and has components for every aspect of your project from your description.

Good Luck

Scott
 

Born2bwire

Diamond Member
Oct 28, 2005
9,840
6
71
Originally posted by: BrownTown
Originally posted by: Born2bwire
Sun has a serial port communications API for Java. I've used it to write programs to run function generators and digital multimeters to automate testing of circuit boards. The API is really easy to use. Heck, you can just use your default TELNET program to communicate using ASCII if you need to.

Yeah, well the point is to make it so a person who is not tech savvy can interface, so a GUI and all. I can already use hyperterminal as an interface, but I need a way to get the data into a GUI and not a command line prompt.

Java is pretty easy to do a GUI in. I made a GUI and everything for the program that I wrote. I think the GUI stuff is called "swing," I did this years ago. I was brought on for an internship to write a Java library for communicating with devices via serial port. The group I was with maintained the vacuum, coolant, and controls systems of the beam line so they wanted a way to easily interface with the devices down there. Ended up doing the work so quickly because of Sun's API that I had pretty much the whole summer to fart around doing other things. I ended up schlepping out a GUI for my program near the end for them.
 

bobsmith1492

Diamond Member
Feb 21, 2004
3,875
3
81
You can do it in Labview, too; the student version should be available for free. Heck, just open up Hyperterminal and watch it! Or, get TeraTerm to do the same thing with logging capabilities and you've got your output in a text file to look at whenever you want. That depends, of course, on what kind of data you're expecting as most characters wouldn't look like much.
 

bobsmith1492

Diamond Member
Feb 21, 2004
3,875
3
81
Oh, don't forget that microcontrollers use logic-level RS232 while the computer output is more like 20V. Hook them straight together and BOOM! Of course you knew that, though...
 

BrownTown

Diamond Member
Dec 1, 2005
5,314
1
0
Originally posted by: bobsmith1492
Oh, don't forget that microcontrollers use logic-level RS232 while the computer output is more like 20V. Hook them straight together and BOOM! Of course you knew that, though...

Try reading the rest of the thread before posting? kthxbai
 

bobsmith1492

Diamond Member
Feb 21, 2004
3,875
3
81
Yeah, I see it - just making sure. I still recommend Tera Term and setting up your microcontroller code so you can do everything with text. It's easy as pie and skips any fooling around on the computer.
 

Mark R

Diamond Member
Oct 9, 1999
8,513
14
81
If you know VB.net or C#, then serial communication is dead simple.

Check out the System.IO.Ports.SerialPort class.
 

BrownTown

Diamond Member
Dec 1, 2005
5,314
1
0
Just an update on this topic, using the "System.IO.Ports.SerialPort" Class in Visual Basic, a MAX232 chip, and a PIC16F690 I was able to get Serial communications working for my senior project allowing me to speak with the microcontroller via RS232 with my computer such that commands can be sent to the microcontroller and data recieved from the microcontroller essentially allowing a user to remotely control the device in question (but only as far as the cable reaches , but this is proof of concept, could be sent to ethernet router or something).

Anyways, just wanted to tell everyone that I pretty much followed all your suggestions (MAX232 chip, System.IO.Ports.SerialPort, etc..) and ya'll were right this WAS quite easy to accomplish, especially with the help of so many knowledgeable people here at AnandTech willing to help .

EDIT: reason why it took so long was we working on some other hardware and stuff first, but I really got all this RS232 stuff done this weekend with only a few difficulties (like say spending an hour to figure my wires were backwards ).
 

Modelworks

Lifer
Feb 22, 2007
16,240
7
76
Glad it all worked out for you.
I always hate the rx , tx , wires part.
Some manufacturers set it up so rx connects with tx, some have it already set up do rx goes to rx.
Really fun sorting it out.
 

Analog

Lifer
Jan 7, 2002
12,755
3
0
This sounds like the last lab that I teach in my EE-422 class. We use a hyperterminal clone (hyperterminal sucks), and use the PIC18F4520 PICDEMO2+ board to send data (ASCII) to the PC, or receive primitive commands.

 

BrownTown

Diamond Member
Dec 1, 2005
5,314
1
0
Originally posted by: Analog
This sounds like the last lab that I teach in my EE-422 class. We use a hyperterminal clone (hyperterminal sucks), and use the PIC18F4520 PICDEMO2+ board to send data (ASCII) to the PC, or receive primitive commands.

I used the program "Realterm" for debugging because like you said Hyperterminal sux. In our microcontrollers class we did like that you are talking about and used Hyperterminal and it is just annoying. Having something like Realterm is nice because it outputs the status of the pins and stuff, so you can tell if signals are making it across your system, or what control pins are doing what (although I didn't use any of those). Also good for some debugging, since I'm using such a low baudrate I was overflowing the read buffer on the PIC (2 freak bytes!!), so it would cr@p out when you did that.
 

Biftheunderstudy

Senior member
Aug 15, 2006
375
1
81
LabVIEW is actually very easy for this sort of thing, there is a handy little "device" that talks to the serial port. The bonus is that LabVIEW is all visual so you don't have to mess around with prompts and terminals. Its like just making the GUI in other languages and then realizing your done, don't have to do any actual code. The only downfall is this only really only works in windows, I tried using linux and failed miserably....
 

TVisitor

Member
Jun 4, 2007
84
1
0
Originally posted by: Modelworks
Glad it all worked out for you.
I always hate the rx , tx , wires part.
Some manufacturers set it up so rx connects with tx, some have it already set up do rx goes to rx.
Really fun sorting it out.

Yeah - it depends if it's a DTE (Data Terminal Equipment) or DCE (Data Communications Equipment) device. When you connected a PC (DTE) to a Modem (DCE) that was the "common" thing to do, the cable was straight through (i.e. what looked like RX to RX, etc.) The RX label was a matter of perspective. RX on the DTE was the pin for the PC to receive data. The RX on the DCE equipment was the pin for which the modem output received data on.

When you connected DTE to DTE (such as 2 PC's back to back), you would use what was called a "NULL" model where you crossed the cable - RX to TX, TX to RX, GND to GND (and probably CTS to RTS, and RTS to CTS for handshaking).

Originally posted by: ScottMac
Do it in Perl.

Perl is so much fun! You could to the GUI in Tk, I know on a Windows platform ActiveState's stuff has Tk with it. O'Reilly has a Perl/Tk book out which is pretty good. Tk doesn't look like native windows stuff, but it certainly gets the job done.

 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |