SerialPort | Serial Port Communicator | Runtime Evironment library
kandi X-RAY | SerialPort Summary
kandi X-RAY | SerialPort Summary
Language: C# OS: Windows.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of SerialPort
SerialPort Key Features
SerialPort Examples and Code Snippets
Community Discussions
Trending Discussions on SerialPort
QUESTION
I have a microcontroller which I communicate with my windows pc, through FT232RL. On the computer side, I am making a C-library to send and receive data, using windows API.
I have managed to:
- Receive data (or multiple receives),
- Transmit data (or multiple transmits),
- First transmit (or multiple transmits) and then receive data (or multiple receives)
But I have not managed to:
- Transmit Data and then receive.
If I receive anything, and then try to transmit, I get error. So, I guess when I receive data, there is a change in configuration of the HANDLE hComm
, which I cannot find.
So the question is, what changes to my HANDLE hComm
configuration when I receive data, which does not allow me to transmit after that?
Here is my code/functions and the main() that give me the error. If I run this, I get this "error 6" -screenshot of the error down below-:
...ANSWER
Answered 2021-Jun-14 at 01:17According to MSDN:Sample, Maybe you need to set a pin's signal state to indicate the data has been sent/received in your microcontroller program. More details reside in your serial communication transmission of data standard. And you should write code according to the result of WaitCommEvent(hCom, &dwEvtMask, &o);
like the linked sample.
QUESTION
I'm trying to read data from the serial port and display it in a JavaFX controller. I'm using jSerialComm to read data from the serial port. This is their example:
...ANSWER
Answered 2021-Jun-05 at 07:11It's not really clear what you're asking: you already have all the pieces.
I'm not familiar with jSerialComm
(in particular how it manages threading), but your JavaFX application will look like this:
QUESTION
I'm trying to use ORSSerialPort to send and receive data to and from serial port.
I'm following the example here but I'm using commandline app: https://github.com/armadsen/ORSSerialPort/tree/master/Examples/ORSSerialPortDemo
I believe I copied/implemented every required method, but the problem is although I can send data to my serial port(I double confirmed from my serial port log and the send succeeded), I cannot receive anything.
My code is very simple as below - it is only intended to be a prototype so the code might not be well designed.
So am I missing anything that I cannot receive data from serial port? Any suggestions are appreciated.
...ANSWER
Answered 2021-May-31 at 22:11Assuming the code you included is the complete program source code (ie. you're compiling it as a command-line app), the problem is that the program terminates right after sendString()
is called, so the port has no chance to receive anything. You need to keep the program alive and running. There are multiple ways to do that, but the simplest is just to call RunLoop.main.run()
as the last line of the program. That will cause the run loop to run indefinitely processing input from all sources, and will both keep the program alive and run the system machinery that ORSSerialPort relies on.
QUESTION
I am developing a simple UWP app which needs to listen to a serial port connected to an esp32 which has a rfid reader attached.
It needs to receive UID of card, navigate to new page, and then navigate back to the original page after a timer has elapsed, or a button has been clicked.
It is all working, except for the part where I navigate back to the original parent page. I believe it's because the app is trying to reconnect to the serial port, but it's unavailalbe. I've tested my theory by creating a setup button with the serial connection setup on this and it does work as expected.
So, does Page_Loaded fire every time the page is reloaded? Is there a function which only fires on the first loading of the form? I can't get disposing of the serial port to work at all, i just get an unhandled exception. I don't have a problem leaving the serial port open though, but this seems to be causing problems too!
Please see some sample code below:
...ANSWER
Answered 2021-May-28 at 08:52So, does Page_Loaded fire every time the page is reloaded?
Yes.
Is there a function which only fires on the first loading of the form?
You could use a boolean flag to determine whether to execute your method:
QUESTION
My code is designed to get data from a serial device and print its contents to a MS Forms Application. The IDE i use is Visual Studio 2019 - Community.
The device does send a variable size packet. First i have to decode the packet "header" to get crucial information for further processing which is the first packet channel as well as the packet length.
Since the packet does neither contain a line ending, nor a fixed character at the end, the functions SerialPort.ReadTo()
and SerialPort.ReadLine()
are not useful. Therefore only SerialPort.Read(buf,offset,count)
can be used
Since sending rather large packets (512bytes) does take time, I've implemented a function for calculation of a desired wait time, which is defined as (1000ms/baud-rate*(8*byte-count))+100ms
While testing, I've experienced delay, much more than the desired wait times, so implemented a measure function for different parts of the function.
In regular cases (with desired wait times) i except a log to console like this:
Load Header(+122ms) Load Data (+326ms) Transform (+3ms)
But its only like this for a few variable amount of records, usually 10, after that, the execution times are much worse:
Load Header(+972ms) Load Data (+990ms) Transform (+2ms)
Here you can see the complete function:
...ANSWER
Answered 2021-May-20 at 19:17Instead of trying to figure out how long a message will take to arrive at the port, why not just read the data in a loop until you have it all? For example, read the header and calculate the msg size. Then read that number of bytes. Ex:
QUESTION
#include
#include "serialcomm.h"
#include
#include
#define BUFF_SIZE 256
int main()
{
CSerialComm serialComm;
BYTE buff[BUFF_SIZE] = { 0, };
int op = 0;
int port = 0;
int size = 0;
int size2 = 0;
int restart = 0;
char port_s[20] = "";
char send_string[1000];
char confirm[BUFF_SIZE];
char dec[BUFF_SIZE];
printf("select mode(1. send, 2. receive) : ");
scanf_s("%d", &op);
printf("insert port num : ");
scanf_s("%d", &port);
getchar();
if (op == 1) {
printf("plz submit data (ex : 0x0a 0x01, 0x02, 0x0b) : ");
gets_s(send_string, sizeof(send_string));
size = serialComm.getHexData(send_string, buff);
printf("read size(max %d) : ", BUFF_SIZE);
scanf_s("%d", &size2);
}
sprintf_s(port_s, "COM%d", port);
// STEP 1. SerialPort Connect
if (!serialComm.connect(port_s)) {
printf("connect faliled");
return -1;
}
else {
printf("connect successed\n");
}
if (op == 1) {
// STEP 2. Send Command
while (1) {
if (!serialComm.sendCommand(buff, size)) {
printf("send command failed\n");
}
else {
int i = 0;
printf("tx data(%d) : [ ", size);
for (i = 0; i < size; i++) {
printf("0x%02X ", buff[i]);
}
printf("]\n");
}
Sleep(2000);
serialComm.readByte(buff, size2);
int j = 0;
printf("rx data(%d) : [ ", size2);
for (j = 0; j < size2; j++) {
printf("0x%02X ", buff[j]);
}
printf("]\n");
//data convert
char buffer[256];
int m = 0;
printf("[ ");
for (m = 0; m < size; m++) {
fprintf(stderr, "%d", buff[m]);
printf(" ");
}
printf("]\n");
sprintf_s(buffer, sizeof(buffer), "%d", buff[m]);
char data1 = buff[0];
char data2 = buff[1];
char data3 = buff[2];
char data4 = buff[3];
char data5 = buff[4];
char data6 = buff[5];
char data7 = buff[6];
char data8 = buff[7];
char data1 = buff[8];
size = serialComm.getHexData(send_string, buff);
Sleep(2000);
}
...ANSWER
Answered 2021-May-11 at 07:45UPDATE: As per cplusplus.com, perhaps a more reputable source, it looks like this is your best option:
QUESTION
I have this "Serial" class that extends Thread that works with a serial port. In the run() method I first open the port, set all the Serial params and add a SerialPortEventListener. Then i just put a while(go) where go is a private (so only the class can see it) boolean instance set as true. I have a kill method that not only it closes the port and remove the SerialEventListener, but also set "go" as false, hence the Thread should stop. Now, here is where things start getting weird: if I put a System.out.println(something) in the while(go), when I call the kill() method the Thred stops, but if I doesn't it remains alive. Do you have any ideas about why it works like that and how to solve it?
...ANSWER
Answered 2021-Apr-24 at 20:11Unless go
is declared volatile, there is no guarantee the while loop (or anything else) will read the current value.
declare go as
QUESTION
serial port not seen in components
I'm working on a windows form application but I can't find the needed SerialPort component in my toolbox. Tried resetting the toolbox but it didn't work either.
Can anyone help me solve this issue?
...ANSWER
Answered 2021-Apr-21 at 20:43The output tab of the Visual Studio on your screenshot, suggests that your project is a .NET Core project. To check this go to the project properties and check the Target Framework setting. SerialPort, you are expecting to see in the toolbox, is a component that is a part of the .NET framework which is different from the .NET Core
If you want to keep using .NET Core as your platform try with the links below:
QUESTION
I'm currently working on a project that includes a short demo game, we've decided to use LibGDX as the java library and we're required to use an arduino and/or raspberry pi as a controller input. My assumption was to make an inputprocessor that uses the serial monitor input sent by the arduino. We're currently stumped on how to accomplish this and aren't even sure if you can use the inputprocessor in this way.
...ANSWER
Answered 2021-Apr-21 at 17:40I would suggest moving your serial listener to a separate dedicated thread, which calls back to your game when it reads something.
This way your GDX Game thread can continue to run as you expect, with a parallel thread listening for inputs, only notifying the game when it receives them.
To achieve this, package your listener into a Runnable interface:
QUESTION
I need to use some At commands & read the data for that I am using below cmds , the response I would be getting is in multiple lines
...ANSWER
Answered 2021-Apr-21 at 14:18readline()
: reads one line, if you use multiple times, each time it will keep giving next line until it reaches end of file or file is closed.
readlines()
: returns a list of lines from a file
If you want the output of a whole file, you can use read()
instead.
About the timeout
flag, I don't think timeout flag exists for I/O operations in Python? But if you are talking about the one in Serial
, then it specifies the maximum time to wait for serial data.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install SerialPort
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page