Wrong data with Read from a serial port.


 
Thread Tools Search this Thread
Top Forums Programming Wrong data with Read from a serial port.
# 22  
Old 11-19-2012
I didn't mean "check for available bytes instead" when I said "no timeouts".

You are getting data every 50 milliseconds. There's no point trying to time it carefully. The timer resolution of the OS itself will make it jitter.

Just read(), only read(), and nothing but read().

If even that doesn't work, there's something wrong with your connection or data...
# 23  
Old 11-19-2012
Corona, my function also work with IOCTL and timer every 10 ms..

I can also try your method but in a while(1){ }? you can write your code pls?

thanks
# 24  
Old 11-19-2012
"doesn't work with ioctl" is what you meant, I believe, since if it were working you wouldn't need our help...

I asked before and ask again, is this actually RS-232? If it plugs into USB, the answer is probably no. And if the answer is no, the usual serial niceties like flow control probably aren't going to work how you want, making a lot of fancy termios things pointless.

Code:
unsigned char buf[1000], checksum;
int pos=0;

unsigned char c=0;

while(1)
{
        if(read(fd, &c, 1) <= 0) break;
        buf[pos++]=c;
        if(c == 'm') break;
}

if(c == 'm') read(fd, &checksum, 1);

// Calculate checksum, discard if bad, accept if good


Last edited by Corona688; 11-19-2012 at 11:51 AM..
# 25  
Old 11-19-2012
Quote:
Originally Posted by Corona688
"doesn't work with ioctl" is what you meant, I believe, since if it were working you wouldn't need our help...

I asked before and ask again, is this actually RS-232? If it plugs into USB, the answer is probably no. And if the answer is no, the usual serial niceties like flow control probably aren't going to work how you want, making a lot of fancy termios things pointless.

Code:
unsigned char buf[1000], checksum;
int pos=0;

unsigned char c=0;

while(1)
{
        if(read(fd, &c, 1) <= 0) break;
        buf[pos++]=c;
        if(c == 'm') break;
}

if(c == 'm') read(fd, &checksum, 1);

// Calculate checksum, discard if bad, accept if good


Yes is RS232.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Solaris

Cabling and adapters to communicate to service processor serial port from Windows PC with USB port.

Hello, I have an unloaded T5140 machine and want to access the ILOM for the first time and subsequently the network port after that., and then load Solaris 10 the final January 2011 build. The first part is what confuses me -the cabling. I am coming from a Windows machine (w/appropriate... (5 Replies)
Discussion started by: joboy
5 Replies

2. Debian

Reading data from a serial port

Dear List - I am trying to capture data from a serial port and write it to a file. /var/www$ cat /dev/ttyS0 > scale_value.html cat: /dev/ttyS0: Device or resource busy /var/www# cat /proc/tty/driver/serial serinfo:1.0 driver revision: 0: uart:16550A port:000003F8 irq:4 tx:90... (11 Replies)
Discussion started by: Meow613
11 Replies

3. Programming

Read from serial port

Hi I try to communicate with a GSM modem, from C, for sending SMS. I use standart AT-commands. Working well with terminal. There is no problem writing ti the port. But when I try to read I only get a echo, I write "ATI" and get "ATI" back, I should get somthing like "SIEMENS 35... (4 Replies)
Discussion started by: dmiller
4 Replies

4. Programming

unable to send read and write serial port

hey frns pls help me out !! i hav a code of c that i have to include in my project. i am using a device (geomeda) that has unix based OS. it also support SIM card for connecting to server . I need to send SMS to user from this device.. below code is not working .. i am unable to send sms and the... (7 Replies)
Discussion started by: yashwantkumar
7 Replies

5. Solaris

How to enable Serial port on ILOM, when Network Port is enabled in parallel

Hi Everyone, In my environment, I have few T5220. On the iLOM Management Card, I have both Network and Serial port are cabled, I don't have any issues while I try to connect using Network Management port, but when I try to connect the serial port for the same server which is actually connected... (3 Replies)
Discussion started by: bobby320
3 Replies

6. Shell Programming and Scripting

Need help with serial port

Hi, I have a external board connected to my serial port. I need to execute "shutdown -r now" command when system boot up. When system boots up it requires a username ans password. Then I need to run my command. I can use rc script but that is rebooting system before it asks for username and... (0 Replies)
Discussion started by: charlie.arya
0 Replies

7. Programming

Problem with read data from serial device

I have problem with C programming. I want to send & receive data through serial communication. I send data(command) to device to get data from device but when receive data, it can't get altogether of data. It get only some data. What should I do to get altogether of data? If all of... (7 Replies)
Discussion started by: noppon_s
7 Replies

8. SCO

data transfer from serial port

dear sir, pls. can you help me ? , my os is unix sco 5.0.4 and ,server dat derive (1,4gb) not working, now i want to transfer my server data in other machine (unix/other possible) by serial port/other port comminication. thanks pankaj raval (2 Replies)
Discussion started by: pankajbraval
2 Replies

9. Linux

Urgent - serial port

Hi All, I am a begineer in Linux, I have 4 ports and 3 are operational port 1,port 2 and port 4 (when I plug in serial device I can see it working) but port 3 seems it is not working. I am sure the hardware is fine. when I give command dmesg | grep tty I get, serial 8250:ttyS0 at... (0 Replies)
Discussion started by: vr_82
0 Replies
Login or Register to Ask a Question