Home > Net >  About SerialPort write com1 jammed
About SerialPort write com1 jammed

Time:09-15

SerialPort. Write (MSG, 0, MSG. Length);

Please comment, use the serialPort own com1 writing data to a computer, why is jammed, .
I downloaded some online serial debugging assistant, some will write card dead, some can continue to normal operation, how to solve this problem,

CodePudding user response:

Write the data through the com, card dead? Just pass the data to the external equipment, through specific the com how can stuck? Is there a catch exceptions?

CodePudding user response:

Or did you receive data is a problem with the thread?

CodePudding user response:

refer to the second floor singularity code farmers reply:
or receiving data of the thread you have any question?

COM1 is actually no connection, I here need to send data to multiple com, one of them will give right feedback; Is to find the correct serial port,
But once sent to com1 this connected peripherals will be stuck on a write this article, don't know how to solve,

CodePudding user response:

You can easily try catch {} {} if the exception handling instructions without external devices, in dealing with abnormal directly it is ok to ignore, not is correct the abnormal's serial port

CodePudding user response:

reference 4 floor singularity code farmers reply:
you can easily try catch {} {} if the exception handling instructions without external devices, in dealing with abnormal directly it is ok to ignore, not is correct the abnormal's serial port

The COM1 not exception, will only be jammed write data in the line, the program does not go down is not abnormal,

CodePudding user response:

Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. The Text;
Using System. The Threading. The Tasks;
Using System. IO. Ports;
The namespace ConsoleApp4
{
Class Program
{
Private static SerialPort laserPort;
The static void Main (string [] args)
{
The Program Program=new Program ();
The program. The Open (" COM1 ");
LaserPort. Write (" MSG ");
LaserPort. Close ();

Console. WriteLine (" OK ");
Console.ReadLine();
}
Public bool Open (string name, Int32 baudRate=9600, Int16 dataBits=8,
StopBits StopBits=StopBits. One, Parity Parity=Parity. None)
{
Try
{
If (null==laserPort)
{
LaserPort=new SerialPort ();
}

If (laserPort. IsOpen)
{
LaserPort. Close ();
}

LaserPort. PortName=name;

LaserPort. BaudRate=BaudRate;
LaserPort. DataBits=DataBits;
LaserPort. StopBits=StopBits;
LaserPort. Parity=Parity. None;
LaserPort. ReadBufferSize=4096;
LaserPort. ReadTimeout=1000;//read timeout
LaserPort. The Open ();
return true;
}
Catch
{
return false;
}
}
}
}
Is how one thing, the COM1 is generally found on the computer, some computers may have multiple, data write COM1 is card dead,

CodePudding user response:

cited the 6th floor of a black hole diving pig response:
using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. The Text;
Using System. The Threading. The Tasks;
Using System. IO. Ports;
The namespace ConsoleApp4
{
Class Program
{
Private static SerialPort laserPort;
The static void Main (string [] args)
{
The Program Program=new Program ();
The program. The Open (" COM1 ");
LaserPort. Write (" MSG ");
LaserPort. Close ();

Console. WriteLine (" OK ");
Console.ReadLine();
}
Public bool Open (string name, Int32 baudRate=9600, Int16 dataBits=8,
StopBits StopBits=StopBits. One, Parity Parity=Parity. None)
{
Try
{
If (null==laserPort)
{
LaserPort=new SerialPort ();
}

If (laserPort. IsOpen)
{
LaserPort. Close ();
}

LaserPort. PortName=name;

LaserPort. BaudRate=BaudRate;
LaserPort. DataBits=DataBits;
LaserPort. StopBits=StopBits;
LaserPort. Parity=Parity. None;
LaserPort. ReadBufferSize=4096;
LaserPort. ReadTimeout=1000;//read timeout
LaserPort. The Open ();
return true;
}
Catch
{
return false;
}
}
}
}
Is how one thing, the COM1 is generally found on the computer, some computers may have multiple, data write COM1 is card dead,

If you have external devices to send no problem, there is no problem, open the serial port is such, don't know what you're there no peripherals, how can have a serial port display?

CodePudding user response:

1. Now that is inspect the status of multiple com, then certainly cannot write the test process in the main thread
Once a com has a problem, as soon as the main thread is blocked,
Suggest put the testing code to thread, so as not to affect the processing of the main thread
2. LaserPort. The Open ();
This sentence is likely to throw exceptions
return true;
It's not reasonable to feel logically

CodePudding user response:

Computers bring a com1, used, you go to SerialPort GetPortNames () should get the com1, and other peripheral access;
The situation now is: I pick up a few peripherals, RS485 communication, such as, for example, now is the need to find what I need in this a few COM, so I send communication COM in instruction, but the instructions sent to COM1 a sink, nor an error also don't continue to run down, I want to know what's going on, the code above you can see for breakpoint test, the laserPort. Write (" MSG "); The below went out,

CodePudding user response:

Open a thread to send no peripherals serial port information, if not received within the time required to return to the information, will abort () off thread; As for will crash this problem should be a system mechanism, wait a moment will timeout?

CodePudding user response:

This is what I think is a method to eliminate no external com, you can check if there is any other way to learn together

CodePudding user response:

references 9 f xian_wwq response:
1. That is inspect the status of multiple com, certainly cannot write the test process in the main thread
Once a com has a problem, as soon as the main thread is blocked,
Suggest put the testing code to thread, so as not to affect the processing of the main thread
2. LaserPort. The Open ();
This sentence is likely to throw exceptions
return true;
It's not reasonable to feel logically

On the thread processing, thread plug does not affect the main thread, but the COM1 is in the congestion state, any good solution for COM1 this problem? Don't use the SerialPort to write this happen?
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • C#
  • Related