| | |
Serial communication using DEV CPP IDE 4.9.9.2
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Sep 2006
Posts: 327
Reputation:
Solved Threads: 22
If you must write a program for the PC side under XP. You can use the SerialPort class in .NET. There's lots of information on the net about using VB for uCs. You don't have to use win32.
http://users.tpg.com.au/gramo/Site/rs232.htm
http://users.tpg.com.au/gramo/Site/rs232.htm
Last edited by Colin Mac; Dec 23rd, 2007 at 9:10 am.
In case of VB, try searching for MSComm controls on google.
"You know you're a computer geek when you try to shoo a fly away from the monitor screen with your cursor. That just happened to me. It was scary." - Juuso Heimonen.
"The only truly secure computer is one buried in concrete, with the power turned off and the network cable cut." - Anonymous.
"The only truly secure computer is one buried in concrete, with the power turned off and the network cable cut." - Anonymous.
•
•
Join Date: Dec 2007
Posts: 40
Reputation:
Solved Threads: 0
•
•
•
•
First of all, the mistake you have been doing is using Turbo C compiler and getting confused between code written for MS-DOS and Windows OS. STOP using your Turbo C compile and just focus on things which are more standard.
>I want to know why the above code i mentioned is getting compiled in TC but not DEV CPP IDE >and how to make it run in DEV CPP IDE 4.9.9.2
You can already see from the error message thrown by the compile on Dev-C++. You have been using some non standard library which was available under TC. But, Dev-C++ doest support those libraries what so ever.
And now explain us, why do you need this code. What is the main purpose of writing this code? What I understand from your post is that, you trying to use this program send and receive data between your microcontroller and your PC. If that was your main intention, there is already inbuilt terminal emulator "HyperTerminal" which does that for you. Where you can transfer your binary to your MController.
If that wasn't your intention, Can you explain you what are you trying to do?
And on the other hand, have a look at the links which I posted in my previous post, there is an article on how to program a serial port for Windows. Its a good Article which was taken from MSDN. If you follow that you will be able to achieve something on Dev-C++.
And start thinking STANDARDS.
ssharish
•
•
•
•
I am using Dev C++ 4.9.9.2 .The above code was working only in Turbo C compiler.
"You know you're a computer geek when you try to shoo a fly away from the monitor screen with your cursor. That just happened to me. It was scary." - Juuso Heimonen.
"The only truly secure computer is one buried in concrete, with the power turned off and the network cable cut." - Anonymous.
"The only truly secure computer is one buried in concrete, with the power turned off and the network cable cut." - Anonymous.
•
•
Join Date: Dec 2007
Posts: 40
Reputation:
Solved Threads: 0
The following code (.cpp for DevCpp, Windows) is for sending characters out from the serial port (com1 ,9600,no parity ,one stop bit).
But I am not getting any output from the serial port.As of now I am sending the char 'a' out but I am not observing it.Can anyone help me rectify the code.
But I am not getting any output from the serial port.As of now I am sending the char 'a' out but I am not observing it.Can anyone help me rectify the code.
cpp Syntax (Toggle Plain Text)
#include <iostream> #include <conio.h> #include <stdio.h> #include <time.h> #include <windows.h> #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers #include <bios.h> //#include <afxwin.h> // serial.cpp : Defines the entry point for the console application. //#include "stdafx.h" #include <string.h> #include "serial.h" // Flow control flags #define FC_DTRDSR 0x01 #define FC_RTSCTS 0x02 #define FC_XONXOFF 0x04 // ascii definitions #define ASCII_BEL 0x07 #define ASCII_BS 0x08 #define ASCII_LF 0x0A #define ASCII_CR 0x0D #define ASCII_XON 0x11 #define ASCII_XOFF 0x13 using namespace std; // variables used with the com port BOOL bPortReady; DCB dcb; COMMTIMEOUTS CommTimeouts; BOOL bWriteRC; BOOL bReadRC; DWORD iBytesWritten; DWORD iBytesRead; HANDLE SerialInit(char *ComPortName, int BaudRate) { HANDLE hComm; hComm = CreateFile(ComPortName, GENERIC_READ | GENERIC_WRITE, 0, // exclusive access NULL, // no security OPEN_EXISTING, 0, // no overlapped I/O NULL); // null template bPortReady = SetupComm(hComm, 1, 128); // set buffer sizes bPortReady = GetCommState(hComm, &dcb); dcb.BaudRate = BaudRate; dcb.ByteSize = 8; dcb.Parity = NOPARITY; //dcb.Parity = EVENPARITY; dcb.StopBits = ONESTOPBIT; dcb.fAbortOnError = TRUE; // set XON/XOFF dcb.fOutX = FALSE; // XON/XOFF off for transmit dcb.fInX = FALSE; // XON/XOFF off for receive // set RTSCTS dcb.fOutxCtsFlow = TRUE; // turn on CTS flow control dcb.fRtsControl = RTS_CONTROL_HANDSHAKE; // // set DSRDTR dcb.fOutxDsrFlow = FALSE; // turn on DSR flow control dcb.fDtrControl = DTR_CONTROL_ENABLE; // dcb.fDtrControl = DTR_CONTROL_DISABLE; // dcb.fDtrControl = DTR_CONTROL_HANDSHAKE; // bPortReady = SetCommState(hComm, &dcb); // Communication timeouts are optional bPortReady = GetCommTimeouts (hComm, &CommTimeouts); CommTimeouts.ReadIntervalTimeout = 5; CommTimeouts.ReadTotalTimeoutConstant = 5; CommTimeouts.ReadTotalTimeoutMultiplier = 1; CommTimeouts.WriteTotalTimeoutConstant = 5; CommTimeouts.WriteTotalTimeoutMultiplier = 1; bPortReady = SetCommTimeouts (hComm, &CommTimeouts); return hComm; } char SerialGetc(HANDLE *hComm) { char rxchar; BOOL bReadRC; static DWORD iBytesRead; bReadRC = ReadFile(*hComm, &rxchar, 1, &iBytesRead, NULL); return rxchar; } void SerialPutc(HANDLE *hComm, char txchar) { BOOL bWriteRC; static DWORD iBytesWritten; bWriteRC = WriteFile(*hComm, &txchar, 1, &iBytesWritten,NULL); return; } int main() { HANDLE my=SerialInit("com1",9600); char letter; printf("ranjan\n"); HANDLE *ptr; *ptr=my; for( ; ; ) { SerialPutc(ptr,'a'); } getch(); return 0; }
Last edited by WolfPack; Jan 14th, 2008 at 6:11 am. Reason: ADDED [CODE][/CODE] TAGS.
![]() |
Other Threads in the C Forum
- Previous Thread: undefined reference to....
- Next Thread: About /proc/stat ???
| Thread Tools | Search this Thread |
#include adobe ansi api append array arrays asterisks binarysearch changingto char character cm copyimagefile cprogramme creafecopyofanytypeoffileinc csyntax database directory dynamic execv feet fgets file fork framework frequency function getlasterror givemetehcodez global grade gtkgcurlcompiling hacking hardware highest histogram include incrementoperators infiniteloop input interest kernel keyboard kilometer license linked linkedlist linux linuxsegmentationfault list lists locate logical_drives looping loopinsideloop. lowest match matrix meter microsoft motherboard mqqueue number odf opensource overwrite owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv repetition research reversing scripting segmentationfault sequential socket socketprograming standard string systemcall testing threads turboc unix user voidmain() wab windows.h windowsapi





