Click here to Skip to main content
15,905,232 members
Home / Discussions / C#
   

C#

 
AnswerRe: basic question close and collapse methods Pin
PIEBALDconsult28-Dec-12 3:33
mvePIEBALDconsult28-Dec-12 3:33 
Questionset the parent form size according to child form in mdi form Pin
Arun kumar Gautam28-Dec-12 1:12
Arun kumar Gautam28-Dec-12 1:12 
AnswerRe: set the parent form size according to child form in mdi form Pin
Matt U.28-Dec-12 4:16
Matt U.28-Dec-12 4:16 
AnswerRe: set the parent form size according to child form in mdi form Pin
Eddy Vluggen28-Dec-12 9:04
professionalEddy Vluggen28-Dec-12 9:04 
QuestionSelected rows in a gridview Pin
rakeshs31227-Dec-12 19:26
rakeshs31227-Dec-12 19:26 
AnswerRe: Selected rows in a gridview Pin
vanikanc28-Dec-12 6:48
vanikanc28-Dec-12 6:48 
GeneralRe: Selected rows in a gridview Pin
rakeshs31228-Dec-12 18:48
rakeshs31228-Dec-12 18:48 
AnswerRe: Selected rows in a gridview Pin
Abhinav S28-Dec-12 23:39
Abhinav S28-Dec-12 23:39 
QuestionSliding an Image on another Image Pin
Shubhanshu Pathak27-Dec-12 18:09
Shubhanshu Pathak27-Dec-12 18:09 
QuestionSerial Port Won't Send While Receiving Pin
C-P-User-327-Dec-12 15:13
C-P-User-327-Dec-12 15:13 
AnswerRe: Serial Port Won't Send While Receiving Pin
Richard MacCutchan27-Dec-12 21:45
mveRichard MacCutchan27-Dec-12 21:45 
GeneralRe: Serial Port Won't Send While Receiving Pin
C-P-User-328-Dec-12 5:21
C-P-User-328-Dec-12 5:21 
GeneralRe: Serial Port Won't Send While Receiving Pin
Richard MacCutchan28-Dec-12 5:45
mveRichard MacCutchan28-Dec-12 5:45 
GeneralRe: Serial Port Won't Send While Receiving Pin
C-P-User-328-Dec-12 5:59
C-P-User-328-Dec-12 5:59 
GeneralRe: Serial Port Won't Send While Receiving Pin
Richard MacCutchan28-Dec-12 6:40
mveRichard MacCutchan28-Dec-12 6:40 
AnswerRe: Serial Port Won't Send While Receiving Pin
GrooverFromHolland28-Dec-12 7:04
GrooverFromHolland28-Dec-12 7:04 
AnswerRe: Serial Port Won't Send While Receiving Pin
jschell28-Dec-12 9:53
jschell28-Dec-12 9:53 
GeneralRe: Serial Port Won't Send While Receiving Pin
C-P-User-331-Dec-12 10:54
C-P-User-331-Dec-12 10:54 
GeneralRe: Serial Port Won't Send While Receiving Pin
C-P-User-31-Jan-13 13:35
C-P-User-31-Jan-13 13:35 
GeneralRe: Serial Port Won't Send While Receiving Pin
C-P-User-31-Jan-13 13:36
C-P-User-31-Jan-13 13:36 
GeneralRe: Serial Port Won't Send While Receiving Pin
GrooverFromHolland1-Jan-13 23:41
GrooverFromHolland1-Jan-13 23:41 
Hi,

A serial port cannot send and receive at the same time.
There must be some kind of protocol e.g. hardware handshaking, software handshaking or some kind of software protocol.
if You don't know what protocol is used, it is impossible to to make it work.

Here is an example of a protocol that my device uses.
My port is listening and waiting for for bytes to receive.
The device sends three bytes(two address bytes and one data byte and expects to have the data byte as answer immediately.
If the device receives the data byte and checks if this was the byte sent it sends the next three bytes, until there is no more to send.

In the code snippet You can see that the port is sending in the data_received event with no problem,
that is because I know the device is not sending until I answer correct.

This is the code I use to do this.
It only works with the protocol of my device, but it shows how to implement such a protocol:

C#
System.Timers.Timer tmrPortInt = new System.Timers.Timer(800);
 comportInt.DataReceived += new SerialDataReceivedEventHandler(portInt_DataReceived);
 tmrPortInt.Elapsed += new System.Timers.ElapsedEventHandler(tmrPortInt_Elapsed);

 private void portInt_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            if (tmrPortInt.Enabled) tmrPortInt.Stop();//this is a timer to check if no more data is received,
                                                      //While data is received within 800 m Sec port keeps listening.
                                                      // In my case he data is processed in the timer elapsed event(~6000 bytes).
            int tempAddress;
            int bytes = comportInt.BytesToRead;
            byte[] buffer = new byte[3];  //I want to read only three bytes.

            if (bytes > 2)
            {
                buffer = new byte[bytes]; //Empty my buffer before filling with received bytes.
                comportInt.Read(buffer, 0, 3);
               
                comportInt.Write(buffer, 2, 1);//You can see i am writing within the port_received event.
                                               // I send the third byte received.
                if (receiveByteList == null) receiveByteList = new List<byte>();
               
                tempAddress = (256 * buffer[0] + buffer[1]); // decimal value of two address bytes
                receiveBytes[tempAddress] = buffer[2];
                receiveByteList.Add(receiveBytes[1]);// add data byte to list
               
                tmrPortInt.Start();// Prevents the timer to elapse until no more bytes are received.
            }
        }
         void tmrPortInt_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            tmrPortInt.Stop();
            this.Invoke(new EventHandler(Process_MachineData));// This is where I do something With the data received.
        }


Regards,

Groover
0200 A9 23
0202 8D 01 80
0205 00

GeneralRe: Serial Port Won't Send While Receiving Pin
C-P-User-32-Jan-13 4:25
C-P-User-32-Jan-13 4:25 
GeneralRe: Serial Port Won't Send While Receiving Pin
C-P-User-37-Jan-13 9:21
C-P-User-37-Jan-13 9:21 
QuestionQuestion about split Pin
S Douglas27-Dec-12 6:32
professionalS Douglas27-Dec-12 6:32 
AnswerRe: Question about split Pin
PIEBALDconsult27-Dec-12 7:20
mvePIEBALDconsult27-Dec-12 7:20 

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.