serial port
-
Hello, i like to read in a data string from my serial port. The string has the format like: [123.233, -4.344, 45.678]. I want to readout this string and transfer the three values into float x,y,z variables for further processing. The code below is a part of my old code which works with only a "1" character input. What i have to change? char cReceivedChar[1]; cReceivedChar[0] = '\0'; DWORD dwBytesRead; if (port.Read(cReceivedChar, 1 , overlapped, &dwBytesRead)) // 1 is number of bytes read from port, how to make this variable? { CString nx = cReceivedChar[1]; SetDlgItemText(IDC_SHIFT_X,("%c", nx)); } Thanks, Mark
-
Hello, i like to read in a data string from my serial port. The string has the format like: [123.233, -4.344, 45.678]. I want to readout this string and transfer the three values into float x,y,z variables for further processing. The code below is a part of my old code which works with only a "1" character input. What i have to change? char cReceivedChar[1]; cReceivedChar[0] = '\0'; DWORD dwBytesRead; if (port.Read(cReceivedChar, 1 , overlapped, &dwBytesRead)) // 1 is number of bytes read from port, how to make this variable? { CString nx = cReceivedChar[1]; SetDlgItemText(IDC_SHIFT_X,("%c", nx)); } Thanks, Mark
-
why not simply CString nx ; while (port.Read(cReceivedChar, 1 , overlapped, &dwBytesRead)) // 1 is number of bytes read from port, how to make this variable? { nx += cReceivedChar[1]; } AfxMessageBox(nx); Papa while (TRUE) Papa.WillLove ( Bebe ) ;
-
Hmm, the output now is like: ||||||||| and how can i extract the three values? Thanks, Mark
Check the string tokenizer classes on CP The main idea, let the comma be your separator and take the values between and convert them to float or double using atof Remeber to clean the string on each new triplet received, i mean each time you receive (x, y, z) clean your string, of course after doing the processing Papa while (TRUE) Papa.WillLove ( Bebe ) ;