Click here to Skip to main content
16,006,768 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Generalwell done !!!!! It was realy silly misprint! Pin
12-Jun-01 19:25
suss12-Jun-01 19:25 
General*.dsw and Borland Compiler Pin
12-Jun-01 8:19
suss12-Jun-01 8:19 
GeneralRe: *.dsw and Borland Compiler Pin
Tim Deveaux12-Jun-01 12:18
Tim Deveaux12-Jun-01 12:18 
GeneralSerial Port Communication. Pin
John Uhlenbrock12-Jun-01 7:44
John Uhlenbrock12-Jun-01 7:44 
GeneralRe: Serial Port Communication. Pin
John Uhlenbrock12-Jun-01 8:55
John Uhlenbrock12-Jun-01 8:55 
GeneralRe: Serial Port Communication. Pin
Eric Hansen12-Jun-01 9:52
Eric Hansen12-Jun-01 9:52 
GeneralRe: Serial Port Communication. Pin
12-Jun-01 22:38
suss12-Jun-01 22:38 
GeneralRe: Serial Port Communication. Pin
Eric Hansen12-Jun-01 9:49
Eric Hansen12-Jun-01 9:49 
I couldn't find any classes in MFC for Serial Port Comms back when I was looking (about one year ago) so I started to write one...but that project has been on hold for a LONG while now. Unfortunately I'm a bit short on time right now so I'm just going to cut up some of my code send it along, hope it helps (I've never posted code to one of these but I have a feeling this isn't going to be that easy to read Frown | :( ).

Opening a port:

if (portOpen)
{
return portHandle;
}
else
{
// Try to open the comm port
char str[30];
sprintf( str, "\\\\.\\COM%d", portNum );

HANDLE hCom;
DWORD dwError;

hCom = CreateFile( str,
GENERIC_READ | GENERIC_WRITE,
0, // comm devices must be opened w/exclusive-access
NULL, // no security attributes
OPEN_EXISTING, // comm devices must use OPEN_EXISTING
0, // not overlapped I/O
NULL // hTemplate must be NULL for comm devices
);
if (hCom == INVALID_HANDLE_VALUE)
{
dwError = GetLastError();
TRACE0("Invalid Comm Handle in openPort()\n");
// handle error
return NULL;
}
else
{
portOpen = true;
portHandle = hCom;
return hCom;
}
}





Example of writing to and reading a response from a comm port (setting baud rate etc):

DCB dcb;
fSuccess = GetCommState(portHndl, &dcb);
if (!fSuccess)
{
// Handle the error.
}
dcb.BaudRate = 9600;
dcb.ByteSize = 8;
dcb.Parity = NOPARITY;
dcb.StopBits = ONESTOPBIT;
fSuccess = SetCommState(portHndl, &dcb);
if (!fSuccess)
{
// Handle the error.
}

//unsigned char lpData[140] = {1,0,0,16,85,0,1,0,0,0,0,0,0,0,0,103 };
DWORD numActual = 0;
OVERLAPPED osWrite = {0};
BOOL succ;
DWORD error;

succ = WriteFile(portHndl,
sendBuffer, //Data to write to comm port
sendBytes, //number of bytes to write
&numActual, //pointer to number of bytes written
&osWrite // pointer to structure for overlapped I/O
);

if (!succ)
{
error = GetLastError();
TRACE("Bad Comm Write: %d,%d\n",portHndl,error);
}
else
TRACE("Good Comm Write: %d,%d\n",portHndl,error);

succ = ReadFile(portHndl, // handle of file to read
receiveBuffer, // pointer to buffer that receives data
receiveBytes, // number of bytes to read
&numActual, // pointer to number of bytes read
&osWrite // pointer to structure for data
);
if (!succ)
error = GetLastError();

Eric Hansen

ehansen@pmsi.cc
GeneralReplacing file types combo in CFileDialog Pin
12-Jun-01 6:54
suss12-Jun-01 6:54 
GeneralRe: Replacing file types combo in CFileDialog Pin
Ben Burnett12-Jun-01 12:08
Ben Burnett12-Jun-01 12:08 
GeneralRe: Replacing file types combo in CFileDialog Pin
18-Jun-01 6:39
suss18-Jun-01 6:39 
GeneralRe: Replacing file types combo in CFileDialog Pin
20-Jun-01 9:21
suss20-Jun-01 9:21 
QuestionMultimedia in MFC?? Pin
Rickard Andersson2012-Jun-01 6:24
Rickard Andersson2012-Jun-01 6:24 
AnswerRe: Multimedia in MFC?? Pin
RobJones12-Jun-01 7:16
RobJones12-Jun-01 7:16 
AnswerRe: Multimedia in MFC?? Pin
RobJones12-Jun-01 7:18
RobJones12-Jun-01 7:18 
GeneralRunning Programs & Waiting For Them To Finish Pin
Jason Teagle12-Jun-01 4:35
Jason Teagle12-Jun-01 4:35 
GeneralRe: Running Programs & Waiting For Them To Finish Pin
Tomasz Sowinski12-Jun-01 4:44
Tomasz Sowinski12-Jun-01 4:44 
GeneralRe: Running Programs & Waiting For Them To Finish Pin
Jason Teagle12-Jun-01 5:37
Jason Teagle12-Jun-01 5:37 
GeneralRe: Running Programs & Waiting For Them To Finish Pin
Tomasz Sowinski12-Jun-01 5:53
Tomasz Sowinski12-Jun-01 5:53 
GeneralRe: Running Programs & Waiting For Them To Finish Pin
Jason Teagle12-Jun-01 5:58
Jason Teagle12-Jun-01 5:58 
GeneralRe: Running Programs & Waiting For Them To Finish Pin
Tomasz Sowinski12-Jun-01 6:11
Tomasz Sowinski12-Jun-01 6:11 
GeneralRe: Running Programs & Waiting For Them To Finish Pin
Stephen Kellett13-Jun-01 0:01
Stephen Kellett13-Jun-01 0:01 
GeneralRe: Running Programs & Waiting For Them To Finish Pin
Jason Teagle13-Jun-01 0:17
Jason Teagle13-Jun-01 0:17 
GeneralRe: Running Programs & Waiting For Them To Finish Pin
#realJSOP13-Jun-01 1:03
professional#realJSOP13-Jun-01 1:03 
GeneralRe: Running Programs & Waiting For Them To Finish Pin
Carlos Antollini12-Jun-01 4:55
Carlos Antollini12-Jun-01 4:55 

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.