473,699 Members | 2,628 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

display received data continously on console

10 New Member
hi there, i need to create a program to continously display the received binary data (2bytes) from COM 8 in a console, however I'm having problem in doing so where i do nt see any data being displayed on the console after i run and compile the created program. How can i solve this problem? please explain on how to display the data continously.... ...shown below is the programming...p lease check and comment..

im using WIndows XP, Visual C++ 6.0 compiler....
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <stdio.h>
  4. #include <time.h>
  5. #include <windows.h>
  6. #include <string.h>
  7. #include "serial.h"
  8.  
  9. // Flow control flags
  10.  
  11. #define FC_DTRDSR 0x01
  12. #define FC_RTSCTS 0x02
  13. #define FC_XONXOFF 0x04
  14.  
  15. // ascii definitions
  16.  
  17. #define ASCII_BEL 0x07
  18. #define ASCII_BS 0x08
  19. #define ASCII_LF 0x0A
  20. #define ASCII_CR 0x0D
  21. #define ASCII_XON 0x11
  22. #define ASCII_XOFF 0x13
  23.  
  24. using namespace std;
  25. // variables used with the com port
  26. BOOL bPortReady;
  27. DCB dcb;
  28. COMMTIMEOUTS CommTimeouts;
  29. BOOL bWriteRC;
  30. BOOL bReadRC;
  31. DWORD iBytesWritten;
  32. DWORD iBytesRead;
  33.  
  34.  
  35. HANDLE SerialInit(char *ComPortName, int BaudRate) 
  36.     {
  37.         HANDLE hCom;
  38.  
  39.         hCom = CreateFile(ComPortName, 
  40.                 GENERIC_READ| GENERIC_WRITE ,
  41.                 0, // exclusive access
  42.                 NULL, // no security
  43.                 OPEN_EXISTING,
  44.                 0, // no overlapped I/O
  45.                 NULL); // null template 
  46.  
  47.         bPortReady = SetupComm(hCom, 2, 128); // set buffer sizes
  48.  
  49.  
  50.         bPortReady = GetCommState(hCom, &dcb);
  51.         dcb.BaudRate = BaudRate;
  52.         dcb.ByteSize = 8;
  53.         dcb.Parity = NOPARITY;
  54.         // dcb.Parity = EVENPARITY;
  55.         dcb.StopBits = ONESTOPBIT;
  56.         dcb.fAbortOnError = TRUE;
  57.  
  58.         // set XON/XOFF
  59.         dcb.fOutX = FALSE; // XON/XOFF off for transmit
  60.         dcb.fInX = FALSE; // XON/XOFF off for receive
  61.         // set RTSCTS
  62.         dcb.fOutxCtsFlow = FALSE; // turn on CTS flow control
  63.         dcb.fRtsControl = RTS_CONTROL_HANDSHAKE; // 
  64.         // set DSRDTR
  65.         dcb.fOutxDsrFlow = FALSE; // turn on DSR flow control
  66.         dcb.fDtrControl = DTR_CONTROL_ENABLE; // 
  67.         // dcb.fDtrControl = DTR_CONTROL_DISABLE; // 
  68.         // dcb.fDtrControl = DTR_CONTROL_HANDSHAKE; // 
  69.  
  70.         bPortReady = SetCommState(hCom, &dcb);
  71.  
  72.         // Communication timeouts are optional
  73.  
  74.         bPortReady = GetCommTimeouts (hCom, &CommTimeouts);
  75.  
  76.         CommTimeouts.ReadIntervalTimeout = 5000;
  77.         CommTimeouts.ReadTotalTimeoutConstant = 5000;
  78.         CommTimeouts.ReadTotalTimeoutMultiplier = 1000;
  79.         CommTimeouts.WriteTotalTimeoutConstant = 5000;
  80.         CommTimeouts.WriteTotalTimeoutMultiplier = 1000;
  81.  
  82.         bPortReady = SetCommTimeouts (hCom, &CommTimeouts);
  83.  
  84.         return hCom;
  85.     }
  86.  
  87. char SerialGetc(HANDLE *hCom)
  88. {
  89.     char rxchar;
  90.     BOOL bReadRC;
  91.     static DWORD iBytesRead;
  92.  
  93.     bReadRC = ReadFile(*hCom, &rxchar, 2, &iBytesRead, NULL);
  94.     printf("%x", rxchar);
  95.  
  96.     return rxchar;
  97. }
  98.  
  99. void SerialPutc(HANDLE *hCom, char txchar)
  100. {
  101.     BOOL bWriteRC;
  102.     static DWORD iBytesWritten;
  103.  
  104.     bWriteRC = WriteFile(*hCom, &txchar, 1, &iBytesWritten,NULL);
  105.  
  106.     return;
  107. }
  108.  
  109. int main()
  110.  
  111.  
  112.     HANDLE my=SerialInit("com8",115200);
  113.     char letter;
  114.  
  115.  
  116.     HANDLE *ptr;
  117.     ptr=&my;
  118.     //SerialPutc(ptr,'a'); 
  119.  
  120.         letter=SerialGetc(ptr);
  121.         //printf("%x",letter);
  122.          getch(); 
  123.  
  124.  
  125.     return 0;
  126. }
  127.  
Feb 3 '07 #1
1 2068
horace1
1,510 Recognized Expert Top Contributor
have a look at this serial driver (it works under VC)
http://www.geocities.com/horacespide...V-C/terminal.c
- it emulates a terminal
(1) characters received from the serial port are displayed on the screen
(2) characters hit on keyboard are transmitted out of the serial port

I assume you can do a similar thing with your version
Feb 3 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1805
by: tim cummings via .NET 247 | last post by:
I am writing a program that interfaces with a cars pcm via theserial port and recieves data (such as rpm) at an interval, oflets say 1 second, and then formats it. The problem is, I wouldlike to display the data that is coming in over the port andhave it continously displayed until the user decides they wantthe data to stop. Currently the only way I have found to show the data in a"streaming" fashion is to loop the request, but once I do that...
3
1124
by: Hari | last post by:
Hi all, I have written a web service that receives large volume of data from consumers and process this data. When a consumer is sending large data (say xml files of 50KB) at frequent interval (say 50ms) for long period of time (5sec continously) i find that the method is not receiving all the data. This behaviour is not observed when consumer is sending small volume of data
2
6178
by: Lou | last post by:
I have a class that creates an instance of the seril Port. Every thing works fine except whenever I receive data I cannot display the recieved data. I get no errors but the recived data seems to just go no where. I can see the recived data in my serial receive function but when I either raise an event with it or try to display it in a text box nothing happens. I do use beginInvoke on the text box. If I trace the code through it all...
6
3881
sammyboy78
by: sammyboy78 | last post by:
I'm trying to display my array of objects in a GUI. How do I get JLabel to refer to the data in my objects? I've read my textbook and some tutorials online I just cannot get this. Plus all the examples I've seen are creating the information that will be displayed from scratch, while I have to use my previously created classes and add a GUI to it. I'm trying to do this GUI using JLabels but it won't let me refer to my CD class methods that...
0
8613
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9032
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8908
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8880
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7745
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6532
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5869
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2344
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.