-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathComService.cpp
More file actions
93 lines (86 loc) · 1.69 KB
/
ComService.cpp
File metadata and controls
93 lines (86 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// ComService.cpp: implementation of the CComService class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "SID_2FY.h"
#include "ComService.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CComService::CComService()
{
m_nPort = -1;
m_frameCount=1;
m_pComSock = NULL;
}
CComService::~CComService()
{
if(m_pComSock != NULL)
{
delete m_pComSock;
m_pComSock = NULL;
}
}
bool CComService::OpenService(ComType comType,int nPort)
{
bool bRe=false;
switch(comType)
{
case EN_USBMW:
if(m_pComSock != NULL)
{
delete m_pComSock;
m_pComSock = NULL;
}
m_pComSock = new CUSBSocket;
if(m_pComSock->CreateSocket(nPort))
{
m_comType = EN_USBMW;
m_nPort = nPort;
bRe=true;
}
else
{
delete m_pComSock;
m_pComSock = NULL;
}
break;
case EN_NETUDP:
if(m_pComSock != NULL)
{
delete m_pComSock;
}
m_pComSock = new CNetSocket;
if(m_pComSock->CreateSocket(nPort))
{
m_comType = EN_NETUDP;
m_nPort = nPort;
bRe=true;
}
else
{
delete m_pComSock;
m_pComSock = NULL;
}
break;
default:
ASSERT(FALSE);
}
return bRe;
}
bool CComService::RecvData(UINT nTimeOut)
{
ASSERT(m_pComSock && m_pComSock->IsOpen());
m_nRecvFrameSize = m_pComSock->RecvData(m_recvFrame,sizeof(m_recvFrame),nTimeOut);
return (m_nRecvFrameSize > 0) ? true:false;
}
bool CComService::SendData()
{
ASSERT(m_pComSock && m_pComSock->IsOpen());
return m_pComSock->SendData(m_sendFrame,m_nSendFrameSize);
}