Old fashion design for PC-104
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.3 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 08/10/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: BoardReceiverSwitcher.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of BoardReceiverSwitcher.cpp
  13. //----------------------------------------------------------------------------
  14. // BoardReceiverSwitcher.cpp: implementation of the CBoardReceiverSwitcher class.
  15. //
  16. //////////////////////////////////////////////////////////////////////
  17. #include "stdafx.h"
  18. #include "BoardReceiver.h"
  19. #include "BoardReceiverSwitcher.h"
  20. //#include "..\testlgs\siteprocessor.h"
  21. #include "..\lglib\net\lgnetsocketmd.h"
  22. #include "..\lglib\net\lgnetdevicelgs.h"
  23. CBoardReceiverSwitcher::CBoardReceiverSwitcher()
  24. {
  25. }
  26. CBoardReceiverSwitcher::~CBoardReceiverSwitcher()
  27. {
  28. }
  29. BOOL CBoardReceiverSwitcher::Switch( INT nDevice, LPCTSTR pPort, INT nCount, DWORD dwTimeout )
  30. {
  31. BOOL bResult = FALSE;
  32. // __try
  33. {
  34. bResult = Switch_( nDevice, pPort, nCount, dwTimeout );
  35. }
  36. // __except( EXCEPTION_CONTINUE_EXECUTION )
  37. {
  38. // LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CBoardReceiverSwitcher::Switch"), _T("Exception 0x%08X"), _exception_code() );
  39. }
  40. return bResult;
  41. }
  42. BOOL CBoardReceiverSwitcher::Switch_( INT nDevice, LPCTSTR pPort, INT nCount, DWORD dwTimeout )
  43. {
  44. CLgNetDeviceLGS *device = new CLgNetDeviceLGS;
  45. CLgNetSocketMD *socket = new CLgNetSocketMD;
  46. device->SetAddress( 0 );
  47. device->SetAutoBaudrate( FALSE );
  48. device->SetSpyMode( FALSE );
  49. if( !socket->CLgLinkP<CLgNetObject,CLgNetObject,CLgNetObjectChild>::Link( device ) )
  50. return FALSE;
  51. if( !socket->Create( pPort, LGS_COMM_BAUDRATE, FALSE, FALSE ) )
  52. return FALSE;
  53. if( !socket->CLgLinkP<CLgNetSocket,CLgNetSocketDevice>::Link( device ) )
  54. return FALSE;
  55. CLgNetMessageLGS msg;
  56. msg.BuildCmdSendBoardData( nDevice );
  57. msg.SetDistinationID( device->GetID() );
  58. msg.SetSenderID( socket->GetID() );
  59. DWORD dwStartTime = ::GetTickCount();
  60. for( INT i = 0; i < nCount; i++ )
  61. {
  62. socket->SendMessageToChild( msg );
  63. Sleep( dwTimeout );
  64. }
  65. socket->Destroy();
  66. return TRUE;
  67. }