A program in c using termios works well if the port is ttyusb0, but misses/garbles data if got through ttys0 i.e comport com1.
proogram runs under ubuntu 9.04 & 10.04
Please suggest the remedies cause for this discrepancy.
Garbled serial data is usually due to using the wrong serial speed. The default might be different for the usb port vs normal serial port. Are you calling cfsetispeed and cfsetospeed?
Are you using the same serial cable for both tests? At higher baud rates, a bad cable can result in noise. If ttyusb0 has a short cable between the USB adapter and the device, but ttyS0 is a long ribbon cable, you'd easily see noise on ttyS0 but not ttyusb0.
Related
Im having issues with my TI LAUNCHXL-F28379D. I have it connected to the laptop I am trying to send data to/from via pins P19 (SCIBRxD) and P18 (SCIBTxD), as well as GND and 5V via J16, using a USB Type B cord to which I sautered pin connectors. I'm sure power is being supplied to the board as when I plug the 5V cable of the USB cable, the RGB lights and 3 other small ones turn on. However, the Computer does not recognize ithe controller at the port - it only recognizes if if it is connected via the board's Mini-USB port. I've also written a C Program which opens the COM port and reads data - but this does not work without my knowledge of the COM port number, usually found in Device Manager. I cannot get any further in my project without the port number and it is very annoying. I will attempt to resauter a new USB cable, but if there are any other possible solutions, or if I'm doing something wrong, please let me know.
Absolutely all feedback is appreciated!
The SCIBRxD and SCIBTxD pins belong to the SCI peripheral in the microcontroller. This peripheral implements a UART port (a.k.a. COM port, a.k.a. TTL serial port). It is not a USB port. Nothing useful will happen if you connect it to a USB port, because it is not compatible with USB in any way.
USB-to-UART adapters (a.k.a. USB-to-serial adapters) do exist. There is one built into the LaunchPad. The UART side of the adapter is connected to the SCIB pins, and the USB side of the adapter is connected to the USB port.
I'm using stm32l151 and I want to use usb peripheral in cdc mode. I used stm32 cubeMx to generate the project. however the function CDC_Transmit_FS() always return USBD_BUSY. can anyone help me?
Here is my code:
while (1)
{
CDC_Transmit_FS(Buffer, 6);
HAL_Delay(2000);
}
I only added the above code to the project created by STM32cubeMX but it didn't work.
STM library is buggy and it stalls when you for example try to send many larger packets of data.
There is a problem with the windows drivers and there are quite long delays between packets. So 12MB is quite difficult to archive - using CubeMx I could only have about 3-4Mb (12MB when packet is sent).
Another problem I had - I needed to send some data to the device bofore I could transmit next packet (max 8kB in my case), otherwise it stalled randomly.
Fortunately, the problem is solved and I can receive data in the PC from the STM32. There was a problem in my terminal software. I used serial port manitor to monitor the received data from the serial port, however this serial monitor software do not open the serial port by itself and if any other software opens the serial port and receives the data, it monitors data receptions. I didn't know that.
Thanks
I am using a Raspberry Pi in order to communicate with a GSM/GPRS modem by USB. I am able to communicate in 115200bps. I would like to improve the communication speed as much as possible but I do not know how I should do it. The connection is RPi's USB <--> Modem's USB
I am programming in C and I have to choose the speed_t in cfsetispeed and cfsetospeed functions, which it`s maximum is B230400... I am using write function to send data.
USB 2.0 protocol has theoretically some mb/s speed so, how could I achieve this?
Unfortunately you can not achieve higher rates.
Most of GSM/GPRS modem have inbuilt USB-->Serial(RS232) Converter.
The USB port is just for USB connector compatibility.
To communicate to these modem's from any computer you need to install drivers to Emulate a RS232 connection.
In this case your board is already have those.
So basically you are doing a RS232 communication over USB lines. Your speed will be limited by RS232 standard baud-rates.
I have sensor node connected to USB port that sense temperature, humidity and light and send the data to PC.
What piece of code will help me to read that data from the USB port in normal C.
Application of the nodes is built on C using Eclipse.
I looked into the specifications of your board and it seems like it's a FTDI chip. This means it's exactly the same way you read from a serial port.
Here is how you program the serial port in Windows (it hasn't changed in a long time).
I have a plugged usb-serial device plugged to my windows and serial mapped it using virtualbox e.g COM1 -> /dev/ttyS0..
Now how will i know which serial port my device is using.. I know right now im using /dev/ttyS0. but what if i don't know?.. Linux Debian is creating this permanent serial port devices on boot time /dev/ttyS0-S3.
How can i make a test that /dev/ttyS0 is the real port im using in c.
Here's my way of testing if it's the right port or not.
devfd=open("/dev/ttyS0",O_WRONLY | O_NOCTTY | O_NDELAY);
if(s_fd<0) exit(1);
printf("open\n"); //It will always return true printing open because this device is created on boot time and is always available. so i made another check and that is to write to the port(Assuming i have set the permission to have full access to the serial port). if i can write to the port then it means it is really the port im using.
test=write(devfd,"ATZ",4);
if(test<0) printf("Can't write to port: Maybe not the serial port ur using\n");
printf("Device is avaialable\n"); // returns true because we can write to the port
Can you show me other samples in c of how can Check serial port if there's a device plugged to that serial port?
Or a test in c to the following serial port /dev/ttyS0 - /dev/ttyS3 if the following have devices plugged on them.
Thanks.
The Standard Serial ports are mapped as /ttyS0,/ttyS1,... as you correctly stated.
Generic USB Serial Ports as well as most G3 modems are accessible as /dev/ttyUSB0 through /dev/ttyUSB255
The better way to distinguish if a serial port 'connected' with a modem is to send ATIx commands to the serial port. These are Identity commands that you may use to detect the model name of the device and many other details.
First you try to send ATIx command not changing the baud rate. If you do not receive any valid response (ASCII multi-line text followed by OK<CR><LF> ERROR...<CR><LF> then you may alter the baud rate and retry. It is better to first set the maximum supported by port speed and then decrease it until you find a modem or you end up with 110 baud or other reasonable limit.
There is a way to detect if most likely there is nothing connected to the serial port. The idea behind is to detect the frame error that persists during some reasonable time (tens times to receive a byte at selected baud rate), say 2-3sec. To see how enable/disable frame errors detection look at man termios. Howeever, I am not absolutely sure that in the setup you described this will be possible (from within VM), so you have to try.
Also look at this post How to connect to a terminal to Serial-USB device on Ubuntu 10.10?
Be aware, that I found by experience that writing to a serial port to test it can have dire consequences; as my script hung (but only when running on ESXi hypervisor) when trying to test write to a disconnected device
In case it helps, here is a safer way to check
cat /proc/tty/driver/serial | \
grep -v unknown | \
sed 's/^/ttyS/g'
and then check output for ttyS0 for example