![]() |
| | #1 |
| Registered User Join Date: Oct 2001
Posts: 14
| serial port still wont work 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 | |
| | #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 | |
| | #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 | |
| | #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 | |
| | #5 |
| It's full of stars 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 | |
| | #6 |
| and the hat of Jobseeking 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] |
| Salem is offline | |
| | #7 |
| It's full of stars Join Date: Aug 2001
Posts: 4,833
|
__________________ Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream. |
| adrianxw is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
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 |