Serial communication using DEV CPP IDE 4.9.9.2

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2006
Posts: 327
Reputation: Colin Mac is on a distinguished road 
Solved Threads: 22
Colin Mac Colin Mac is offline Offline
Posting Whiz

Re: Serial communication using DEV CPP IDE 4.9.9.2

 
1
  #11
Dec 23rd, 2007
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
Last edited by Colin Mac; Dec 23rd, 2007 at 9:10 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 514
Reputation: Jishnu will become famous soon enough Jishnu will become famous soon enough 
Solved Threads: 26
Jishnu's Avatar
Jishnu Jishnu is offline Offline
Posting Pro

Re: Serial communication using DEV CPP IDE 4.9.9.2

 
0
  #12
Dec 23rd, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 40
Reputation: danibootstrap is an unknown quantity at this point 
Solved Threads: 0
danibootstrap danibootstrap is offline Offline
Light Poster

Re: Serial communication using DEV CPP IDE 4.9.9.2

 
0
  #13
Dec 27th, 2007
Originally Posted by ssharish2005 View Post
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 dont want to use hypertermiaml..I want to have my own standard window where I can send and receive.I want to add more functionality to this and hyperterminal window will not serve that.I am using Dev C++ 4.9.9.2 .The above code was working only in Turbo C compiler.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 514
Reputation: Jishnu will become famous soon enough Jishnu will become famous soon enough 
Solved Threads: 26
Jishnu's Avatar
Jishnu Jishnu is offline Offline
Posting Pro

Re: Serial communication using DEV CPP IDE 4.9.9.2

 
0
  #14
Dec 27th, 2007
I am using Dev C++ 4.9.9.2 .The above code was working only in Turbo C compiler.
It is obvious from the earlier posts. Try AD's suggestions..
"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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 40
Reputation: danibootstrap is an unknown quantity at this point 
Solved Threads: 0
danibootstrap danibootstrap is offline Offline
Light Poster

Re: Serial communication using DEV CPP IDE 4.9.9.2

 
0
  #15
Jan 14th, 2008
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.

  1. #include <iostream>
  2. #include <conio.h>
  3. #include <stdio.h>
  4. #include <time.h>
  5. #include <windows.h>
  6.  
  7. #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
  8. #include <bios.h>
  9. //#include <afxwin.h> // serial.cpp : Defines the entry point for the console application.
  10.  
  11. //#include "stdafx.h"
  12. #include <string.h>
  13. #include "serial.h"
  14.  
  15. // Flow control flags
  16.  
  17. #define FC_DTRDSR 0x01
  18. #define FC_RTSCTS 0x02
  19. #define FC_XONXOFF 0x04
  20.  
  21. // ascii definitions
  22.  
  23. #define ASCII_BEL 0x07
  24. #define ASCII_BS 0x08
  25. #define ASCII_LF 0x0A
  26. #define ASCII_CR 0x0D
  27. #define ASCII_XON 0x11
  28. #define ASCII_XOFF 0x13
  29. using namespace std;
  30. // variables used with the com port
  31. BOOL bPortReady;
  32. DCB dcb;
  33. COMMTIMEOUTS CommTimeouts;
  34. BOOL bWriteRC;
  35. BOOL bReadRC;
  36. DWORD iBytesWritten;
  37. DWORD iBytesRead;
  38.  
  39. HANDLE SerialInit(char *ComPortName, int BaudRate)
  40. {
  41. HANDLE hComm;
  42.  
  43. hComm = CreateFile(ComPortName,
  44. GENERIC_READ | GENERIC_WRITE,
  45. 0, // exclusive access
  46. NULL, // no security
  47. OPEN_EXISTING,
  48. 0, // no overlapped I/O
  49. NULL); // null template
  50.  
  51. bPortReady = SetupComm(hComm, 1, 128); // set buffer sizes
  52.  
  53.  
  54. bPortReady = GetCommState(hComm, &dcb);
  55. dcb.BaudRate = BaudRate;
  56. dcb.ByteSize = 8;
  57. dcb.Parity = NOPARITY;
  58. //dcb.Parity = EVENPARITY;
  59. dcb.StopBits = ONESTOPBIT;
  60. dcb.fAbortOnError = TRUE;
  61.  
  62. // set XON/XOFF
  63. dcb.fOutX = FALSE; // XON/XOFF off for transmit
  64. dcb.fInX = FALSE; // XON/XOFF off for receive
  65. // set RTSCTS
  66. dcb.fOutxCtsFlow = TRUE; // turn on CTS flow control
  67. dcb.fRtsControl = RTS_CONTROL_HANDSHAKE; //
  68. // set DSRDTR
  69. dcb.fOutxDsrFlow = FALSE; // turn on DSR flow control
  70. dcb.fDtrControl = DTR_CONTROL_ENABLE; //
  71. dcb.fDtrControl = DTR_CONTROL_DISABLE; //
  72. dcb.fDtrControl = DTR_CONTROL_HANDSHAKE; //
  73.  
  74. bPortReady = SetCommState(hComm, &dcb);
  75.  
  76. // Communication timeouts are optional
  77.  
  78. bPortReady = GetCommTimeouts (hComm, &CommTimeouts);
  79.  
  80. CommTimeouts.ReadIntervalTimeout = 5;
  81. CommTimeouts.ReadTotalTimeoutConstant = 5;
  82. CommTimeouts.ReadTotalTimeoutMultiplier = 1;
  83. CommTimeouts.WriteTotalTimeoutConstant = 5;
  84. CommTimeouts.WriteTotalTimeoutMultiplier = 1;
  85.  
  86. bPortReady = SetCommTimeouts (hComm, &CommTimeouts);
  87.  
  88. return hComm;
  89. }
  90.  
  91. char SerialGetc(HANDLE *hComm)
  92. {
  93. char rxchar;
  94. BOOL bReadRC;
  95. static DWORD iBytesRead;
  96.  
  97. bReadRC = ReadFile(*hComm, &rxchar, 1, &iBytesRead, NULL);
  98.  
  99. return rxchar;
  100. }
  101.  
  102. void SerialPutc(HANDLE *hComm, char txchar)
  103. {
  104. BOOL bWriteRC;
  105. static DWORD iBytesWritten;
  106.  
  107. bWriteRC = WriteFile(*hComm, &txchar, 1, &iBytesWritten,NULL);
  108.  
  109. return;
  110. }
  111.  
  112. int main()
  113. {
  114. HANDLE my=SerialInit("com1",9600);
  115. char letter;
  116. printf("ranjan\n");
  117.  
  118. HANDLE *ptr;
  119. *ptr=my;
  120. for( ; ; )
  121. {
  122.  
  123. SerialPutc(ptr,'a');
  124.  
  125. }
  126. getch();
  127.  
  128. return 0;
  129.  
  130. }
Last edited by WolfPack; Jan 14th, 2008 at 6:11 am. Reason: ADDED [CODE][/CODE] TAGS.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC