Click here to Skip to main content
14,741,142 members
Home » Discussions » C#
   

C#

 
Questionhow to insert unknown amount of data into a database Pin
steven_noppe11-Oct-20 8:41
Membersteven_noppe11-Oct-20 8:41 
AnswerRe: how to insert unknown amount of data into a database Pin
Luc Pattyn11-Oct-20 9:32
sitebuilderLuc Pattyn11-Oct-20 9:32 
AnswerRe: how to insert unknown amount of data into a database Pin
OriginalGriff11-Oct-20 9:33
mveOriginalGriff11-Oct-20 9:33 
AnswerRe: how to insert unknown amount of data into a database Pin
jsc4213-Oct-20 4:50
professionaljsc4213-Oct-20 4:50 
QuestionWhy am I not allowed to do this with events Pin
Keith Barrow9-Oct-20 2:20
professionalKeith Barrow9-Oct-20 2:20 
AnswerRe: Why am I not allowed to do this with events Pin
Richard Deeming9-Oct-20 3:12
mveRichard Deeming9-Oct-20 3:12 
GeneralRe: Why am I not allowed to do this with events Pin
Keith Barrow9-Oct-20 4:19
professionalKeith Barrow9-Oct-20 4:19 
QuestionHow to read from serial port until timeout of no more data received? Pin
td17768-Oct-20 14:27
Membertd17768-Oct-20 14:27 
I am trying to data from a serial port to store in a text file. I want to save each data burst (which are infrequent and relatively short) in discrete text files, but some data bursts may include a pause of a minute or so.

Even for short bursts without the pause, .ReadExisting does not capture everything, breaking it up into several pieces when displaying it on screen and creating several text files. I came up with an unsatisfactory hack-y solution for that, but I need advice/help with how to continue capturing until I reach a timeout duration of some number of milliseconds with no further data received and store all data received from the DataReceived event firing until the timeout is reached.

My original whack at it, would always break the data up into chunks and create multiple files:
try
{
	String tempReadData = myPort.ReadExisting();   // read data from the line
	showLoggedData(tempReadData);                  // display data      

	//create filename
	storeLog(tempReadData, fileName);
}
catch (Exception ex)
	// handle exception


Throwing some sleep cycles into a while(myPort.BytesToRead > 0) loop gives it time to wait for more to arrive and keeps it all together in one file and displays it in a text box without having to stitch it all together.

try
{
	while(myPort.BytesToRead > 0)
	{
		logText += myPort.ReadExisting();         // read data from the line
		System.Threading.Thread.Sleep(500);
	}
	showLoggedData(logText);                      // display data      

	// create filename
	writeLogFile(logText, fileName);
}
catch (Exception ex)

	//handle exception


But I can't figure out how to get it to to read all data from the time that myPort_DataReceived(object sender, SerialDataReceivedEventArgs e) fires until some specified amount of time has passed, and store it all in one text file.
AnswerRe: How to read from serial port until timeout of no more data received? Pin
Luc Pattyn8-Oct-20 15:27
sitebuilderLuc Pattyn8-Oct-20 15:27 
GeneralRe: How to read from serial port until timeout of no more data received? Pin
td17768-Oct-20 16:36
Membertd17768-Oct-20 16:36 
GeneralRe: How to read from serial port until timeout of no more data received? Pin
Luc Pattyn9-Oct-20 2:25
sitebuilderLuc Pattyn9-Oct-20 2:25 
AnswerRe: How to read from serial port until timeout of no more data received? Pin
Gerry Schmitz8-Oct-20 19:27
mveGerry Schmitz8-Oct-20 19:27 
GeneralRe: How to read from serial port until timeout of no more data received? Pin
td17769-Oct-20 12:16
Membertd17769-Oct-20 12:16 
GeneralRe: How to read from serial port until timeout of no more data received? Pin
Gerry Schmitz9-Oct-20 15:10
mveGerry Schmitz9-Oct-20 15:10 
AnswerRe: How to read from serial port until timeout of no more data received? Pin
Richard MacCutchan8-Oct-20 23:55
mveRichard MacCutchan8-Oct-20 23:55 
AnswerMy (temporary?) solution Pin
td17769-Oct-20 12:25
Membertd17769-Oct-20 12:25 
QuestionCOM exception loss Pin
Member 126326017-Oct-20 21:57
MemberMember 126326017-Oct-20 21:57 
AnswerRe: COM exception loss Pin
Richard MacCutchan7-Oct-20 22:35
mveRichard MacCutchan7-Oct-20 22:35 
GeneralRe: COM exception loss Pin
Member 126326017-Oct-20 23:03
MemberMember 126326017-Oct-20 23:03 
GeneralRe: COM exception loss Pin
Richard MacCutchan7-Oct-20 23:25
mveRichard MacCutchan7-Oct-20 23:25 
GeneralRe: COM exception loss Pin
Member 126326017-Oct-20 23:58
MemberMember 126326017-Oct-20 23:58 
GeneralRe: COM exception loss Pin
Richard MacCutchan8-Oct-20 0:24
mveRichard MacCutchan8-Oct-20 0:24 
AnswerRe: COM exception loss Pin
OriginalGriff8-Oct-20 5:10
mveOriginalGriff8-Oct-20 5:10 
QuestionScanning for servers Pin
pkfox4-Oct-20 22:52
professionalpkfox4-Oct-20 22:52 
AnswerRe: Scanning for servers Pin
Richard Deeming5-Oct-20 3:44
mveRichard Deeming5-Oct-20 3:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.