LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-09-2005, 10:15 AM   #1
fingerling54
LQ Newbie
 
Registered: May 2005
Posts: 3

Rep: Reputation: 0
Problem of serial port programming


I am trying to use an Imada DPS-1 Force Digital Force Guage under Debian Linux system via RS-232 serial port.
I checked "the Serial Programming Guide for POSIX Operating System" and have my own code as shown in the end.
This is just a testing code to see whether I can communicate well with the force guage. I tried to write 2 ASCII characters "Q" and CR to the port. As suggested by the force guage manual, this is to turn off the power of the force guage.
However, though no "Unable to open /dev/ttyS0!" or "Writing failed" message showed up, the command "Q\r" doesn't turn off the power at all.
I also added more code to this simple one to set the attributes of the serial port, like the baudrate, whether it is a canonical process or not, etc, though I think this is only necessary for reading the port. And it still couldn't work.
I used to use the MSComm class to do the same thing under MS Windows, and it works perfectly (which means the product manual can't be wrong). But it just can't work when I switch to Linux.

Could anyone help me out of this problem? It's really killing me.

Here's the code:
#include <stdio.h> /* Standard input/output definitions */
#include <string.h> /* String function definitions */
#include <unistd.h> /* UNIX standard function definitions */
#include <fcntl.h> /* File control definitions */
#include <errno.h> /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */

main()
{
int fd;
int n;

if ((fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY)) == -1)
perror("Unable to open /dev/ttyS0!\n");
else printf("/dev/ttyS0 succesfully opened, fd=%i.\n",fd);

fcntl(fd, F_SETFL, O_RDWR);

n = write(fd, "Q\r",2);
if (n<0) printf("Writing failed!\n");
else printf("%i bytes written to /dev/ttyS0.\n",n);

close(fd);
}

Thank you very much.

Last edited by fingerling54; 05-09-2005 at 12:16 PM.
 
Old 05-09-2005, 10:25 AM   #2
trevelluk
Member
 
Registered: Nov 2003
Location: Bristol, UK
Distribution: Debian Lenny, Gentoo (at work)
Posts: 388

Rep: Reputation: 32
That code is opening a regular file called test.dat, not the serial port.
 
Old 05-09-2005, 12:14 PM   #3
fingerling54
LQ Newbie
 
Registered: May 2005
Posts: 3

Original Poster
Rep: Reputation: 0
Sorry

Sorry, I guess I post the trial version of my code to see whether I can output anything to a text file at all. I did use "\dev\ttyS0" in my real code.

I am going to correct this stupid mistake. Thanks.

Last edited by fingerling54; 05-09-2005 at 12:16 PM.
 
Old 05-11-2005, 11:50 AM   #4
fingerling54
LQ Newbie
 
Registered: May 2005
Posts: 3

Original Poster
Rep: Reputation: 0
Help please....
 
Old 05-18-2005, 03:22 PM   #5
guest4321
LQ Newbie
 
Registered: May 2005
Posts: 1

Rep: Reputation: 0
If you are getting a permission denied when opening the device, try doing a "chmod a+rwr /dev/ttyS0" as root.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Serial port programming problem (Win32 VS POSIX) chanwing Programming 1 06-29-2005 11:17 AM
serial port programming: Java or C? ar1 Programming 5 05-19-2005 02:55 PM
serial port programming!!! novice_din Programming 4 02-03-2005 08:50 PM
Serial Port Programming Question Darktyco Programming 8 03-23-2004 05:13 PM
Programming the Serial Port karans Linux - Networking 2 11-03-2003 01:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration