Click here to Skip to main content
16,018,353 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
namespace SerialData
{
    public partial class Form1 : Form
    {
        private const int V = 0;
        string nonc;
        string strNonc;
     
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            SerialPort port = new SerialPort("COM3", 9600, Parity.Even, 8, StopBits.One);
            serialPort1.Open();

            if (serialPort1.IsOpen)
            {
                try
                {
                    byte[] arr1 = { 58, 23, 68, 68, 68, 0, 22, 167 };
                    serialPort1.Write(arr1, 0, arr1.Length);
 
                    Thread.Sleep(500);
                    byte[] arr2 = { 58, 23, 68, 68, 68, 0, 22, 167 };
                    serialPort1.Write(arr2, 0, arr2.Length);

                    byte[] arr3 = { 58, 23, 68, 68, 68, 0, 22, 167 };
                    serialPort1.Write(arr3, 0, arr3.Length);

                    byte[] arr4 = { 58, 23, 68, 68, 68, 0, 22, 167 };
                    serialPort1.Write(arr4, 0, arr4.Length);

                }

                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }


What I have tried:

But Serial Port Does Not Write any Data
Posted
Comments
Richard MacCutchan 28-Aug-23 5:57am    
How do you determine that it does not write any data?
Member 16038362 31-Aug-23 1:01am    
I Have Check Communication with Modscan App its working Fine , And When I go For Coding I Add Breakpoint and i Uses Debugger,then it will Show all parameter of Serial Port Like Parity,Databits,StopBits.
And Bytes to Write is Zero And Bytes To Read is also Zero
Member 16038362 1-Sep-23 5:22am    
is this Correct ?
Richard MacCutchan 1-Sep-23 7:30am    
I have no idea as I cannot test your system for you. Matbe you need to look at the device you are writing to in order to check what is happening.
CPallini 28-Aug-23 7:34am    
As Richard suggests, probably you are just not-properly-detecting the serial port output.

1 solution

Start by checking that you have the right COM port and data format: some devices will just reject data if the parity is wrong for example, or you could have the wrong speed.

So start with HyperTerminal or similar, and ensure that you can talk to the device yourself and see any replies correctly before you go anywhere near writing software.

When you can, you can use the same settings to set up your code and see what happens.
But until then, you are just adding another large set of variables to the system and that makes it impossible for us to even start helping you!
 
Share this answer
 
Comments
Member 16038362 30-Aug-23 0:47am    
Yes, i Connected to right Com Port , and All settings are ok, Still is doesn't Write any Data
OriginalGriff 30-Aug-23 1:55am    
How do you know it's the right port and configuration, and how are you checking if anything is written? What did HyperTerminal (or similar) show?
Member 16038362 30-Aug-23 2:18am    
I check Com port Name and properties in Device Manager - Ports( Newly added Port )
and I have added BreakPoint and by using Dubugger , I checked this
OriginalGriff 30-Aug-23 2:53am    
So you haven't tried to check communications work at all, just that "a com port exists and it's probably got the device I want to talk to on the other end"?

As I said to start with, check the comms work first, then start looking at code. Until you have proved that comms happen at all, you don't know that the device works, is turned on, can listen to you, can respond because you haven't got any way to establish that data leaves your PC, let alone that your code is working as expected!
Member 16038362 30-Aug-23 4:06am    
Okey...I got this ..But i check Communication on ModScan ..I have Recieved Data in Modscan and i also checked this communication with my old Application.
No Problem With this

When I go For Coding , at that time Port not write Anything

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900