#include // definire constante, variabile, structuri, functii #define ID_QRG 0 #define ID_MODE 1 #define ID_TX 3 #define ID_COM1 10 #define ID_COM2 11 #define ID_COM3 12 #define IDM_SYS_ABOUT 6 int cxChar, cyChar; int i=0; int h; int iFrecventa; DWORD iBytesWritten; DWORD iBytesRead; TCHAR szAppName[]=TEXT("IC-736"); // secventa de comanda pentru aflarea frecventei TCHAR szPCToControler_QRG[7] = {0xFE, 0xFE, 0x04, 0xE0, 0x03, 0xFD}; // pentru modul de lucru TCHAR szPCToControler_Mode[7] = {0xFE, 0xFE, 0x04, 0xE0, 0x04, 0xFD}; // 14.0 Mhz -> TRCV TCHAR szQRGToControler[12] = {0xFE, 0xFE, 0x04, 0xE0, 0x05, 0x00, 0x00, 0x00, 0x14, 0x00, 0xFD}; TCHAR szBuff01[10]; // portul serial predefinit TCHAR szBuff02[5] = TEXT("COM1"); HWND hwnd; HWND hwndButton[6]; HINSTANCE hInstance; DCB dcb; HANDLE hCom; DWORD dwError; BOOL fSuccess; HDC hdc; HMENU hMenu; MSG msg; BYTE rx, rx1; void OpenCom(void); void RS232(void); int AskConfirmation (HWND hwnd) { return MessageBox (hwnd, "Close ?", szAppName, MB_YESNO | MB_ICONQUESTION); } LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM); // inceputul programului int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int iCmdShow) { // definirea clasei wndclass WNDCLASS wndclass; wndclass.style = CS_HREDRAW | CS_VREDRAW ; wndclass.lpfnWndProc = WndProc ; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance ; wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION); wndclass.hCursor = LoadCursor( NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); wndclass.lpszMenuName = szAppName; wndclass.lpszClassName = szAppName ; // inregistrarea clasei wndclass if (!RegisterClass (&wndclass)) { MessageBox ( NULL, TEXT ("Windows NT !"), szAppName, MB_ICONERROR); return 0; } // definirea ferestrei hwnd = CreateWindow (szAppName, TEXT ("CAT IC-736"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 500, 200, NULL, NULL, hInstance, NULL); // extindere meniu sistem hMenu = GetSystemMenu(hwnd, FALSE); AppendMenu(hMenu, MF_SEPARATOR, 0, NULL); AppendMenu(hMenu, MF_STRING, IDM_SYS_ABOUT, TEXT ("Mesaj")); // afisarea ferestrei ShowWindow (hwnd, iCmdShow); UpdateWindow (hwnd); // contextul dispozitiv port serial OpenCom(); // setare date RS232 pentru IC-736 RS232(); // bucla de mesaje while (msg.message != WM_QUIT) { if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage (&msg); DispatchMessage (&msg); } else { } } return 0 ; } // functia fereastra LRESULT CALLBACK WndProc ( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_CREATE: // afisare butoane cxChar = LOWORD (GetDialogBaseUnits ()); cyChar = HIWORD (GetDialogBaseUnits ()); hwndButton[0] = CreateWindow ( TEXT("button"), "Read QRG", WS_CHILD | WS_VISIBLE | BS_CENTER | BS_PUSHBUTTON, 11* cxChar, 2* cyChar, 11 * cxChar, 7 * cyChar / 4, hwnd, (HMENU) ID_QRG, hInstance, NULL); hwndButton[1] = CreateWindow ( TEXT("button"), "Read Mode", WS_CHILD | WS_VISIBLE | BS_CENTER | BS_PUSHBUTTON, 23* cxChar, 2* cyChar, 11 * cxChar, 7 * cyChar / 4, hwnd, (HMENU) ID_MODE, hInstance, NULL); hwndButton[2] = CreateWindow ( TEXT("button"), "14MHz to TRCV", WS_CHILD | WS_VISIBLE | BS_CENTER | BS_PUSHBUTTON, 35* cxChar, 2* cyChar, 14 * cxChar, 7 * cyChar / 4, hwnd, (HMENU) ID_TX, hInstance, NULL); hwndButton[3] = CreateWindow ( TEXT("button"), TEXT("COM1"), WS_CHILD | WS_VISIBLE | BS_CENTER | BS_AUTORADIOBUTTON | WS_GROUP, cxChar, 2 * cyChar, 8 * cxChar, 7 * cyChar / 4, hwnd, (HMENU) ID_COM1, hInstance, NULL); SendMessage(hwndButton[3], BM_SETCHECK, 1, 0L); // default COM1 activ hwndButton[4] = CreateWindow ( TEXT("button"), TEXT("COM2"), WS_CHILD | WS_VISIBLE | BS_CENTER | BS_AUTORADIOBUTTON, cxChar, 4*cyChar, 8 * cxChar, 7 * cyChar / 4, hwnd, (HMENU) ID_COM2, hInstance, NULL); hwndButton[5] = CreateWindow ( TEXT("button"), TEXT("COM3"), WS_CHILD | WS_VISIBLE | BS_CENTER | BS_AUTORADIOBUTTON, cxChar, 6*cyChar, 8 * cxChar, 7 * cyChar / 4, hwnd, (HMENU) ID_COM3, hInstance, NULL); return 0; // testare comenzi ( mesaje sistem ) case WM_COMMAND: // alegerea portului serial if(wParam == ID_COM1) { CloseHandle(hCom); hCom = NULL; strcpy(szBuff02, "COM1"); OpenCom(); RS232(); } if(wParam == ID_COM2) { CloseHandle(hCom); hCom = NULL; strcpy(szBuff02, "COM2"); OpenCom; RS232(); } if(wParam == ID_COM3) { CloseHandle(hCom); hCom = NULL; strcpy(szBuff02, "COM3"); OpenCom(); RS232(); } // citirea frecventei de la transceiver if(wParam == ID_QRG) { PurgeComm(hCom, PURGE_TXCLEAR); // scriere secventa de comanda in bufferul de iesire WriteFile(hCom, szPCToControler_QRG, 6, &iBytesWritten, NULL); if(iBytesWritten != 6) { MessageBox (hwnd, "Writing not ok", szAppName, MB_YESNO); } PurgeComm(hCom, PURGE_RXCLEAR); hdc= GetDC(hwnd); SelectObject ( hdc, GetStockObject ( SYSTEM_FIXED_FONT)); SetTextColor(hdc, RGB(255,0,0)); for (i=0;i<17;i++) { // citire octet dupa octet din bufferul de intrare ReadFile(hCom,&rx, 1, &iBytesRead, 0); if(i==11) { rx=rx>>4; iFrecventa=rx; } if(i==12) { rx1=rx; rx1=rx1>>4; iFrecventa=iFrecventa +rx1*100; rx=rx&0x0F; iFrecventa=iFrecventa + rx*10; } if(i==13) { rx1=rx; rx1=rx1>>4; iFrecventa=iFrecventa + rx1*10000; rx=rx&0x0F; iFrecventa=iFrecventa + rx*1000; } if(i==14) { rx1=rx; rx1=rx1>>4; iFrecventa=iFrecventa + rx1*1000000; rx=rx&0x0F; iFrecventa=iFrecventa + rx*100000; } if(i==15) { rx=rx&0x0F; iFrecventa=iFrecventa + rx*10000000; } TextOut ( hdc, 90, 80, szBuff01, wsprintf ( szBuff01, TEXT("%8d"), iFrecventa)); } ReleaseDC(hwnd, hdc); } // citire mod de lucru if(wParam == ID_MODE) { WriteFile(hCom, szPCToControler_Mode, 6, &iBytesWritten, NULL); if(iBytesWritten != 6) { MessageBox (hwnd, "Writing not ok", szAppName, MB_YESNO); } PurgeComm(hCom, PURGE_RXCLEAR); hdc= GetDC(hwnd); h=210; SelectObject ( hdc, GetStockObject ( SYSTEM_FIXED_FONT)); SetTextColor(hdc, RGB(20,200,0)); for (i=0;i<13;i++) { ReadFile(hCom,&rx, 1, &iBytesRead, 0); if(i==11 && rx==0) { TextOut ( hdc, h, 80,"LSB",3); } if(i==11 && rx==1) { TextOut ( hdc, h, 80,"USB",3); } if(i==11 && rx==3) { TextOut ( hdc, h, 80,"CW ",3); } } ReleaseDC(hwnd, hdc); } // scriere frecventa -> trcv if(wParam == ID_TX) { PurgeComm(hCom, PURGE_TXCLEAR); WriteFile(hCom, szQRGToControler, 11, &iBytesWritten, NULL); if(iBytesWritten != 11) { MessageBox (hwnd, "Writing not ok", szAppName, MB_YESNO); } } return 0; // meniu sistem case WM_SYSCOMMAND: switch(LOWORD(wParam)) { case IDM_SYS_ABOUT: MessageBox(hwnd, TEXT("Vy 73's de YO2CMI\nBerni"),szAppName, MB_OK); return 0; } break; case WM_CLOSE: if (IDYES == AskConfirmation(hwnd)) { DestroyWindow(hwnd); } return 0; // iesire program case WM_DESTROY: CloseHandle(hCom); hCom = NULL; PostQuitMessage (0); return 0; } return DefWindowProc ( hwnd, message, wParam,lParam); } void OpenCom(void) { hCom = CreateFile(szBuff02, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if(hCom == INVALID_HANDLE_VALUE) { MessageBox (hwnd, "Port not available !", szAppName, MB_YESNO); } fSuccess = GetCommState(hCom, &dcb); if(!fSuccess) { MessageBox (hwnd, "Port problem !", szAppName, MB_YESNO); } } void RS232(void) { SetupComm(hCom, 128, 128); // buffer sizes dcb.BaudRate = 1200; // viteza dcb.ByteSize = 8; dcb.Parity = NOPARITY; dcb.StopBits = TWOSTOPBITS; dcb.fAbortOnError = TRUE; dcb.fRtsControl = RTS_CONTROL_ENABLE; dcb.fDtrControl = DTR_CONTROL_ENABLE; SetCommState(hCom, &dcb); }