Click here to Skip to main content
15,890,282 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
AnswerRe: Please determine the output Pin
Christian Graus27-Sep-06 19:12
protectorChristian Graus27-Sep-06 19:12 
GeneralRe: Please determine the output Pin
Sushant Duggal27-Sep-06 19:38
Sushant Duggal27-Sep-06 19:38 
GeneralRe: Please determine the output Pin
Christian Graus27-Sep-06 19:45
protectorChristian Graus27-Sep-06 19:45 
QuestionRe: Please determine the output [modified] Pin
Sushant Duggal27-Sep-06 21:03
Sushant Duggal27-Sep-06 21:03 
AnswerRe: Please determine the output Pin
Nish Nishant28-Sep-06 5:57
sitebuilderNish Nishant28-Sep-06 5:57 
QuestionProblem in using CList Pin
GudduRanchi26-Sep-06 23:48
GudduRanchi26-Sep-06 23:48 
AnswerRe: Problem in using CList Pin
Christian Graus27-Sep-06 12:47
protectorChristian Graus27-Sep-06 12:47 
QuestionSerial port communication using C++ Pin
prashw26-Sep-06 23:02
prashw26-Sep-06 23:02 
hey...........

i managed to compile and run a C++ program that intializes and reads/writes to a serial port . I was using the Dev C++ compiler to write the code.


Now I am trying to verify the output.What I did was to write the letter 'a' to the serial port. The serial port is connected to a digital oscilloscope and I intend to see the voltage patterns that correspond to the letter 'a' as below.

11 01000001 0 = stop bits / data bits / start bit


But this voltage pattern is not shown in the oscilloscope. Instead I only see the handshaking signal (a data bit '1') coming from the serial port.( I was able to see the handshaking control signal/initializing signal but not the data signal (the data signal was the letter 'a') ).
I saw a '1' from pin 3 and pin 6 of the R232 serial port when I ran the program. These pins correspond to Transmit data, Data set ready signals that are sent from the laptop to the oscilloscope.

1. I cannot see any data signals corresponding to the letter 'a'. What is the reason behind this????
Is it because there is no reply from the oscilloscope for the handshaking signal the laptop sends to it?? (i am using a laptop to run the program)
(Meaning the oscilloscope fails to send a handshking signal back to the laptop......this might indeed be the case because oscilloscopes are not built to send handshking signals)

2.If so how can I bypass sending handshking signals and simply send the letter 'a' to the oscilloscope and view its voltage pattern???

3.Can I do this by a simple adjustemnt to the code I have written below????



I would greatly appreciate any help u guys can give....

the code is below (compiles without errors on Dev C++ )



Serial.h
CODE
CODE// Flow control flags

#define FC_DTRDSR 0x01
#define FC_RTSCTS 0x02
#define FC_XONXOFF 0x04

// ascii definitions
#include <stdio.h>
#include <time.h>

//#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#include <string.h>

#define ASCII_BEL 0x07
#define ASCII_BS 0x08
#define ASCII_LF 0x0A
#define ASCII_CR 0x0D
#define ASCII_XON 0x11
#define ASCII_XOFF 0x13


HANDLE SerialInit(char*, int);

char SerialGetc(HANDLE*);

void SerialPutc(HANDLE*, char);


--------------------------------------------------------------------------


Serial.cpp
CODE
CODE
#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 = 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(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, 1, &iBytesRead, NULL);

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("com1",1200);
char letter;

HANDLE *ptr;
*ptr=my;
SerialPutc(ptr,'a');
//letter=SerialGetc(ptr);
getch();

return 0;

}

hi
AnswerRe: Serial port communication using C++ Pin
Christian Graus27-Sep-06 13:12
protectorChristian Graus27-Sep-06 13:12 
GeneralRe: Serial port communication using C++ Pin
prashw27-Sep-06 20:27
prashw27-Sep-06 20:27 
GeneralRe: Serial port communication using C++ Pin
Christian Graus27-Sep-06 21:16
protectorChristian Graus27-Sep-06 21:16 
QuestionCreation of OCX in Borlands c++ Pin
zareee26-Sep-06 20:07
zareee26-Sep-06 20:07 
AnswerRe: Creation of OCX in Borlands c++ Pin
Christian Graus27-Sep-06 13:13
protectorChristian Graus27-Sep-06 13:13 
GeneralRe: Creation of OCX in Borlands c++ Pin
zareee27-Sep-06 19:21
zareee27-Sep-06 19:21 
GeneralRe: Creation of OCX in Borlands c++ Pin
Christian Graus27-Sep-06 19:34
protectorChristian Graus27-Sep-06 19:34 
GeneralRe: Creation of OCX in Borlands c++ Pin
zareee27-Sep-06 22:49
zareee27-Sep-06 22:49 
QuestionManaged to unmanaged debugger transition Pin
User 58385226-Sep-06 16:48
User 58385226-Sep-06 16:48 
AnswerRe: Managed to unmanaged debugger transition Pin
led mike27-Sep-06 8:09
led mike27-Sep-06 8:09 
GeneralRe: Managed to unmanaged debugger transition Pin
User 58385227-Sep-06 12:42
User 58385227-Sep-06 12:42 
QuestionQueryInterface in managed code Pin
lafleon26-Sep-06 15:16
lafleon26-Sep-06 15:16 
AnswerRe: QueryInterface in managed code Pin
User 58385226-Sep-06 16:38
User 58385226-Sep-06 16:38 
GeneralRe: QueryInterface in managed code Pin
lafleon26-Sep-06 17:43
lafleon26-Sep-06 17:43 
GeneralRe: QueryInterface in managed code Pin
User 58385226-Sep-06 17:48
User 58385226-Sep-06 17:48 
QuestionString.Split not functioning correctly? Pin
jmlsteele26-Sep-06 9:14
jmlsteele26-Sep-06 9:14 
AnswerRe: String.Split not functioning correctly? Pin
led mike26-Sep-06 10:11
led mike26-Sep-06 10:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.