MatTrans.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. // MatTrans.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "StoneU_HC_OCX.h"
  5. #include "MatTrans.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CMatTrans dialog
  13. CMatTrans::CMatTrans(CWnd* pParent /*=NULL*/)
  14. : CDialog(CMatTrans::IDD, pParent)
  15. {
  16. //{{AFX_DATA_INIT(CMatTrans)
  17. m_Ip = _T("");
  18. m_Port = 0;
  19. m_232FullDup = 0;
  20. m_485FullDup = 0;
  21. //}}AFX_DATA_INIT
  22. m_lSerialCount = 0;
  23. }
  24. void CMatTrans::DoDataExchange(CDataExchange* pDX)
  25. {
  26. CDialog::DoDataExchange(pDX);
  27. //{{AFX_DATA_MAP(CMatTrans)
  28. DDX_Control(pDX, IDC_BAUD485, m_BaudCtrl);
  29. DDX_Control(pDX, IDC_STOPBIT485, m_StopBitCtrl);
  30. DDX_Control(pDX, IDC_LIST1, m_List);
  31. DDX_Control(pDX, IDC_FLOW485, m_FlowCtrl);
  32. DDX_Control(pDX, IDC_DATABIT485, m_DataBitCtrl);
  33. DDX_Control(pDX, IDC_CHECKBIT485, m_CheckBitCtrl);
  34. DDX_Control(pDX, IDC_COMSER2, m_SerCtrl1);
  35. DDX_Control(pDX, IDC_COMSER, m_SerCtrl);
  36. DDX_Control(pDX, IDC_COMPRO, m_ProCtrl);
  37. DDX_Text(pDX, IDC_EDITIP, m_Ip);
  38. DDX_Text(pDX, IDC_EDITPORT, m_Port);
  39. DDX_Text(pDX, IDC_FULLDUPNUM232, m_232FullDup);
  40. DDX_Text(pDX, IDC_FULLDUPNUM485, m_485FullDup);
  41. //}}AFX_DATA_MAP
  42. }
  43. BEGIN_MESSAGE_MAP(CMatTrans, CDialog)
  44. //{{AFX_MSG_MAP(CMatTrans)
  45. ON_BN_CLICKED(IDC_BUTSET, OnButset)
  46. ON_BN_CLICKED(IDC_BUTEXIT, OnButexit)
  47. ON_BN_CLICKED(IDC_ADDTOLIST, OnAddtolist)
  48. ON_BN_CLICKED(IDC_DELFROMLIST, OnDelfromlist)
  49. ON_BN_CLICKED(IDC_SETFULLDUP, OnSetfulldup)
  50. ON_NOTIFY(HDN_ITEMCLICK, IDC_LIST1, OnItemclickList1)
  51. ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
  52. //}}AFX_MSG_MAP
  53. END_MESSAGE_MAP()
  54. /////////////////////////////////////////////////////////////////////////////
  55. // CMatTrans message handlers
  56. void CMatTrans::OnCancel()
  57. {
  58. // TODO: Add extra cleanup here
  59. //CDialog::OnCancel();
  60. }
  61. void CMatTrans::OnOK()
  62. {
  63. // TODO: Add extra validation here
  64. //CDialog::OnOK();
  65. }
  66. void CMatTrans::ConInfoToDisp(int index, int i)
  67. {
  68. // CString tmp;
  69. //
  70. // if (m_stru.struTranInfo[i].byTranChanEnable == 1)
  71. // {
  72. // tmp = "开";
  73. // }
  74. // else if (m_stru.struTranInfo[i].byTranChanEnable == 0)
  75. // {
  76. // tmp = "关";
  77. // }
  78. // m_List.SetItemText(index, 1, tmp);
  79. //
  80. // tmp.Empty();
  81. // if (m_stru.struTranInfo[i].byLocalSerialDevice == 0)
  82. // {
  83. // tmp = "RS485";
  84. // }
  85. // else if (m_stru.struTranInfo[i].byLocalSerialDevice == 1)
  86. // {
  87. // tmp = "RS232 console";
  88. // }
  89. // else
  90. // {
  91. // tmp = "RS232 panel control";
  92. // }
  93. // m_List.SetItemText(index, 2, tmp);
  94. //
  95. // tmp.Empty();
  96. // if (m_stru.struTranInfo[i].byRemoteSerialDevice == 1)
  97. // {
  98. // tmp = "232";
  99. // }
  100. // else if (m_stru.struTranInfo[i].byRemoteSerialDevice == 2)
  101. // {
  102. // tmp = "485";
  103. // }
  104. // m_List.SetItemText(index, 5, tmp);
  105. //
  106. // tmp.Format("%s", m_stru.struTranInfo[i].sRemoteDevIP);
  107. // m_List.SetItemText(index, 3, tmp);
  108. //
  109. // tmp.Format("%d", m_stru.struTranInfo[i].wRemoteDevPort);
  110. // m_List.SetItemText(index, 4, tmp);
  111. //
  112. // switch(m_stru.struTranInfo[i].RemoteSerialDevCfg.baudrate)
  113. // {
  114. // case 0:
  115. // tmp.Format("%d", 50);
  116. // break;
  117. // case 1:
  118. // tmp.Format("%d", 75);
  119. // break;
  120. // case 2:
  121. // tmp.Format("%d", 110);
  122. // break;
  123. // case 3:
  124. // tmp.Format("%d", 150);
  125. // break;
  126. // case 4:
  127. // tmp.Format("%d", 300);
  128. // break;
  129. // case 5:
  130. // tmp.Format("%d", 600);
  131. // break;
  132. // case 6:
  133. // tmp.Format("%d", 1200);
  134. // break;
  135. // case 7:
  136. // tmp.Format("%d", 2400);
  137. // break;
  138. // case 8:
  139. // tmp.Format("%d", 4800);
  140. // break;
  141. // case 9:
  142. // tmp.Format("%d", 9600);
  143. // break;
  144. // case 10:
  145. // tmp.Format("%d", 19200);
  146. // break;
  147. // case 11:
  148. // tmp.Format("%d", 38400);
  149. // break;
  150. // case 12:
  151. // tmp.Format("%d", 57600);
  152. // break;
  153. // case 13:
  154. // tmp.Format("%d", 76800);
  155. // break;
  156. // case 14:
  157. // tmp.Format("%d", 1152000);
  158. // break;
  159. // default:
  160. // tmp.Empty();
  161. // break;
  162. // }
  163. // m_List.SetItemText(index, 6, tmp);
  164. //
  165. // switch(m_stru.struTranInfo[i].RemoteSerialDevCfg.databits)
  166. // {
  167. // case 0:
  168. // tmp.Format("%d", 5);
  169. // break;
  170. // case 1:
  171. // tmp.Format("%d", 6);
  172. // break;
  173. // case 2:
  174. // tmp.Format("%d", 7);
  175. // break;
  176. // case 3:
  177. // tmp.Format("%d", 8);
  178. // break;
  179. // default:
  180. // tmp.Empty();
  181. // break;
  182. // }
  183. // m_List.SetItemText(index, 7, tmp);
  184. //
  185. // switch(m_stru.struTranInfo[i].RemoteSerialDevCfg.stopbits)
  186. // {
  187. // case 0:
  188. // tmp.Format("%d", 1);
  189. // break;
  190. // case 1:
  191. // tmp.Format("%d", 2);
  192. // break;
  193. // default:
  194. // tmp.Empty();
  195. // break;
  196. // }
  197. // m_List.SetItemText(index, 8, tmp);
  198. //
  199. // switch(m_stru.struTranInfo[i].RemoteSerialDevCfg.parity)
  200. // {
  201. // case 0:
  202. // tmp.Format("无");
  203. // break;
  204. // case 1:
  205. // tmp.Format("奇");
  206. // break;
  207. // case 2:
  208. // tmp.Format("偶");
  209. // break;
  210. // default:
  211. // tmp.Empty();
  212. // break;
  213. // }
  214. // m_List.SetItemText(index, 9, tmp);
  215. //
  216. // switch(m_stru.struTranInfo[i].RemoteSerialDevCfg.flowcontrol)
  217. // {
  218. // case 0:
  219. // tmp.Format("无");
  220. // break;
  221. // case 1:
  222. // tmp.Format("软");
  223. // break;
  224. // case 2:
  225. // tmp.Format("硬");
  226. // break;
  227. // default:
  228. // tmp.Empty();
  229. // break;
  230. // }
  231. // m_List.SetItemText(index, 10, tmp);
  232. }
  233. BOOL CMatTrans::OnInitDialog()
  234. {
  235. CDialog::OnInitDialog();
  236. // TODO: Add extra initialization here
  237. m_ProCtrl.SetCurSel(0);
  238. m_SerCtrl.SetCurSel(0);
  239. m_SerCtrl1.SetCurSel(0);
  240. m_DataBitCtrl.SetCurSel(0);
  241. m_BaudCtrl.SetCurSel(0);
  242. m_FlowCtrl.SetCurSel(0);
  243. m_StopBitCtrl.SetCurSel(0);
  244. m_CheckBitCtrl.SetCurSel(0);
  245. m_Port = 0;
  246. m_List.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
  247. m_List.InsertColumn(0, "序号", LVCFMT_LEFT, 60, -1);
  248. m_List.InsertColumn(1, "开关", LVCFMT_LEFT, 80, -1);
  249. m_List.InsertColumn(2, "本地串口号", LVCFMT_LEFT, 120, -1);
  250. m_List.InsertColumn(3, "IP地址", LVCFMT_LEFT, 150, -1);
  251. m_List.InsertColumn(4, "端口号", LVCFMT_LEFT, 60, -1);
  252. m_List.InsertColumn(5, "远程串口号", LVCFMT_LEFT, 120, -1);
  253. m_List.InsertColumn(6, "波特率", LVCFMT_LEFT, 50, -1);
  254. m_List.InsertColumn(7, "数据位", LVCFMT_LEFT, 50, -1);
  255. m_List.InsertColumn(8, "停止位", LVCFMT_LEFT, 50, -1);
  256. m_List.InsertColumn(9, "校验", LVCFMT_LEFT, 50, -1);
  257. m_List.InsertColumn(10, "流控", LVCFMT_LEFT, 50, -1);
  258. // CString tmp;
  259. // memset(&m_stru, 0, sizeof(m_stru));
  260. // if (!NET_DVR_MatrixGetTranInfo(m_lServerID, &m_stru))
  261. // {
  262. // tmp.Format("Error: NET_DVR_MatrixGetTranInfo = %d", NET_DVR_GetLastError());
  263. // AfxMessageBox(tmp);
  264. // }
  265. // else
  266. // {
  267. // int index = 0;
  268. // for (int i=0; i<MAX_SERIAL_NUM; i++)
  269. // {
  270. // tmp.Format("%d", i+1);
  271. // index = m_List.InsertItem(m_List.GetItemCount(), tmp);
  272. //
  273. // ConInfoToDisp(index, i);
  274. // }
  275. // }
  276. // m_232FullDup = (char)m_stru.by232IsDualChan;
  277. // m_485FullDup = (char)m_stru.by485IsDualChan;
  278. UpdateData(FALSE);
  279. return TRUE;
  280. }
  281. void CMatTrans::OnButset()
  282. {
  283. // TODO: Add your control notification handler code here
  284. // UpdateData(TRUE);
  285. //
  286. // m_stru.dwSize = sizeof(m_stru);
  287. // m_stru.by232IsDualChan = m_232FullDup;
  288. // m_stru.by485IsDualChan = m_485FullDup;
  289. //
  290. // if (!NET_DVR_MatrixSetTranInfo(m_lServerID, &m_stru))
  291. // {
  292. // CString tmp;
  293. // tmp.Format("Error: NET_DVR_MatrixSetTranInfo = %d", NET_DVR_GetLastError());
  294. // AfxMessageBox(tmp);
  295. // return;
  296. // }
  297. // MessageBox("设置成功");
  298. }
  299. void CMatTrans::OnButexit()
  300. {
  301. // TODO: Add your control notification handler code here
  302. CDialog::OnCancel();
  303. }
  304. void CMatTrans::OnAddtolist()
  305. {
  306. // TODO: Add your control notification handler code here
  307. // UpdateData(TRUE);
  308. //
  309. // POSITION pos = m_List.GetFirstSelectedItemPosition();
  310. // if (pos == NULL)
  311. // {
  312. // AfxMessageBox("貌似不能添加,建议先在列表里选一项再改!");
  313. // return;
  314. // }
  315. // int sel = m_List.GetNextSelectedItem(pos);
  316. //
  317. // memset(&(m_stru.struTranInfo[sel]), 0, sizeof(m_stru.struTranInfo[sel]));
  318. //
  319. // m_stru.struTranInfo[sel].byTranChanEnable = m_ProCtrl.GetCurSel();
  320. // m_stru.struTranInfo[sel].byLocalSerialDevice = m_SerCtrl.GetCurSel();
  321. // m_stru.struTranInfo[sel].byRemoteSerialDevice = m_SerCtrl1.GetCurSel()+1;
  322. // sprintf(m_stru.struTranInfo[sel].sRemoteDevIP, "%s", m_Ip);
  323. // m_stru.struTranInfo[sel].wRemoteDevPort = m_Port;
  324. // m_stru.struTranInfo[sel].RemoteSerialDevCfg.baudrate = m_BaudCtrl.GetCurSel();
  325. // m_stru.struTranInfo[sel].RemoteSerialDevCfg.databits = m_DataBitCtrl.GetCurSel();
  326. // m_stru.struTranInfo[sel].RemoteSerialDevCfg.stopbits = m_StopBitCtrl.GetCurSel();
  327. // m_stru.struTranInfo[sel].RemoteSerialDevCfg.parity = m_CheckBitCtrl.GetCurSel();
  328. // m_stru.struTranInfo[sel].RemoteSerialDevCfg.flowcontrol = m_FlowCtrl.GetCurSel();
  329. //
  330. // ConInfoToDisp(sel, sel);
  331. // UpdateData(FALSE);
  332. }
  333. void CMatTrans::OnDelfromlist()
  334. {
  335. // TODO: Add your control notification handler code here
  336. // UpdateData(TRUE);
  337. //
  338. // POSITION pos = m_List.GetFirstSelectedItemPosition();
  339. // if (pos == NULL)
  340. // {
  341. // return;
  342. // }
  343. // int sel = m_List.GetNextSelectedItem(pos);
  344. //
  345. // memset(&(m_stru.struTranInfo[sel]), 0, sizeof(m_stru.struTranInfo[sel]));
  346. //
  347. // ConInfoToDisp(sel, sel);
  348. // UpdateData(FALSE);
  349. }
  350. void CMatTrans::OnSetfulldup()
  351. {
  352. // TODO: Add your control notification handler code here
  353. // UpdateData(TRUE);
  354. //
  355. // POSITION pos = m_List.GetFirstSelectedItemPosition();
  356. // if (pos == NULL)
  357. // {
  358. // AfxMessageBox("先到列表里选一个再点!");
  359. // return;
  360. // }
  361. // int sel = m_List.GetNextSelectedItem(pos);
  362. //
  363. // if (m_stru.struTranInfo[sel].sRemoteDevIP != "" && m_stru.struTranInfo[sel].wRemoteDevPort != 0)
  364. // {
  365. // if (m_stru.struTranInfo[sel].byLocalSerialDevice == 0)
  366. // {
  367. // m_485FullDup = sel + 1;
  368. // }
  369. // else
  370. // {
  371. // m_232FullDup = sel + 1;
  372. // }
  373. // }
  374. //
  375. // UpdateData(FALSE);
  376. }
  377. void CMatTrans::OnItemclickList1(NMHDR* pNMHDR, LRESULT* pResult)
  378. {
  379. // UpdateData(TRUE);
  380. //
  381. // HD_NOTIFY *phdn = (HD_NOTIFY *) pNMHDR;
  382. // // TODO: Add your control notification handler code here
  383. // POSITION pos = m_List.GetFirstSelectedItemPosition();
  384. // if (pos == NULL)
  385. // {
  386. // return;
  387. // }
  388. // int sel = m_List.GetNextSelectedItem(pos);
  389. //
  390. // m_ProCtrl.SetCurSel(m_stru.struTranInfo[sel].byTranChanEnable);
  391. // m_SerCtrl.SetCurSel(m_stru.struTranInfo[sel].byLocalSerialDevice);
  392. // m_SerCtrl1.SetCurSel(m_stru.struTranInfo[sel].byRemoteSerialDevice);
  393. // m_Ip.Format("%s", m_stru.struTranInfo[sel].sRemoteDevIP);
  394. // m_Port = m_stru.struTranInfo[sel].wRemoteDevPort;
  395. // m_BaudCtrl.SetCurSel(m_stru.struTranInfo[sel].RemoteSerialDevCfg.baudrate);
  396. // m_DataBitCtrl.SetCurSel(m_stru.struTranInfo[sel].RemoteSerialDevCfg.databits);
  397. // m_StopBitCtrl.SetCurSel(m_stru.struTranInfo[sel].RemoteSerialDevCfg.stopbits);
  398. // m_FlowCtrl.SetCurSel(m_stru.struTranInfo[sel].RemoteSerialDevCfg.flowcontrol);
  399. // m_CheckBitCtrl.SetCurSel(m_stru.struTranInfo[sel].RemoteSerialDevCfg.parity);
  400. //
  401. // UpdateData(FALSE);
  402. *pResult = 0;
  403. }
  404. void CMatTrans::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
  405. {
  406. UpdateData(TRUE);
  407. /*
  408. // TODO: Add your control notification handler code here
  409. POSITION pos = m_List.GetFirstSelectedItemPosition();
  410. if (pos == NULL)
  411. {
  412. return;
  413. }
  414. int sel = m_List.GetNextSelectedItem(pos);
  415. m_ProCtrl.SetCurSel(m_stru.struTranInfo[sel].byTranChanEnable);
  416. m_SerCtrl.SetCurSel(m_stru.struTranInfo[sel].byLocalSerialDevice);
  417. m_SerCtrl1.SetCurSel(m_stru.struTranInfo[sel].byRemoteSerialDevice);
  418. m_Ip.Format("%s", m_stru.struTranInfo[sel].sRemoteDevIP);
  419. m_Port = m_stru.struTranInfo[sel].wRemoteDevPort;
  420. m_BaudCtrl.SetCurSel(m_stru.struTranInfo[sel].RemoteSerialDevCfg.baudrate);
  421. m_DataBitCtrl.SetCurSel(m_stru.struTranInfo[sel].RemoteSerialDevCfg.databits);
  422. m_StopBitCtrl.SetCurSel(m_stru.struTranInfo[sel].RemoteSerialDevCfg.stopbits);
  423. m_FlowCtrl.SetCurSel(m_stru.struTranInfo[sel].RemoteSerialDevCfg.flowcontrol);
  424. m_CheckBitCtrl.SetCurSel(m_stru.struTranInfo[sel].RemoteSerialDevCfg.parity);
  425. */
  426. UpdateData(FALSE);
  427. *pResult = 0;
  428. }