C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-31-2001, 09:39 AM   #1
Registered User
 
Join Date: Oct 2001
Posts: 14
serial port still wont work

Below are first my main file and then the port write function I have got no errors but i dont know where I am going wrong as the 3 byte protocol still wont send to the serial port!! can anyone help me achieve the impossible and send the three byte protocol??
thanks



/************************************************** *********************

WINMAIN ( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)

************************************************** *********************/

int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)



{


hPort = INVALID_HANDLE_VALUE; // Serial port handle
hReadThread = NULL; // Handle to the read thread

unsigned char Bytes[3] = { 255, 1, 127 } ;

lpszDevName = TEXT("COM1:");

// Initialize the port.
if (!PortInitialize (lpszDevName))
{
return 0 ;
}


PortWrite(Bytes) ;

PortClose(hPort) ;


return 0 ;

}



/************************************************** *********************

PortWrite (BYTE Byte)

************************************************** *********************/
void PortWrite (unsigned char *Bytes)
{
DWORD dwError,
dwNumBytesWritten;


if (!WriteFile (hPort, // Port handle
&Bytes, // Pointer to the data to write
3, // Number of bytes to write
&dwNumBytesWritten, // Pointer to the number of bytes
// written
NULL)) // Must be NULL for Windows CE
{
// WriteFile failed. Report error.
dwError = GetLastError ();
}
}
alcoholic is offline   Reply With Quote
Old 10-31-2001, 09:51 AM   #2
Registered User
 
Join Date: Sep 2001
Posts: 156
Its difficult to debug what you've got since it is incomplete.

I would recommend looking at http://www.programmersheaven.com/zone3/cat411/index.htm
Dang is offline   Reply With Quote
Old 10-31-2001, 09:56 AM   #3
Registered User
 
Join Date: Oct 2001
Posts: 14
could i mail you my code in full so that you can spot why it wont send the bytes to the serial port??
alcoholic is offline   Reply With Quote
Old 10-31-2001, 10:23 AM   #4
Registered User
 
Join Date: Sep 2001
Posts: 156
No problem. Just push the email button and enter your code. Please use "CODE" (replace " with [ and ] respectively) to start code and "/CODE"to end it. This will keep it much cleaner.
Dang is offline   Reply With Quote
Old 10-31-2001, 12:08 PM   #5
It's full of stars
 
adrianxw's Avatar
 
Join Date: Aug 2001
Posts: 4,833
Just a simple question, are you sure you understand the passing of char * to functions?
__________________
Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.
adrianxw is offline   Reply With Quote
Old 10-31-2001, 12:12 PM   #6
and the hat of Jobseeking
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,650
Doesn't look like it
> void PortWrite (unsigned char *Bytes)
...
> &Bytes, // Pointer to the data to write
This isn't true
It should be Bytes or &Bytes[0]
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.

Salem is offline   Reply With Quote
Old 10-31-2001, 12:51 PM   #7
It's full of stars
 
adrianxw's Avatar
 
Join Date: Aug 2001
Posts: 4,833
__________________
Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.
adrianxw is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
sending streams over serial port in win32 deian C Programming 2 07-13-2009 12:01 PM
serial port to poll on request infineonintern C++ Programming 2 06-11-2009 06:52 AM
Serial port Communication vin_pll C++ Programming 23 01-07-2009 09:32 AM
brace-enclosed error jdc18 C++ Programming 53 05-03-2007 05:49 PM
Problem with string and serial port collinm C Programming 2 03-23-2005 10:19 AM


All times are GMT -6. The time now is 10:29 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22