Sponsored Content
Top Forums Programming Help with C in linux Ubuntu 12.04 Post 302659751 by Corona688 on Thursday 21st of June 2012 11:07:58 AM
Old 06-21-2012
You don't need C to put two statements in a text file:

Code:
# Create retrieve.sh
cat <<EOF >retrieve.sh
#!/bin/sh
echo "#o1" > /dev/ttyUSB1
cat /dev/ttyUSB1 > /home/hectormasencio/Desktop/text.txt
EOF
# Set it executable
chmod +x ./retrieve.sh
# Run it
./retrieve.sh

# You now have a file which retrieves data from your microcontroller when you run it.

But if you insist:

Code:
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int main(void)
{
        ssize_t ret;
        char buf[512];
        int fd=open("/dev/ttyUSB1", O_RDWR);
        if(fd < 0) return(1);

        write(fd, "#o1\n", 4);

        while( (ret=read(fd, buf, 512)) > 0)
                write(STDOUT_FILENO, buf, ret);

        close(fd);
        return(0);
}

 

4 More Discussions You Might Find Interesting

1. Ubuntu

XP and Linux (Ubuntu) on same disk, Can I install Ubuntu on not-yet partitioned portion of disk?

My PC (Esprimo, 3 yeas old) has one hard drive having 2 partitions C: (80 GB NTFS, XP) and D: (120 GB NTFS, empty) and and a 200 MB area that yet is not-partitioned. I would like to try Ubuntu and to install Ubuntu on the not-partitioned area . The idea is to have the possibility to run... (7 Replies)
Discussion started by: C.Weidemann
7 Replies

2. UNIX for Dummies Questions & Answers

How do I mount a new disk on ubuntu linux?

Hello, I am fairly new to ubuntu and have been learning linux using this distro. I am using Ubuntu 11.04 server. Recently I added a new HD to the desktop.. however I know I need to mount it, My question is how would I mount this disk? so I can use it as a drive? Thanks here are my... (5 Replies)
Discussion started by: NelsonC
5 Replies

3. Ubuntu

Modifying PATH (LINUX, Ubuntu)

Hello, I'm a newbi to Unix and the last few weeks I have been trying to learn Unix through a book called Unix in 24 hours. I have tried advanced shell programming (that's what the chapter is called) today and what the excersise was all about was to create mylocate - a version of locate that is... (1 Reply)
Discussion started by: Tolmac
1 Replies

4. Ubuntu

Application clustering in Linux Ubuntu

Dear, Please help me to configure application clustering in linux ubuntu. Application is running apache server. Please help Jewel ---------- Post updated at 01:07 PM ---------- Previous update was at 12:48 PM ---------- linuxvirtualserver dot org in this link i go there's three... (2 Replies)
Discussion started by: Jewel100
2 Replies
WRITE(1)                                                    BSD General Commands Manual                                                   WRITE(1)

NAME
write -- send a message to another user SYNOPSIS
write user [tty] DESCRIPTION
The write utility allows you to communicate with other users, by copying lines from your terminal to theirs. When you run the write command, the user you are writing to gets a message of the form: Message from yourname@yourhost on yourtty at hh:mm ... Any further lines you enter will be copied to the specified user's terminal. If the other user wants to reply, they must run write as well. When you are done, type an end-of-file or interrupt character. The other user will see the message 'EOF' indicating that the conversation is over. You can prevent people (other than the super-user) from writing to you with the mesg(1) command. If the user you want to write to is logged in on more than one terminal, you can specify which terminal to write to by specifying the termi- nal name as the second operand to the write command. Alternatively, you can let write select one of the terminals - it will pick the one with the shortest idle time. This is so that if the user is logged in at work and also dialed up from home, the message will go to the right place. The traditional protocol for writing to someone is that the string '-o', either at the end of a line or on a line by itself, means that it is the other person's turn to talk. The string 'oo' means that the person believes the conversation to be over. SEE ALSO
mesg(1), talk(1), wall(1), who(1) HISTORY
A write command appeared in Version 1 AT&T UNIX. BUGS
The sender's LC_CTYPE setting is used to determine which characters are safe to write to a terminal, not the receiver's (which write has no way of knowing). BSD February 13, 2012 BSD
All times are GMT -4. The time now is 11:33 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy