123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463 |
- // MatTrans.cpp : implementation file
- //
- #include "stdafx.h"
- #include "StoneU_HC_OCX.h"
- #include "MatTrans.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CMatTrans dialog
- CMatTrans::CMatTrans(CWnd* pParent /*=NULL*/)
- : CDialog(CMatTrans::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CMatTrans)
- m_Ip = _T("");
- m_Port = 0;
- m_232FullDup = 0;
- m_485FullDup = 0;
- //}}AFX_DATA_INIT
- m_lSerialCount = 0;
- }
- void CMatTrans::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CMatTrans)
- DDX_Control(pDX, IDC_BAUD485, m_BaudCtrl);
- DDX_Control(pDX, IDC_STOPBIT485, m_StopBitCtrl);
- DDX_Control(pDX, IDC_LIST1, m_List);
- DDX_Control(pDX, IDC_FLOW485, m_FlowCtrl);
- DDX_Control(pDX, IDC_DATABIT485, m_DataBitCtrl);
- DDX_Control(pDX, IDC_CHECKBIT485, m_CheckBitCtrl);
- DDX_Control(pDX, IDC_COMSER2, m_SerCtrl1);
- DDX_Control(pDX, IDC_COMSER, m_SerCtrl);
- DDX_Control(pDX, IDC_COMPRO, m_ProCtrl);
- DDX_Text(pDX, IDC_EDITIP, m_Ip);
- DDX_Text(pDX, IDC_EDITPORT, m_Port);
- DDX_Text(pDX, IDC_FULLDUPNUM232, m_232FullDup);
- DDX_Text(pDX, IDC_FULLDUPNUM485, m_485FullDup);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CMatTrans, CDialog)
- //{{AFX_MSG_MAP(CMatTrans)
- ON_BN_CLICKED(IDC_BUTSET, OnButset)
- ON_BN_CLICKED(IDC_BUTEXIT, OnButexit)
- ON_BN_CLICKED(IDC_ADDTOLIST, OnAddtolist)
- ON_BN_CLICKED(IDC_DELFROMLIST, OnDelfromlist)
- ON_BN_CLICKED(IDC_SETFULLDUP, OnSetfulldup)
- ON_NOTIFY(HDN_ITEMCLICK, IDC_LIST1, OnItemclickList1)
- ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMatTrans message handlers
- void CMatTrans::OnCancel()
- {
- // TODO: Add extra cleanup here
-
- //CDialog::OnCancel();
- }
- void CMatTrans::OnOK()
- {
- // TODO: Add extra validation here
-
- //CDialog::OnOK();
- }
- void CMatTrans::ConInfoToDisp(int index, int i)
- {
- // CString tmp;
- //
- // if (m_stru.struTranInfo[i].byTranChanEnable == 1)
- // {
- // tmp = "开";
- // }
- // else if (m_stru.struTranInfo[i].byTranChanEnable == 0)
- // {
- // tmp = "关";
- // }
- // m_List.SetItemText(index, 1, tmp);
- //
- // tmp.Empty();
- // if (m_stru.struTranInfo[i].byLocalSerialDevice == 0)
- // {
- // tmp = "RS485";
- // }
- // else if (m_stru.struTranInfo[i].byLocalSerialDevice == 1)
- // {
- // tmp = "RS232 console";
- // }
- // else
- // {
- // tmp = "RS232 panel control";
- // }
- // m_List.SetItemText(index, 2, tmp);
- //
- // tmp.Empty();
- // if (m_stru.struTranInfo[i].byRemoteSerialDevice == 1)
- // {
- // tmp = "232";
- // }
- // else if (m_stru.struTranInfo[i].byRemoteSerialDevice == 2)
- // {
- // tmp = "485";
- // }
- // m_List.SetItemText(index, 5, tmp);
- //
- // tmp.Format("%s", m_stru.struTranInfo[i].sRemoteDevIP);
- // m_List.SetItemText(index, 3, tmp);
- //
- // tmp.Format("%d", m_stru.struTranInfo[i].wRemoteDevPort);
- // m_List.SetItemText(index, 4, tmp);
- //
- // switch(m_stru.struTranInfo[i].RemoteSerialDevCfg.baudrate)
- // {
- // case 0:
- // tmp.Format("%d", 50);
- // break;
- // case 1:
- // tmp.Format("%d", 75);
- // break;
- // case 2:
- // tmp.Format("%d", 110);
- // break;
- // case 3:
- // tmp.Format("%d", 150);
- // break;
- // case 4:
- // tmp.Format("%d", 300);
- // break;
- // case 5:
- // tmp.Format("%d", 600);
- // break;
- // case 6:
- // tmp.Format("%d", 1200);
- // break;
- // case 7:
- // tmp.Format("%d", 2400);
- // break;
- // case 8:
- // tmp.Format("%d", 4800);
- // break;
- // case 9:
- // tmp.Format("%d", 9600);
- // break;
- // case 10:
- // tmp.Format("%d", 19200);
- // break;
- // case 11:
- // tmp.Format("%d", 38400);
- // break;
- // case 12:
- // tmp.Format("%d", 57600);
- // break;
- // case 13:
- // tmp.Format("%d", 76800);
- // break;
- // case 14:
- // tmp.Format("%d", 1152000);
- // break;
- // default:
- // tmp.Empty();
- // break;
- // }
- // m_List.SetItemText(index, 6, tmp);
- //
- // switch(m_stru.struTranInfo[i].RemoteSerialDevCfg.databits)
- // {
- // case 0:
- // tmp.Format("%d", 5);
- // break;
- // case 1:
- // tmp.Format("%d", 6);
- // break;
- // case 2:
- // tmp.Format("%d", 7);
- // break;
- // case 3:
- // tmp.Format("%d", 8);
- // break;
- // default:
- // tmp.Empty();
- // break;
- // }
- // m_List.SetItemText(index, 7, tmp);
- //
- // switch(m_stru.struTranInfo[i].RemoteSerialDevCfg.stopbits)
- // {
- // case 0:
- // tmp.Format("%d", 1);
- // break;
- // case 1:
- // tmp.Format("%d", 2);
- // break;
- // default:
- // tmp.Empty();
- // break;
- // }
- // m_List.SetItemText(index, 8, tmp);
- //
- // switch(m_stru.struTranInfo[i].RemoteSerialDevCfg.parity)
- // {
- // case 0:
- // tmp.Format("无");
- // break;
- // case 1:
- // tmp.Format("奇");
- // break;
- // case 2:
- // tmp.Format("偶");
- // break;
- // default:
- // tmp.Empty();
- // break;
- // }
- // m_List.SetItemText(index, 9, tmp);
- //
- // switch(m_stru.struTranInfo[i].RemoteSerialDevCfg.flowcontrol)
- // {
- // case 0:
- // tmp.Format("无");
- // break;
- // case 1:
- // tmp.Format("软");
- // break;
- // case 2:
- // tmp.Format("硬");
- // break;
- // default:
- // tmp.Empty();
- // break;
- // }
- // m_List.SetItemText(index, 10, tmp);
- }
- BOOL CMatTrans::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- // TODO: Add extra initialization here
- m_ProCtrl.SetCurSel(0);
- m_SerCtrl.SetCurSel(0);
- m_SerCtrl1.SetCurSel(0);
-
- m_DataBitCtrl.SetCurSel(0);
- m_BaudCtrl.SetCurSel(0);
- m_FlowCtrl.SetCurSel(0);
- m_StopBitCtrl.SetCurSel(0);
- m_CheckBitCtrl.SetCurSel(0);
- m_Port = 0;
- m_List.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
-
- m_List.InsertColumn(0, "序号", LVCFMT_LEFT, 60, -1);
- m_List.InsertColumn(1, "开关", LVCFMT_LEFT, 80, -1);
- m_List.InsertColumn(2, "本地串口号", LVCFMT_LEFT, 120, -1);
- m_List.InsertColumn(3, "IP地址", LVCFMT_LEFT, 150, -1);
- m_List.InsertColumn(4, "端口号", LVCFMT_LEFT, 60, -1);
- m_List.InsertColumn(5, "远程串口号", LVCFMT_LEFT, 120, -1);
- m_List.InsertColumn(6, "波特率", LVCFMT_LEFT, 50, -1);
- m_List.InsertColumn(7, "数据位", LVCFMT_LEFT, 50, -1);
- m_List.InsertColumn(8, "停止位", LVCFMT_LEFT, 50, -1);
- m_List.InsertColumn(9, "校验", LVCFMT_LEFT, 50, -1);
- m_List.InsertColumn(10, "流控", LVCFMT_LEFT, 50, -1);
-
- // CString tmp;
- // memset(&m_stru, 0, sizeof(m_stru));
- // if (!NET_DVR_MatrixGetTranInfo(m_lServerID, &m_stru))
- // {
- // tmp.Format("Error: NET_DVR_MatrixGetTranInfo = %d", NET_DVR_GetLastError());
- // AfxMessageBox(tmp);
- // }
- // else
- // {
- // int index = 0;
- // for (int i=0; i<MAX_SERIAL_NUM; i++)
- // {
- // tmp.Format("%d", i+1);
- // index = m_List.InsertItem(m_List.GetItemCount(), tmp);
- //
- // ConInfoToDisp(index, i);
- // }
- // }
- // m_232FullDup = (char)m_stru.by232IsDualChan;
- // m_485FullDup = (char)m_stru.by485IsDualChan;
- UpdateData(FALSE);
- return TRUE;
- }
- void CMatTrans::OnButset()
- {
- // TODO: Add your control notification handler code here
- // UpdateData(TRUE);
- //
- // m_stru.dwSize = sizeof(m_stru);
- // m_stru.by232IsDualChan = m_232FullDup;
- // m_stru.by485IsDualChan = m_485FullDup;
- //
- // if (!NET_DVR_MatrixSetTranInfo(m_lServerID, &m_stru))
- // {
- // CString tmp;
- // tmp.Format("Error: NET_DVR_MatrixSetTranInfo = %d", NET_DVR_GetLastError());
- // AfxMessageBox(tmp);
- // return;
- // }
- // MessageBox("设置成功");
- }
- void CMatTrans::OnButexit()
- {
- // TODO: Add your control notification handler code here
- CDialog::OnCancel();
- }
- void CMatTrans::OnAddtolist()
- {
- // TODO: Add your control notification handler code here
- // UpdateData(TRUE);
- //
- // POSITION pos = m_List.GetFirstSelectedItemPosition();
- // if (pos == NULL)
- // {
- // AfxMessageBox("貌似不能添加,建议先在列表里选一项再改!");
- // return;
- // }
- // int sel = m_List.GetNextSelectedItem(pos);
- //
- // memset(&(m_stru.struTranInfo[sel]), 0, sizeof(m_stru.struTranInfo[sel]));
- //
- // m_stru.struTranInfo[sel].byTranChanEnable = m_ProCtrl.GetCurSel();
- // m_stru.struTranInfo[sel].byLocalSerialDevice = m_SerCtrl.GetCurSel();
- // m_stru.struTranInfo[sel].byRemoteSerialDevice = m_SerCtrl1.GetCurSel()+1;
- // sprintf(m_stru.struTranInfo[sel].sRemoteDevIP, "%s", m_Ip);
- // m_stru.struTranInfo[sel].wRemoteDevPort = m_Port;
- // m_stru.struTranInfo[sel].RemoteSerialDevCfg.baudrate = m_BaudCtrl.GetCurSel();
- // m_stru.struTranInfo[sel].RemoteSerialDevCfg.databits = m_DataBitCtrl.GetCurSel();
- // m_stru.struTranInfo[sel].RemoteSerialDevCfg.stopbits = m_StopBitCtrl.GetCurSel();
- // m_stru.struTranInfo[sel].RemoteSerialDevCfg.parity = m_CheckBitCtrl.GetCurSel();
- // m_stru.struTranInfo[sel].RemoteSerialDevCfg.flowcontrol = m_FlowCtrl.GetCurSel();
- //
- // ConInfoToDisp(sel, sel);
- // UpdateData(FALSE);
- }
- void CMatTrans::OnDelfromlist()
- {
- // TODO: Add your control notification handler code here
- // UpdateData(TRUE);
- //
- // POSITION pos = m_List.GetFirstSelectedItemPosition();
- // if (pos == NULL)
- // {
- // return;
- // }
- // int sel = m_List.GetNextSelectedItem(pos);
- //
- // memset(&(m_stru.struTranInfo[sel]), 0, sizeof(m_stru.struTranInfo[sel]));
- //
- // ConInfoToDisp(sel, sel);
- // UpdateData(FALSE);
- }
- void CMatTrans::OnSetfulldup()
- {
- // TODO: Add your control notification handler code here
- // UpdateData(TRUE);
- //
- // POSITION pos = m_List.GetFirstSelectedItemPosition();
- // if (pos == NULL)
- // {
- // AfxMessageBox("先到列表里选一个再点!");
- // return;
- // }
- // int sel = m_List.GetNextSelectedItem(pos);
- //
- // if (m_stru.struTranInfo[sel].sRemoteDevIP != "" && m_stru.struTranInfo[sel].wRemoteDevPort != 0)
- // {
- // if (m_stru.struTranInfo[sel].byLocalSerialDevice == 0)
- // {
- // m_485FullDup = sel + 1;
- // }
- // else
- // {
- // m_232FullDup = sel + 1;
- // }
- // }
- //
- // UpdateData(FALSE);
- }
- void CMatTrans::OnItemclickList1(NMHDR* pNMHDR, LRESULT* pResult)
- {
- // UpdateData(TRUE);
- //
- // HD_NOTIFY *phdn = (HD_NOTIFY *) pNMHDR;
- // // TODO: Add your control notification handler code here
- // POSITION pos = m_List.GetFirstSelectedItemPosition();
- // if (pos == NULL)
- // {
- // return;
- // }
- // int sel = m_List.GetNextSelectedItem(pos);
- //
- // m_ProCtrl.SetCurSel(m_stru.struTranInfo[sel].byTranChanEnable);
- // m_SerCtrl.SetCurSel(m_stru.struTranInfo[sel].byLocalSerialDevice);
- // m_SerCtrl1.SetCurSel(m_stru.struTranInfo[sel].byRemoteSerialDevice);
- // m_Ip.Format("%s", m_stru.struTranInfo[sel].sRemoteDevIP);
- // m_Port = m_stru.struTranInfo[sel].wRemoteDevPort;
- // m_BaudCtrl.SetCurSel(m_stru.struTranInfo[sel].RemoteSerialDevCfg.baudrate);
- // m_DataBitCtrl.SetCurSel(m_stru.struTranInfo[sel].RemoteSerialDevCfg.databits);
- // m_StopBitCtrl.SetCurSel(m_stru.struTranInfo[sel].RemoteSerialDevCfg.stopbits);
- // m_FlowCtrl.SetCurSel(m_stru.struTranInfo[sel].RemoteSerialDevCfg.flowcontrol);
- // m_CheckBitCtrl.SetCurSel(m_stru.struTranInfo[sel].RemoteSerialDevCfg.parity);
- //
- // UpdateData(FALSE);
- *pResult = 0;
- }
- void CMatTrans::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
- {
- UpdateData(TRUE);
- /*
- // TODO: Add your control notification handler code here
- POSITION pos = m_List.GetFirstSelectedItemPosition();
- if (pos == NULL)
- {
- return;
- }
- int sel = m_List.GetNextSelectedItem(pos);
-
- m_ProCtrl.SetCurSel(m_stru.struTranInfo[sel].byTranChanEnable);
- m_SerCtrl.SetCurSel(m_stru.struTranInfo[sel].byLocalSerialDevice);
- m_SerCtrl1.SetCurSel(m_stru.struTranInfo[sel].byRemoteSerialDevice);
- m_Ip.Format("%s", m_stru.struTranInfo[sel].sRemoteDevIP);
- m_Port = m_stru.struTranInfo[sel].wRemoteDevPort;
- m_BaudCtrl.SetCurSel(m_stru.struTranInfo[sel].RemoteSerialDevCfg.baudrate);
- m_DataBitCtrl.SetCurSel(m_stru.struTranInfo[sel].RemoteSerialDevCfg.databits);
- m_StopBitCtrl.SetCurSel(m_stru.struTranInfo[sel].RemoteSerialDevCfg.stopbits);
- m_FlowCtrl.SetCurSel(m_stru.struTranInfo[sel].RemoteSerialDevCfg.flowcontrol);
- m_CheckBitCtrl.SetCurSel(m_stru.struTranInfo[sel].RemoteSerialDevCfg.parity);
- */
- UpdateData(FALSE);
- *pResult = 0;
- }
|