logo
down
shadow

send and receive via Serial port Windows


send and receive via Serial port Windows

By : Najla Abdulla
Date : November 19 2020, 01:01 AM
I wish did fix the issue. I've encountered a similar problem a while ago.
I found out that WriteFile(..) blocks if a ReadFile(..) is currently in progress for a serial port. So that's a problem if ReadFile(..) blocks if there is no data to be read.
code :
void ReceiverThread(void *param)
{
    DWORD dwRead=0;
    COMSTAT comStat;
    char buffer[1024];

    while (m_hCommPort != INVALID_HANDLE_VALUE)
    {
        if ((ClearCommError(m_hCommPort, NULL, &comStat) != FALSE) && (comStat.cbInQue > 0))
        {
            /* todo: ensure buffer is big enough to contain comStat.cbInQue bytes! */

            if (ReadFile(m_hCommPort, buffer, comStat.cbInQue, &dwRead, NULL) != FALSE)
            {
                /* do something with data in buffer */
            }
        }

        /* avoid busy-wait */
        if (comStat.cbInQue == 0)
        {
            SleepEx(1, FALSE);
        }
    }
}


Share : facebook icon twitter icon
Serial Port: Unable to Send/Receive Data

Serial Port: Unable to Send/Receive Data


By : Runner
Date : March 29 2020, 07:55 AM
will help you Wrong connector, you need a null modem.
(Copied from Hans Passant's comment to allow question to show as answered as per protocol.)
how to send and receive data to serial port or USB port in asp.net?

how to send and receive data to serial port or USB port in asp.net?


By : Reckoner
Date : March 29 2020, 07:55 AM
hop of those help? You need to host asp.net net application/website on a server your browser is a client machine. Your client will request a page from server and website could not be hosted on client machine. So you can connect your device to server machine and client sent you request to post data through device e.g gsm modem. Now you need to connect your device to server and you can make a windows service to pull the posted message from database to post them through device.
You need to talk to COM port, even your USB devices listen to COM port. You can use serial port class to communicate with device. You can do this with desktop application and I could not see any reason for using website. The following links will help you.
Send and receive over serial port doesn't work

Send and receive over serial port doesn't work


By : SUBHAM CHAKRABORTY
Date : March 29 2020, 07:55 AM
This might help you As far as I can tell, there may be several things causing it not to work. First of all, the Read method is outside the Program scope, resulting in it not working. Secondly, moving it inside won't work either, until you also make "_continue" and "_serialPort" fields (outside methods).
Reworked code (removed redundant 'using' statements):
code :
using System;
using System.IO.Ports;
using System.Threading;

namespace Terminal_0._0._0._2
{
    class Program
    {
        private static bool _continue;
        private static SerialPort _serialPort;

        public static void Main()
        {
            string name;
            string message;
            StringComparer stringComparer = StringComparer.OrdinalIgnoreCase;
            var readThread = new Thread(Read);

            // Create a new SerialPort object with default settings.
            _serialPort = new SerialPort
                {
                    PortName = "COM8",
                    BaudRate = 115200,
                    Parity = Parity.None,
                    DataBits = 8,
                    StopBits = StopBits.One,
                    Handshake = Handshake.None,
                    ReadTimeout = 500,
                    WriteTimeout = 500
                };

            // Allow the user to set the appropriate properties.

            // Set the read/write timeouts

            _serialPort.Open();
            _continue = true;
            readThread.Start();

            Console.Write("Name: ");
            name = Console.ReadLine();

            Console.WriteLine("Type QUIT to exit");

            while (_continue)
            {
                message = Console.ReadLine();

                if (stringComparer.Equals("quit", message))
                {
                    _continue = false;
                }
                else
                {
                    _serialPort.WriteLine(
                        String.Format("<{0}>: {1}", name, message));
                }
            }

            readThread.Join();
            _serialPort.Close();
        }

        public static void Read()
        {
            while (_continue)
            {
                try
                {
                    string message = _serialPort.ReadLine();
                    Console.WriteLine(message);
                }
                catch (TimeoutException) { }
            }
        }
    }
}
How to send and receive data from serial port for server side in asp.net mvc

How to send and receive data from serial port for server side in asp.net mvc


By : stanley.fang
Date : March 29 2020, 07:55 AM
I wish did fix the issue. i found my answer finally. this is about Interference on send speed in serial port and receive(calculate) speed in server ! you should set sleep time in first line of "port_DataReceived" method, as you see:
code :
public static void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
    {

        Thread.Sleep(TimeSpan.FromMilliseconds(100));
        int dataLength = port.BytesToRead;
        char[] result = new char[dataLength];

        for (int len = 0; len < result.Length;)
        {


            len += port.Read(result, len, result.Length - len);
        }
        string send = "";
        for (int i = 0; i < result.Length; i++)
        {
            send += result[i];
        }

        Taxi.Controllers.ReceiveController.Decision(send);  

    }
How to send and receive a decimal array through serial port?

How to send and receive a decimal array through serial port?


By : Monzer Mohamed
Date : March 29 2020, 07:55 AM
hop of those help? Of course you can go back to [0, 100, 150, 175, 255]! You're sending the data from a bytearray, and you should also use a bytearray to receive the data. To convert the received bytes back to integers, you just need to pass the bytearray to list().
Here's a demo:
code :
elements = [0, 100, 150, 175, 255]

# Buffer for sending data
data2 = bytearray(elements)

# Buffer for reading data
rdata = bytearray()

# Simulate sending data over the serial port
rdata.extend(data2[0:2])
rdata.extend(data2[2:5])

vect = list(rdata)
print(vect)
[0, 100, 150, 175, 255]
Related Posts Related Posts :
  • Need a startup script in windows to send ALT+F11 keys?
  • Information about DLL files in windows
  • Prerequisites for learning MFC programming
  • Java Version in a batch file
  • cURL in power shell windows 8.1: "A drive with the name 'localhost' does not exist"
  • How can I make a macro to run a few PowerShell commands one after the other?
  • Add a domain user into a local group when the domain is not available
  • windows 7 bat file leaves out parts of the command
  • psql "more is not recognized" error
  • Bundler error when executing berks command from a rake task on windows
  • Echo first three characters of filenames in CMD Windows
  • yii2 composer.phar update is not working
  • Generate memory dump for a windows service that stops unexpectedly
  • Sending data over ethernet from a Raspberry Pi to a c# program on a windows PC
  • Windows driver installation failure after signing and verifying with signtool using cross signed certificates using SHA-
  • Is there any way to make a First Person Shooter input in Windows 8.1?
  • Perl: Check if string is valid directory, case SENSITIVE
  • How to add a program (in this case gmsh) to the PATH
  • Command-line to show a file's properties?
  • ErrorDocument in httpd.conf not working
  • Windows Task Scheduler - specify time window, but only fire once
  • How to delete the mistakenly case-changed renamed tag in github?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org