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.... -
#include <iostream>
-
#include <conio.h>
-
#include <stdio.h>
-
#include <time.h>
-
#include <windows.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 hCom;
-
-
hCom = CreateFile(ComPortName,
-
GENERIC_READ| GENERIC_WRITE ,
-
0, // exclusive access
-
NULL, // no security
-
OPEN_EXISTING,
-
0, // no overlapped I/O
-
NULL); // null template
-
-
bPortReady = SetupComm(hCom, 2, 128); // set buffer sizes
-
-
-
bPortReady = GetCommState(hCom, &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 = FALSE; // 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(hCom, &dcb);
-
-
// Communication timeouts are optional
-
-
bPortReady = GetCommTimeouts (hCom, &CommTimeouts);
-
-
CommTimeouts.ReadIntervalTimeout = 5000;
-
CommTimeouts.ReadTotalTimeoutConstant = 5000;
-
CommTimeouts.ReadTotalTimeoutMultiplier = 1000;
-
CommTimeouts.WriteTotalTimeoutConstant = 5000;
-
CommTimeouts.WriteTotalTimeoutMultiplier = 1000;
-
-
bPortReady = SetCommTimeouts (hCom, &CommTimeouts);
-
-
return hCom;
-
}
-
-
char SerialGetc(HANDLE *hCom)
-
{
-
char rxchar;
-
BOOL bReadRC;
-
static DWORD iBytesRead;
-
-
bReadRC = ReadFile(*hCom, &rxchar, 2, &iBytesRead, NULL);
-
printf("%x", rxchar);
-
-
return rxchar;
-
}
-
-
void SerialPutc(HANDLE *hCom, char txchar)
-
{
-
BOOL bWriteRC;
-
static DWORD iBytesWritten;
-
-
bWriteRC = WriteFile(*hCom, &txchar, 1, &iBytesWritten,NULL);
-
-
return;
-
}
-
-
int main()
-
{
-
-
-
HANDLE my=SerialInit("com8",115200);
-
char letter;
-
-
-
HANDLE *ptr;
-
ptr=&my;
-
//SerialPutc(ptr,'a');
-
-
letter=SerialGetc(ptr);
-
//printf("%x",letter);
-
getch();
-
-
-
return 0;
-
}
-
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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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
|
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...
|
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...
|
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,...
| |
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...
|
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,...
|
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...
|
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...
|
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...
|
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();...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |