943,096 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1260
  • C++ RSS
Jun 13th, 2008
0

Help writing a simple Ymodem Send

Expand Post »
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!

C++ Syntax (Toggle Plain Text)
  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. }
Reputation Points: 10
Solved Threads: 0
Newbie Poster
feru33 is offline Offline
1 posts
since Jun 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Form Is Scrolling Down
Next Thread in C++ Forum Timeline: Problems parsing arguments.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC