Exemple #1
0
void CSerialPort::WriteSerial(const CString& strCmd)
{
	OVERLAPPED m_osWrite;
	memset(&m_osWrite, 0, sizeof(OVERLAPPED));
	m_osWrite.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);

	char lpOutBuffer[MAX_PATH] = { 0 };

	DWORD dwBytesWrite = CStringToChar(strCmd, lpOutBuffer, MAX_PATH);
	COMSTAT ComStat;
	DWORD dwErrorFlags;
	BOOL bWriteStat;
	ClearCommError(m_hComm, &dwErrorFlags, &ComStat);
	bWriteStat = WriteFile(m_hComm, lpOutBuffer, dwBytesWrite, &dwBytesWrite, &m_osWrite);

	if (!bWriteStat)
	{
		if (GetLastError() == ERROR_IO_PENDING)
		{
			WaitForSingleObject(m_osWrite.hEvent, 1000);
		}
	}
	CloseHandle(m_osWrite.hEvent);

	return;
}
Exemple #2
0
//-----------------------------------------------------------------------------
void CIfcbDlg::OnTimer(UINT_PTR nIDEvent) {

	static UINT32 prevCount = 0;
	CString fpsText;
	unsigned int fps;
	CString str;
	//int stepCount;
	char cval[20];
	CString valstr;
	CStringToChar(cval, &valstr);
	CString args;		
	CString args2;	

	switch (nIDEvent) {
		case SYRINGE_TIMER_ID:
			DEBUG_MESSAGE(_T("Syringe timeout fired\r\n"));
			AcqComplete(END_AUTO);						// finish this run
			if (++syringesDone < nSyringes) {			// start a new run if required
				if (!AcqInit())
					Stop();
			} else {									// release the start button
				RunButton.SetCheck(BST_UNCHECKED);
				grabbing = false;						// this stops the data files being written twice
				OnBnClickedRun();
				if (autoShutdown)
					ShutdownWindows();
			}
			break;

		case TRIGGER_TIMER_ID:
			GenerateTrigger();
			break;

		case AUTOSTART_TIMER_ID:
			KillTimer(AUTOSTART_TIMER_ID);
			if (nSyringes) {							// start a run if required
				RunButton.SetCheck(BST_CHECKED);
				OnBnClickedRun();
			}
			break;

		case ACQ_START_TIMEOUT_ID:
			DEBUG_MESSAGE(_T("Trigger timeout fired\r\n"));
			AcqComplete(END_RETRY);						// finish this run
			if (!AcqInit())								// start a new run
				Stop();
			break;

		case FRAMERATE_TIMER_ID:
			if (!grabbing)
				break;
			UINT32_TYPE thisCount;
			thisCount = TabContainer.tabPages[cameraTab]->GetFrameCount();
//			TabContainer.tabPages[cameraTab]->SetDlgItemInt(IDC_FRAMEDROPPEDCOUNT, (thisCount - prevCount) * 2, FALSE);
			fps = (thisCount - prevCount) * 2;
			prevCount = thisCount;
			fpsText.Format(_T("%d.%d"), fps / 10, fps % 10);
			TabContainer.tabPages[cameraTab]->SetDlgItemText(IDC_FRAMEDROPPEDCOUNT, fpsText);
			break;

		case FRAMECOUNT_TIMER_ID:
			if (!grabbing)
				break;
			TabContainer.tabPages[cameraTab]->SetDlgItemInt(IDC_FRAMECOUNT, TabContainer.tabPages[cameraTab]->GetFrameCount(), FALSE);
			break;

		case TCP_TIMER_ID:
			HandleTcp();
			break;

		case PZT_TIMER_ID:							// synchronise the PZT command to only happen directly after a capture
			rqPZT = true;
			//PZTcommand(PZTmode RUN);
			break;

		case PZT_SCAN_TIMER_ID:
			rqPZT = true; // at 492, add this here to see if it fixes eventual-crashing problem with scanning
			str.Format(_T("in scan timer; stepCount = %d\r\n"), stepCount);
				DEBUG_MESSAGE_EXT(str); 
				//To DoFreqScan,
				//we want a loop using a counter for FreqStep (e.g.,StepCounter), 
				//so that at each StepCounter, FreqStep is added to NewFreq. 
				//This loop needs to extend over multiple syringes (i.e., using 
				//freqstepsPerSyr = minPerSyr / minPerStep (from Fileio.cpp) 
				//to keep track of when to go back to StartFreq.
				//We want the loop to continue indefinitely so that multiple scans
				//can be made as instrument temperature is varied (for calibration).

				if (stepCount == 1) {
					PZTfrequency = (int)(StartFreq + FreqStep);
				}
				else if(stepCount % freqstepsPerCycle == 0) {
					PZTfrequency = (int)StartFreq;
				}
				else {
					PZTfrequency = PZTfrequency + (int)FreqStep;
				}
				WriteFreqFile();
					/*args.Format(_T(" --nogui --on --noinit --hz %d --volts %d"), PZTfrequency, PZTvolts);
					DEBUG_MESSAGE_EXT(args); 
					DEBUG_MESSAGE_EXT(_T("\r\n"));
					str = sigGenPath; // note -- this includes the file name as well as path (e.g., "C:\AcousticFocusingWHOI\sig_gen\sig-gen-v1.0.4_64bit\sig-gen-v1.0.4\sig-gen")
					//DEBUG_MESSAGE_EXT(str); 
					DEBUG_MESSAGE_EXT(_T("\r\n"));
					//args2.Format(_T("floor(freqstepsPerSyr) = %f"), floor(freqstepsPerSyr)); 
					args2.Format(_T("freqstepsPerCycle = %d"), int(floor(freqstepsPerCycle))); 
					DEBUG_MESSAGE_EXT(args2); 
					DEBUG_MESSAGE_EXT(_T("\r\n"));
					//args.Format(_T(""));
					//str = "%windir\\system32\\notepad.exe";
					//str += (args);
					//DEBUG_MESSAGE_EXT(str);
					//DEBUG_MESSAGE_EXT(_T("\r\n")); 
					ShellExecute(NULL, _T("open"), str, args, NULL, SW_HIDE);	
					//ShellExecute(NULL, _T("open"), str, args, NULL, SW_NORMAL);	
					*/
					stepCount = stepCount + 1;
					//return;
			rqPZT =  true;
			//}
			break;
			

		case CAPTURE_TIMER_ID:						// used when hasCamera == false
			if (rqStop) {
				Stop();
				break;
			}

			if (!grabbing)
				break;
			
			if (!CheckForCapture()) {
				if (rqStop)
					Stop();
				break;
			}

			KillTimer(ACQ_START_TIMEOUT_ID);
			triggerTickCount = GetTickCount();
			ProcessTrigger(0);
			SetHWParams();							// change any parameters that need it

			// alignment graph plot - takes about 0.5 ms
			if (GraphData.GraphType != GraphData.GRAPH_NONE) {
				TabContainer.tabPages[graphTab]->UpdateGraph();
				TabContainer.tabPages[graphTab]->PostMessage(WM_PAINT, 0, 0);
			}

			DaqArmTrigger();
			if (rqStop)
				Stop();
			break;

		default:
			break;
	}
}
void CCommonConvert::CStringToint(int& i,CString str)
{
	char c_str[255]={0};
	CStringToChar(str,c_str);
	i=atoi(c_str);
}