serial-port

Serial port and handling errors during overlapped I/O operations

五迷三道 提交于 2019-12-24 07:07:55
问题 I've been doing serial communications lately so I prepared a class being a simple interface to all those Windows API functions responsible for reading, writing, etc. All I/O operations inside this class are handled asynchronously. Before I go to my question, let me show you how I write and read data from serial port (this is only the reading function, because the structure of the writing one is exactly the same so there is no point in presenting both of them). function TSerialPort.Read(var

Correct Implementation of Async SerialPort Read

邮差的信 提交于 2019-12-24 05:39:13
问题 I have read a few threads here suggesting to use port.BaseStream.ReadAsync() with waith async / await. What is not clear to me is what is the best way to implement this? Do i still use the event_handler and just make it async / awaitable ? private async void myPort_DataReceived(object sender, SerialDataReceivedEventArgs e) { byte[] buffer = new byte[myPort.BytesToRead]; await (myPort.BaseStream.ReadAsync(buffer, 0, buffer.Length)); } Or is the event handler ignored completely and instead i am

Compact Framework serial port and balance

蓝咒 提交于 2019-12-24 05:33:21
问题 So, to open up a serial port and successfully transmit data from the balance through the serial port, i need to make sure that the settings on the serialPort object match the actual settings of the balance. Now, the question is how do i detect that the connection hasn't been established due to the settings being different? No exception is thrown by serialPort.Open to indicate that the connection has been established. Yes, the settings are valid, but if they don't match the device (balance)

Parsing time-delimited UART data

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 04:26:09
问题 When trying to correctly reverse-engineer and decode data on a UART connection, I have arrived at the following conclusions about the format of the data being received. Data is sent in "packets". Each packet is delimited only by time (spaces) between transmissions. Packets are of variable length. The length is specified by the third byte in the sequence. Data is not framed using any special characters or out-of-band signals, but a valid data packet can be (assumed to be) valid, based on the

Serial communication over USB converter in Python - how to aproach this?

独自空忆成欢 提交于 2019-12-24 03:45:14
问题 A python program needs to accept a string every second from a serial port. I plan on using a RS-232 to USB converter. The application is going to work under Ubuntu 10.04. How do I approach this? Do I use pySerial or libusb? There needs to be done some processing in the meantime, so synchronous communication is not viable. Do I use some kind of interrupts or do I need to open separate threads? Or do I use blocking reads, believing that 1s is enough for my computations (it is plenty ... for now

Ruby + Windows + Timeouts + SerialPorts won't work

十年热恋 提交于 2019-12-24 03:07:50
问题 I am developing a multiplatform Ruby program that is supposed to connect via USB to a serial device. First I was using the serialport gem (1.0.4), but then I ran into some strange problems and had to drop it. I then proceeded to communicate via Ruby's IO class, as follows: @port = IO.new IO.sysopen(path, mode), mode Communication via syswrite and sysread is perfect both in Linux as Windows. With the communication done, I tried setting up timeouts so that the program won't hang if any desync

Accessing COM-port with Windows 10

白昼怎懂夜的黑 提交于 2019-12-24 02:57:19
问题 I have some stupid code to access a Windows COM-port (just some pseudo-code of the most relevant functions): // open device: COMMTIMEOUTS timeouts; DCB ComSettings; memset(&ComSettings,0,sizeof(ComSettings)); ComSettings.DCBlength=sizeof(DCB); *fd=CreateFile(serialParams>port,GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING,0,0); GetCommState(*fd,&ComSettings); ComSettings.BaudRate=9600; ComSettings.ByteSize=8; ComSettings.Parity=NOPARITY; ComSettings.fParity=0; ComSettings.StopBits=ONESTOPBIT;

How to build and send hex commands to TV

删除回忆录丶 提交于 2019-12-24 02:25:08
问题 I have an NEC PX-42VM5HA plasma tv that I am trying to control with the connected computer. I have the data sheet that shows all the codes to control the tv and the protocol information. I am unsure how to build the right data structure in python to send the HEX control codes. Below is the Power Control Codes and the Communications Protocol. Communication Protocol: Interface: RS-232C Communication: Asynchronous Baud Rate: 9600 Data Length: 8bits Parity: Odd Stop Bit: 1bit Communication Code:

C# Calculate LRC (Longitudinal Redundancy Check)

馋奶兔 提交于 2019-12-24 02:07:44
问题 I've been researching this everywhere and all the LRC implementation seems to not giving me the right answer. After spending few days on it, I decided to put my code here to see if anyone else can spot the problem. Here's the code (C#) //Input Data = "31303030315E315E31303030325E315E31303030375E39395E31303032325E36353631335E" //LRC Answer = "30" private static string LRC(string Data) { int checksum = 0; foreach (char c in GetStringFromHex(Data)) { checksum ^= Convert.ToByte(c); } string hex =

How to read RTS/CTS pins' values on Linux?

℡╲_俬逩灬. 提交于 2019-12-24 02:05:53
问题 I would like to know the status of RTS/CTS pins on the serial port on my Linux machine. Also, since I am using /dev/ttyUSB0 will the same mechanism work? Regards, Aakash 回答1: It is usually recommended to use termios for interacting with a serial port but I believe RTS/CTS access is not supported. You will need to use ioctl(2) along with TIOCMGET and TIOCMSET. You can see an example here. Your USB dongle probably supports RTS/CTS but there are many different USB serial devices and not all of