Click here to Skip to main content
15,886,919 members
Home / Discussions / C#
   

C#

 
GeneralRe: Debugger issues Pin
Mustafa Ismail Mustafa28-Dec-08 9:17
Mustafa Ismail Mustafa28-Dec-08 9:17 
GeneralRe: Debugger issues Pin
Guffa28-Dec-08 14:21
Guffa28-Dec-08 14:21 
GeneralRe: Debugger issues Pin
Luc Pattyn28-Dec-08 14:29
sitebuilderLuc Pattyn28-Dec-08 14:29 
Questionuser control interaction Pin
dustybike28-Dec-08 1:54
dustybike28-Dec-08 1:54 
AnswerRe: user control interaction Pin
Colin Angus Mackay28-Dec-08 3:53
Colin Angus Mackay28-Dec-08 3:53 
AnswerRe: user control interaction Pin
Code Soldier28-Dec-08 4:21
Code Soldier28-Dec-08 4:21 
GeneralRe: user control interaction Pin
Colin Angus Mackay28-Dec-08 6:58
Colin Angus Mackay28-Dec-08 6:58 
QuestionProblem with a byte array buffer Pin
ajorge200828-Dec-08 1:43
ajorge200828-Dec-08 1:43 
Good Afternoon to all Smile | :)

Currently, i'm doing a program that send commands through my serial port via GSM Modem to a remote equipment. After sending the first command, i'm receiving the first packet where it cames the packet counter which value i need to obtain the rest of packets. To do this, i'm writing the first packet on a text file, and then i'm going to search the packet counter value. But there's a problem, after making the GSM connection, i receive the CONNECT string and it is saved into my text file, but after this, when i send the first command, the first received data packet remains in the buffer (byte array), without going to my text file. When i'm reading the file, only the CONNECT string is saved on the file.

I'm sending the functions i'm using to monitor the received data:

private void OnComm(object sender, EventArgs e)  //  MSCommLib OnComm Event Handler
		{
            int counter = new int();
			

			if (com.InBufferCount > 0) 
			{
				try
				{                   				

                    Stream s = new MemoryStream((byte[])com.Input);
                    counter = Convert.ToInt32(s.Length);                    

                    byte[] fileData = new byte[counter];                    

                    s.Read(fileData, 0, counter);
                    
                    s.Close();

					ReadDeviceResponse(fileData);                    
                    					
				}
				catch(Exception ex)
				{
					MessageBox.Show(ex.Message, this.Text,
						MessageBoxButtons.OK,MessageBoxIcon.Information);
				}
			}
		}

private void ReadDeviceResponse(byte[] response)
		{

            WritePacketDataOnTextFile(response);

			for(int i = 0; i < response.Length; i++)
			{
				rtfTerminal.AppendText(response[i].ToString() + " ");
			}
			rtfTerminal.AppendText("\n");            
			
		}

public static void WritePacketDataOnTextFile(byte[] Buffer)
        {
            int i;
            FileInfo file1 = new FileInfo("C:\\Users\\AJorge\\Desktop\\TestData.txt");
            StreamWriter sw = file1.AppendText();

            for (i = 0; i < Buffer.Length; i++)        

                sw.Write("{0} ", Buffer[i]);              

            sw.Close();           

        }


Could anyone help me with this?

Best Regards.
AnswerRe: Problem with a byte array buffer Pin
Richard Andrew x6428-Dec-08 3:00
professionalRichard Andrew x6428-Dec-08 3:00 
GeneralRe: Problem with a byte array buffer Pin
ajorge200828-Dec-08 3:23
ajorge200828-Dec-08 3:23 
GeneralRe: Problem with a byte array buffer Pin
Luc Pattyn28-Dec-08 14:35
sitebuilderLuc Pattyn28-Dec-08 14:35 
AnswerRe: Problem with a byte array buffer Pin
Wendelius28-Dec-08 12:02
mentorWendelius28-Dec-08 12:02 
GeneralRe: Problem with a byte array buffer Pin
ajorge200828-Dec-08 22:33
ajorge200828-Dec-08 22:33 
GeneralRe: Problem with a byte array buffer Pin
ajorge200829-Dec-08 0:32
ajorge200829-Dec-08 0:32 
GeneralRe: Problem with a byte array buffer Pin
ajorge200829-Dec-08 6:13
ajorge200829-Dec-08 6:13 
QuestionShowing multiple forms inside a single form Pin
shaf21127-Dec-08 23:19
shaf21127-Dec-08 23:19 
AnswerRe: Showing multiple forms inside a single form Pin
#realJSOP27-Dec-08 23:50
mve#realJSOP27-Dec-08 23:50 
GeneralRe: Showing multiple forms inside a single form Pin
shaf21129-Dec-08 22:18
shaf21129-Dec-08 22:18 
AnswerRe: Showing multiple forms inside a single form Pin
Code Soldier28-Dec-08 4:47
Code Soldier28-Dec-08 4:47 
GeneralRe: Showing multiple forms inside a single form Pin
shaf21129-Dec-08 22:22
shaf21129-Dec-08 22:22 
QuestionActiveX PDF problem Pin
frappydan27-Dec-08 23:10
frappydan27-Dec-08 23:10 
QuestionVPN programmin Pin
sepel27-Dec-08 23:01
sepel27-Dec-08 23:01 
QuestionPython to .Net tool Pin
George_George27-Dec-08 21:20
George_George27-Dec-08 21:20 
AnswerRe: Python to .Net tool Pin
Dave Kreskowiak28-Dec-08 4:51
mveDave Kreskowiak28-Dec-08 4:51 
GeneralRe: Python to .Net tool Pin
George_George28-Dec-08 18:37
George_George28-Dec-08 18:37 

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.