1

I am working on a project and I'm trying to figure out how I'm going to write to the serial port. Since my laptop does not have a serial port, I have purchased a USB to serial adapter. Now I need to send data from my C program to the serial port but I do not know how to address the port. Does anyone have any idea how this is done?

When I had worked on a Windows 98 I used outportb() to address the parallel port but this will not work on Windows 7.

(I am using Windows 7 64 bit.)

dsolimano
  • 8,870
  • 3
  • 48
  • 63
Tamara Caligari
  • 479
  • 3
  • 12
  • 28

1 Answers1

1

There is a nice tutorial on MSDN about that topic. You can also find a more basic How-to here. If you have problems with any part of it, don't hesitate to ask here.

Good luck

Frank Bollack
  • 24,478
  • 5
  • 49
  • 58
  • I have taken a look at that link already but since I have very basic knowledge in programming I found it a bit complicated :/ Is there a simpler way? – Tamara Caligari Mar 22 '12 at 11:22
  • There's always a simpler way, but it heavily depends on your specific problem. What does the communication look like, what have you done so far, what tools are you developing with. Please extend your question to make things clearer. As always, broad question, broad answers. – Frank Bollack Mar 22 '12 at 11:30
  • So far I have written a program in C which controls a counter using arrow keys. (As in when I press the key 'A', the value of the counter increases etc...) The value of this counter is to be sent via usb - RS232 port and then to a transceiver. – Tamara Caligari Mar 22 '12 at 11:36
  • I added another link that is a bit more basic, but the standard way of doing serial communicaion on Win32 platforms is simply that way. – Frank Bollack Mar 22 '12 at 12:06
  • Hi I found this link: http://cboard.cprogramming.com/networking-device-communication/119973-rs232-serial-port-library-linux-windows.html and I downloaded the files. However, I am getting compilation errors: "'PortDCB' : undeclared identifier " :S – Tamara Caligari Mar 28 '12 at 10:41
  • This library is for the [MinGW](http://www.mingw.org) compiler on Windows, not for Visual Studio. Have you tried the sample code from the 2nd link? – Frank Bollack Mar 28 '12 at 10:58
  • The code is pretty much the same though - I'm only getting compiler errors and the link you gave me has the same code so I'll get the same errors. Is there a header file which I need to add apart from ? – Tamara Caligari Mar 28 '12 at 11:27
  • [MSDN](http://msdn.microsoft.com/en-us/library/windows/desktop/aa363214.aspx) states, you only need ``. What development environment do you use? Can you post your fully (not) working example? – Frank Bollack Mar 28 '12 at 11:49
  • I have changed the language to Visual Basic and the connection to the serial port is much easier. I am using forms with Serial.Write() – Tamara Caligari Apr 04 '12 at 19:03