#include #include #include #include "cbw.h" #include #include #include #include "serial.h" // Declaration of the main routine void homingRoutine( HANDLE m_hCom); HANDLE InitializeCOMPort(); // Implementation of the routine HANDLE InitializeCOMPort( void ) { HANDLE m_hCom; char* m_sComPort; DCB m_dcb; COMMTIMEOUTS m_CommTimeouts; BOOL bWriteRC; BOOL bReadRC; DWORD iBytesWritten; DWORD iBytesRead; BOOL m_bPortReady; //set the properties of the serial port //Values seen below assume factory default where: //BaudRate=9600 //DataBits=8 //Parity=None //StopBits=1 m_sComPort = "Com1"; m_hCom = CreateFile(m_sComPort, GENERIC_READ | GENERIC_WRITE, 0, // exclusive access NULL, // no security OPEN_EXISTING, 0, // no overlapped I/O NULL); // null template if(m_hCom == INVALID_HANDLE_VALUE) { printf("Error opening serial port.\n"); exit(1); } m_bPortReady = SetupComm(m_hCom, 128, 128); // set buffer sizes m_bPortReady = GetCommState(m_hCom, &m_dcb); m_dcb.BaudRate = 9600; m_dcb.ByteSize = 8; m_dcb.Parity = NOPARITY; m_dcb.StopBits = ONESTOPBIT; m_dcb.fAbortOnError = TRUE; m_bPortReady = SetCommState(m_hCom, &m_dcb); //set timeouts for communications m_bPortReady = GetCommTimeouts (m_hCom, &m_CommTimeouts); m_CommTimeouts.ReadIntervalTimeout = 50; m_CommTimeouts.ReadTotalTimeoutConstant = 50; m_CommTimeouts.ReadTotalTimeoutMultiplier = 10; m_CommTimeouts.WriteTotalTimeoutConstant = 50; m_CommTimeouts.WriteTotalTimeoutMultiplier = 10; m_bPortReady = SetCommTimeouts (m_hCom, &m_CommTimeouts); return m_hCom; } void homingRoutine(HANDLE m_hCom){ BOOL bWriteRC; BOOL bReadRC; DWORD iBytesWritten; DWORD iBytesRead; //Output Homing routine complete printf("Homing Routine Complete.\n"); } void main() { //declare constants char number[3]; // variables used with the com port char sBuffer[128]; __time64_t time1; int i; for(i = 0; i < 128; i++) { sBuffer[i] = '\0'; } m_sComPort = "Com1"; //for use with Comport1 ----- Peut-etre a ne pas utiliser ------ HANDLE m_hCom = InitializeCOMPort(); //Setup for penetrometer motor Serial motor(1); //uses com1 for the motor motor.Setup(); char buff[1024]; char* str = (char*)malloc( 1024*sizeof( char ) ); int bufsize = 1024; int strlen = 1024; for(int i=1; i<=10; i++) { bufsize = 1024; motor.WaitForChar(buff, bufsize); } motor.WriteBuffer("4", 1); bufsize = 1024; printf( "Motor ready\n" ); char* m_sComPort; DCB m_dcb; COMMTIMEOUTS m_CommTimeouts; BOOL bWriteRC; BOOL bReadRC; DWORD iBytesWritten; DWORD iBytesRead; BOOL m_bPortReady; motor.WaitForChar(buff, bufsize, '-'); //main for loop for(int j=1;j<=50;j++) { homingRoutine(m_hCom); //motor controller reads input one character at a time, hence the for loops below. str = "v=721:@2=1:home:w=20:init\r";//initialize motor strlen = 26; for(int i=0; i