Help writing a simple Ymodem Send

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2008
Posts: 1
Reputation: feru33 is an unknown quantity at this point 
Solved Threads: 0
feru33 feru33 is offline Offline
Newbie Poster

Help writing a simple Ymodem Send

 
0
  #1
Jun 13th, 2008
Hey there, I'm fairly new to programming but have been tasked with writing a Ymodem send program to send some data that I parsed out to hardware. So far I have parsed data into a char array, and then opened up a serial port. I just don't know where to begin in writing a Ymodem send program (the receiving end was written by someone else). Here is my code for opening the serial port, now I am stuck in implementing the actual Ymodem protocol. I have searched for code online but most of it makes use of extra libraries that I don't have. I am currently writing this in Visual C++ . Any help would be greatly appreciated, Thanks!

  1. #include "stdafx.h"
  2. #include "windows.h"
  3. #include "string.h"
  4. #include "stdio.h"
  5. #include "ymodem.h"
  6.  
  7.  
  8. HANDLE hComPort;
  9. BOOL SetCommDefaults(HANDLE hSerial);
  10.  
  11. int main()
  12. {
  13. hComPort = CreateFile("\\\\.\\COM24", GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
  14. if (hComPort == INVALID_HANDLE_VALUE){
  15. return FALSE;
  16. SetCommDefaults(hComPort);
  17. printf("E012_Failed to open port");
  18. }else{
  19.  
  20. SetCommDefaults(hComPort);
  21.  
  22. DWORD dwBytesRead =0;
  23. DWORD dwBytesWritten =1;
  24.  
  25. char buf[50];
  26.  
  27. sprintf(buf,"I am connected to hyperterminal\n");
  28.  
  29. WriteFile(hComPort, buf, strlen(buf), &dwBytesWritten,NULL);
  30. }
  31.  
  32. CloseHandle(hComPort);
  33.  
  34. return 0;
  35. }
  36.  
  37.  
  38. BOOL SetCommDefaults(HANDLE hComPort)
  39. {
  40. DCB dcb;
  41. dcb.BaudRate = 115200;
  42. dcb.ByteSize = 8;
  43. dcb.Parity = 0;
  44. dcb.StopBits = ONESTOPBIT;
  45. dcb.fDtrControl = DTR_CONTROL_DISABLE;
  46. dcb.fDtrControl = RTS_CONTROL_DISABLE;
  47.  
  48. if(!SetCommState(hComPort, &dcb))
  49. return FALSE;
  50. return TRUE;
  51. }
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC