Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

8431/16 RS422 C# programming (How to be sure all data is sent)

I am using the serial ports of 8431/16 card with C#.

 

I am using "Write" function of "SerialPort class" in .NET. "Write" function is a blocking function so I assume that when "Write" function return all data is sent, at least placed in transmit buffer. But I saw that for 9600 baudrate, writing above 10000bytes data size all data are no sent(about 9872 bytes sent when write function returns) to the other side when write function returns.(20000 bytes for 19200 baudrate).

 

I changed the value of transmit buffer from "SerialPort class" and also changed  8431/16 card transmit buffer size (1-127) but I could not solve the problem.

 

I want to be sure that my all data is sent to the other side so I can say the other side that I sent to you this match data.

0 Kudos
Message 1 of 6
(6,670 Views)

Hi! Would you mind pasting the relevant code in the forum so I can simulate your setup and see if I'm getting the same behavior? 

Rob B
FlexRIO Product Manager
0 Kudos
Message 2 of 6
(6,647 Views)

Hello,

 

I am writing simple C# code for it. Here is how code looks like.

 

private void Function()

{

 

 SerialPort port = new SerialPort();
                byte[] data = new byte[10000];
                for (int i = 0; i < 10000; i++)
                {
                    data[i] = i;
                }
                port.PortName = "COM1";
                port.BaudRate = 9600;
                port.Parity = Parity.None;
                port.StopBits = StopBits.One;
                
                port.Open();
                port.Write(data, 0, data.Length);

}

 

 

I am trying to send 10000 bytes at 9600 baudrate. Other side receives about 9872 bytes sometimes about 9700. But at baudrate 19200, 10000 bytes are able to be sent. However 20000 bytes for 19200 baudrate again there is problem. I think maybe some overflow occurs but I am not sure.

 

It is a simple situation to try I am waiting for results.

 

Thank you..

 

 

 

 

Software Test Engineer

0 Kudos
Message 3 of 6
(6,637 Views)

So when you write fewer than 10,000 bytes do you experience a similar behavior? What if you try writing 1024 bytes at 19200 baud rate? I'm curious at to whether or not it's a buffer issue or a programming issue. Can you try varying the bytes to write and baud rate and post your findings? 

 

Also, how are you measuring the number of bytes received? What device is on the other end?

Rob B
FlexRIO Product Manager
0 Kudos
Message 4 of 6
(6,599 Views)

So far, I dont face a problem when writing fewer than 10000bytes for 9600 baudrate, I have tried different data sizes for different baudrates, but I will again try it. On the other end there is a computer with embedded real time software, It receives the data, I also use Serial Monitor on my PC to see how many bytes are sent. For 9600 baudrate 10000bytes I saw there are fewer than 10000bytes on the "Serial Monitor".

 

These days I will again try to similar things and look whether there will be error or not. Did you try to send 10000 bytes with your setup? Or do you have the chance to try it? 

0 Kudos
Message 5 of 6
(6,588 Views)

I haven't had a chance to try it only because I don't have access to that card. I've simulated it but I also don't have a Real Time target to read the results. Let me know when you've had a chance to perform testing at different baud rates sending 10,000 bytes or less; I think that will help isolate the issue. 

Rob B
FlexRIO Product Manager
0 Kudos
Message 6 of 6
(6,562 Views)